mirror of
https://git.wownero.com/lza_menace/totrader.git
synced 2024-08-15 00:33:13 +00:00
tighten up order checks, templatize more vars, be more aggressive
This commit is contained in:
parent
802c780159
commit
a3cd63d82f
1 changed files with 19 additions and 16 deletions
35
trade.py
35
trade.py
|
@ -25,8 +25,10 @@ class Trader(TradeOgre):
|
||||||
base_currency = getenv('BASE_CURRENCY', 'BTC')
|
base_currency = getenv('BASE_CURRENCY', 'BTC')
|
||||||
trade_currency = getenv('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 = getenv('TRADE_AMOUNT', 200)
|
trade_amount = float(getenv('TRADE_AMOUNT', 200))
|
||||||
spread_target = getenv('SPREAD_TARGET', 4)
|
spread_target = float(getenv('SPREAD_TARGET', 4))
|
||||||
|
amount_multiplier = float(getenv('AMOUNT_MULTIPLIER', 1.2))
|
||||||
|
active_order_limit = float(getenv('ACTIVE_ORDER_LIMIT', 10))
|
||||||
|
|
||||||
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}')
|
||||||
|
@ -79,7 +81,7 @@ class Trader(TradeOgre):
|
||||||
|
|
||||||
def get_active_orders(self):
|
def get_active_orders(self):
|
||||||
logging.info('[ORDERS] Getting active orders in local database')
|
logging.info('[ORDERS] Getting active orders in local database')
|
||||||
orders = Order.select().where(Order.active==True)
|
orders = Order.select().where(Order.active==True, Order.trade_pair==self.trade_pair)
|
||||||
logging.debug(f'Found {len(orders)} in database')
|
logging.debug(f'Found {len(orders)} in database')
|
||||||
return orders
|
return orders
|
||||||
|
|
||||||
|
@ -114,18 +116,19 @@ class Trader(TradeOgre):
|
||||||
|
|
||||||
def start_market_maker(self):
|
def start_market_maker(self):
|
||||||
logging.info('[MARKET MAKER] Starting market maker')
|
logging.info('[MARKET MAKER] Starting market maker')
|
||||||
latest = Ticker.select().order_by(Ticker.date.desc()).get()
|
latest = Ticker.select().where(Ticker.trade_pair==self.trade_pair).order_by(Ticker.date.desc()).get()
|
||||||
trade_type = 'market_maker'
|
trade_type = 'market_maker'
|
||||||
|
active_orders = len(self.get_active_orders())
|
||||||
|
|
||||||
if len(self.get_active_orders()) > 8:
|
if active_orders > self.active_order_limit:
|
||||||
logging.info('[MARKET MAKER] Too many active orders in place. Skipping.')
|
logging.info(f'[MARKET MAKER] Too many active orders in place ({active_orders}). Skipping.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if latest.spread_sats > self.spread_target:
|
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 * self.amount_multiplier)
|
||||||
ask_amount = uniform(bid_amount - 6, bid_amount + 6)
|
ask_amount = uniform(self.trade_amount, self.trade_amount * self.amount_multiplier)
|
||||||
bid_price = '{:.8f}'.format(latest.bid + self.satoshi)
|
bid_price = '{:.8f}'.format(latest.bid + self.satoshi * 1000)
|
||||||
ask_price = '{:.8f}'.format(latest.ask - self.satoshi)
|
ask_price = '{:.8f}'.format(latest.ask - self.satoshi * 1000)
|
||||||
logging.info(f'[MARKET MAKER] Submitting buy order for {bid_amount} at {bid_price} {self.trade_pair}')
|
logging.info(f'[MARKET MAKER] Submitting buy order for {bid_amount} at {bid_price} {self.trade_pair}')
|
||||||
buy = self.submit_order('buy', self.trade_pair, bid_amount, bid_price)
|
buy = self.submit_order('buy', self.trade_pair, bid_amount, bid_price)
|
||||||
logging.debug(buy)
|
logging.debug(buy)
|
||||||
|
@ -190,9 +193,9 @@ if __name__ == '__main__':
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info('[ERROR] Unable to store market data!', e)
|
logging.info('[ERROR] Unable to store market data!', e)
|
||||||
|
|
||||||
# update orders every 5 minutes
|
# update orders every 4 minutes
|
||||||
if args.update_orders:
|
if args.update_orders:
|
||||||
if orders_counter == 5:
|
if orders_counter == 4:
|
||||||
try:
|
try:
|
||||||
t.update_orders()
|
t.update_orders()
|
||||||
logging.info('[ORDERS] Resetting orders counter')
|
logging.info('[ORDERS] Resetting orders counter')
|
||||||
|
@ -200,9 +203,9 @@ if __name__ == '__main__':
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info('[ERROR] Unable to update orders!', e)
|
logging.info('[ERROR] Unable to update orders!', e)
|
||||||
|
|
||||||
# update balances every 6 minutes
|
# update balances every 2 minutes
|
||||||
if args.balances:
|
if args.balances:
|
||||||
if balances_counter == 6:
|
if balances_counter == 2:
|
||||||
try:
|
try:
|
||||||
t.store_balances()
|
t.store_balances()
|
||||||
logging.info('[BALANCE] Resetting balances counter')
|
logging.info('[BALANCE] Resetting balances counter')
|
||||||
|
@ -210,9 +213,9 @@ if __name__ == '__main__':
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info('[ERROR] Unable to update balances!', e)
|
logging.info('[ERROR] Unable to update balances!', e)
|
||||||
|
|
||||||
# start market makers every 2 minutes
|
# start market makers every 3 minutes
|
||||||
if args.market_maker:
|
if args.market_maker:
|
||||||
if market_maker_counter == 2:
|
if market_maker_counter == 3:
|
||||||
try:
|
try:
|
||||||
t.start_market_maker()
|
t.start_market_maker()
|
||||||
logging.info('[MARKET MAKER] Resetting market maker counter')
|
logging.info('[MARKET MAKER] Resetting market maker counter')
|
||||||
|
|
Loading…
Reference in a new issue