2020-09-06 13:27:19 +00:00
|
|
|
from os import getenv
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from peewee import *
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
|
|
|
|
load_dotenv('.env')
|
|
|
|
|
|
|
|
db = PostgresqlDatabase(
|
2020-09-09 06:34:21 +00:00
|
|
|
getenv('DB_NAME', 'trader'),
|
2020-09-06 13:27:19 +00:00
|
|
|
user=getenv('DB_USER'),
|
|
|
|
password=getenv('DB_PASS'),
|
|
|
|
host=getenv('DB_HOST', '127.0.0.1'),
|
|
|
|
port=getenv('DB_PORT', 5432)
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_time():
|
|
|
|
now = datetime.now()
|
|
|
|
now = now + timedelta(hours=7)
|
|
|
|
return now
|
|
|
|
|
|
|
|
class Ticker(Model):
|
|
|
|
id = AutoField()
|
|
|
|
trade_pair = CharField()
|
|
|
|
initial_price = DoubleField()
|
|
|
|
current_price = DoubleField()
|
|
|
|
high_price = DoubleField()
|
|
|
|
low_price = DoubleField()
|
|
|
|
volume = DoubleField()
|
|
|
|
bid = DoubleField()
|
|
|
|
ask = DoubleField()
|
|
|
|
spread_btc = DoubleField()
|
|
|
|
spread_sats = IntegerField()
|
|
|
|
spread_perc = DoubleField()
|
|
|
|
date = DateTimeField(default=get_time)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
database = db
|
|
|
|
|
|
|
|
class Balance(Model):
|
|
|
|
total = DoubleField()
|
|
|
|
available = DoubleField()
|
|
|
|
currency = CharField()
|
|
|
|
date = DateTimeField(default=get_time)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
database = db
|
|
|
|
|
2020-09-07 07:43:05 +00:00
|
|
|
class Order(Model):
|
|
|
|
trade_pair = CharField()
|
|
|
|
trade_type = CharField()
|
|
|
|
buy = BooleanField()
|
|
|
|
quantity = DoubleField()
|
|
|
|
price = DoubleField()
|
2020-09-09 04:30:49 +00:00
|
|
|
uuid = TextField()
|
2020-09-07 07:43:05 +00:00
|
|
|
active = BooleanField(default=True)
|
|
|
|
cancelled = BooleanField(default=False)
|
|
|
|
date = DateTimeField(default=get_time)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
database = db
|
|
|
|
|
2020-10-03 02:42:21 +00:00
|
|
|
class Earning(Model):
|
|
|
|
trade_pair = CharField()
|
|
|
|
quantity = DoubleField()
|
|
|
|
date = DateTimeField(default=get_time)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
database = db
|
2020-09-06 13:27:19 +00:00
|
|
|
|
2020-10-03 02:42:21 +00:00
|
|
|
db.create_tables([Ticker, Balance, Order, Earning])
|