-
Notifications
You must be signed in to change notification settings - Fork 2
/
my_model.py
40 lines (31 loc) · 1.01 KB
/
my_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from peewee import *
from playhouse.sqlite_ext import SqliteExtDatabase
import datetime
import os
from my_conf import config
DB_PATH = os.path.abspath(os.path.expanduser(os.path.join(config['storage_dir'], 'data.db')))
print('using database path', DB_PATH)
db = SqliteExtDatabase(DB_PATH)
class BaseModel(Model):
class Meta:
database = db
class Instrument(BaseModel):
ticker = CharField(unique=True)
class OrderBookUpdate(BaseModel):
created_utc = DateTimeField(default=datetime.datetime.utcnow)
ms_out = IntegerField()
instrument = ForeignKeyField(Instrument)
class OrderBook(BaseModel):
is_bid = BooleanField()
cm = FloatField()
price = FloatField()
qty = FloatField()
update = ForeignKeyField(OrderBookUpdate)
class Summary(BaseModel):
high = FloatField()
last = FloatField()
low = FloatField()
update = ForeignKeyField(OrderBookUpdate)
if not os.path.exists(DB_PATH):
db.connect()
db.create_tables([Instrument, OrderBookUpdate, OrderBook, Summary])