Merge pull request #1830 from nanoric/database_open_interest
[Add] database: open_interest
This commit is contained in:
commit
bc900dfc82
@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Sequence, Optional
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from mongoengine import DateTimeField, Document, FloatField, StringField, connect
|
||||
|
||||
@ -47,6 +47,7 @@ class DbBarData(Document):
|
||||
interval: str = StringField()
|
||||
|
||||
volume: float = FloatField()
|
||||
open_interest: float = FloatField()
|
||||
open_price: float = FloatField()
|
||||
high_price: float = FloatField()
|
||||
low_price: float = FloatField()
|
||||
@ -73,6 +74,7 @@ class DbBarData(Document):
|
||||
db_bar.datetime = bar.datetime
|
||||
db_bar.interval = bar.interval.value
|
||||
db_bar.volume = bar.volume
|
||||
db_bar.open_interest = bar.open_interest
|
||||
db_bar.open_price = bar.open_price
|
||||
db_bar.high_price = bar.high_price
|
||||
db_bar.low_price = bar.low_price
|
||||
@ -90,6 +92,7 @@ class DbBarData(Document):
|
||||
datetime=self.datetime,
|
||||
interval=Interval(self.interval),
|
||||
volume=self.volume,
|
||||
open_interest=self.open_interest,
|
||||
open_price=self.open_price,
|
||||
high_price=self.high_price,
|
||||
low_price=self.low_price,
|
||||
@ -112,6 +115,7 @@ class DbTickData(Document):
|
||||
|
||||
name: str = StringField()
|
||||
volume: float = FloatField()
|
||||
open_interest: float = FloatField()
|
||||
last_price: float = FloatField()
|
||||
last_volume: float = FloatField()
|
||||
limit_up: float = FloatField()
|
||||
@ -168,6 +172,7 @@ class DbTickData(Document):
|
||||
db_tick.datetime = tick.datetime
|
||||
db_tick.name = tick.name
|
||||
db_tick.volume = tick.volume
|
||||
db_tick.open_interest = tick.open_interest
|
||||
db_tick.last_price = tick.last_price
|
||||
db_tick.last_volume = tick.last_volume
|
||||
db_tick.limit_up = tick.limit_up
|
||||
@ -215,6 +220,7 @@ class DbTickData(Document):
|
||||
datetime=self.datetime,
|
||||
name=self.name,
|
||||
volume=self.volume,
|
||||
open_interest=self.open_interest,
|
||||
last_price=self.last_price,
|
||||
last_volume=self.last_volume,
|
||||
limit_up=self.limit_up,
|
||||
@ -255,6 +261,7 @@ class DbTickData(Document):
|
||||
|
||||
|
||||
class MongoManager(BaseDatabaseManager):
|
||||
|
||||
def load_bar_data(
|
||||
self,
|
||||
symbol: str,
|
||||
|
@ -56,6 +56,7 @@ def init_postgresql(settings: dict):
|
||||
|
||||
|
||||
class ModelBase(Model):
|
||||
|
||||
def to_dict(self):
|
||||
return self.__data__
|
||||
|
||||
@ -75,6 +76,7 @@ def init_models(db: Database, driver: Driver):
|
||||
interval: str = CharField()
|
||||
|
||||
volume: float = FloatField()
|
||||
open_interest: float = FloatField()
|
||||
open_price: float = FloatField()
|
||||
high_price: float = FloatField()
|
||||
low_price: float = FloatField()
|
||||
@ -96,6 +98,7 @@ def init_models(db: Database, driver: Driver):
|
||||
db_bar.datetime = bar.datetime
|
||||
db_bar.interval = bar.interval.value
|
||||
db_bar.volume = bar.volume
|
||||
db_bar.open_interest = bar.open_interest
|
||||
db_bar.open_price = bar.open_price
|
||||
db_bar.high_price = bar.high_price
|
||||
db_bar.low_price = bar.low_price
|
||||
@ -133,10 +136,10 @@ def init_models(db: Database, driver: Driver):
|
||||
DbBarData.insert(bar).on_conflict(
|
||||
update=bar,
|
||||
conflict_target=(
|
||||
DbBarData.datetime,
|
||||
DbBarData.interval,
|
||||
DbBarData.symbol,
|
||||
DbBarData.exchange,
|
||||
DbBarData.interval,
|
||||
DbBarData.datetime,
|
||||
),
|
||||
).execute()
|
||||
else:
|
||||
@ -159,6 +162,7 @@ def init_models(db: Database, driver: Driver):
|
||||
|
||||
name: str = CharField()
|
||||
volume: float = FloatField()
|
||||
open_interest: float = FloatField()
|
||||
last_price: float = FloatField()
|
||||
last_volume: float = FloatField()
|
||||
limit_up: float = FloatField()
|
||||
@ -209,6 +213,7 @@ def init_models(db: Database, driver: Driver):
|
||||
db_tick.datetime = tick.datetime
|
||||
db_tick.name = tick.name
|
||||
db_tick.volume = tick.volume
|
||||
db_tick.open_interest = tick.open_interest
|
||||
db_tick.last_price = tick.last_price
|
||||
db_tick.last_volume = tick.last_volume
|
||||
db_tick.limit_up = tick.limit_up
|
||||
@ -256,6 +261,7 @@ def init_models(db: Database, driver: Driver):
|
||||
datetime=self.datetime,
|
||||
name=self.name,
|
||||
volume=self.volume,
|
||||
open_interest=self.open_interest,
|
||||
last_price=self.last_price,
|
||||
last_volume=self.last_volume,
|
||||
limit_up=self.limit_up,
|
||||
@ -303,9 +309,9 @@ def init_models(db: Database, driver: Driver):
|
||||
DbTickData.insert(tick).on_conflict(
|
||||
update=tick,
|
||||
conflict_target=(
|
||||
DbTickData.datetime,
|
||||
DbTickData.symbol,
|
||||
DbTickData.exchange,
|
||||
DbTickData.datetime,
|
||||
),
|
||||
).execute()
|
||||
else:
|
||||
@ -318,6 +324,7 @@ def init_models(db: Database, driver: Driver):
|
||||
|
||||
|
||||
class SqlManager(BaseDatabaseManager):
|
||||
|
||||
def __init__(self, class_bar: Type[Model], class_tick: Type[Model]):
|
||||
self.class_bar = class_bar
|
||||
self.class_tick = class_tick
|
||||
|
Loading…
Reference in New Issue
Block a user