use more .env vars

This commit is contained in:
lza_menace 2020-09-08 23:34:21 -07:00
parent d3d5bd2580
commit 4aff63211f
2 changed files with 10 additions and 9 deletions

2
db.py
View file

@ -7,7 +7,7 @@ from datetime import datetime, timedelta
load_dotenv('.env') load_dotenv('.env')
db = PostgresqlDatabase( db = PostgresqlDatabase(
'trader', getenv('DB_NAME', 'trader'),
user=getenv('DB_USER'), user=getenv('DB_USER'),
password=getenv('DB_PASS'), password=getenv('DB_PASS'),
host=getenv('DB_HOST', '127.0.0.1'), host=getenv('DB_HOST', '127.0.0.1'),

View file

@ -2,6 +2,7 @@
import logging import logging
from os import getenv from os import getenv
from dotenv import load_dotenv
from argparse import ArgumentParser from argparse import ArgumentParser
from datetime import datetime from datetime import datetime
from decimal import Decimal from decimal import Decimal
@ -18,11 +19,14 @@ logging.basicConfig(
class Trader(TradeOgre): class Trader(TradeOgre):
load_dotenv('.env')
satoshi = .00000001 satoshi = .00000001
base_currency = 'BTC' base_currency = getenv('BASE_CURRENCY', 'BTC')
trade_currency = 'WOW' trade_currency = getenv('TRADE_CURRENCY', 'WOW')
trade_pair = f'{base_currency}-{trade_currency}' trade_pair = f'{base_currency}-{trade_currency}'
trade_amount = 250 trade_amount = getenv('TRADE_AMOUNT', 200)
spread_target = getenv('SPREAD_TARGET', 4)
def get_market_data(self): def get_market_data(self):
logging.info(f'[MARKET] Getting market data for trade pair {self.trade_pair}') logging.info(f'[MARKET] Getting market data for trade pair {self.trade_pair}')
@ -113,11 +117,11 @@ class Trader(TradeOgre):
latest = Ticker.select().order_by(Ticker.date.desc()).get() latest = Ticker.select().order_by(Ticker.date.desc()).get()
trade_type = 'market_maker' trade_type = 'market_maker'
if len(self.get_active_orders()) > 5: if len(self.get_active_orders()) > 8:
logging.info('[MARKET MAKER] Too many active orders in place. Skipping.') logging.info('[MARKET MAKER] Too many active orders in place. Skipping.')
return False return False
if latest.spread_sats > 4: if latest.spread_sats > self.spread_target:
bid_amount = uniform(self.trade_amount, self.trade_amount + 30) bid_amount = uniform(self.trade_amount, self.trade_amount + 30)
ask_amount = uniform(bid_amount - 6, bid_amount + 6) ask_amount = uniform(bid_amount - 6, bid_amount + 6)
bid_price = '{:.8f}'.format(latest.bid + self.satoshi) bid_price = '{:.8f}'.format(latest.bid + self.satoshi)
@ -171,16 +175,13 @@ if __name__ == '__main__':
if not args.run and args.market_maker: if not args.run and args.market_maker:
t.start_market_maker() t.start_market_maker()
exit()
if not args.run and args.update_orders: if not args.run and args.update_orders:
t.reconcile_orders() t.reconcile_orders()
t.update_orders() t.update_orders()
exit()
if not args.run and args.balances: if not args.run and args.balances:
t.store_balances() t.store_balances()
exit()
if args.run: if args.run:
while True: while True: