mirror of
https://git.wownero.com/lza_menace/totrader.git
synced 2024-08-15 00:33:13 +00:00
refresh the bot
This commit is contained in:
parent
a92effbe60
commit
e121cc8920
3 changed files with 43 additions and 30 deletions
2
db.py
2
db.py
|
@ -52,7 +52,7 @@ class Order(Model):
|
|||
buy = BooleanField()
|
||||
quantity = DoubleField()
|
||||
price = DoubleField()
|
||||
uuid = TextField()
|
||||
uuid = TextField(null=True)
|
||||
active = BooleanField(default=True)
|
||||
cancelled = BooleanField(default=False)
|
||||
date = DateTimeField(default=get_time)
|
||||
|
|
|
@ -11,3 +11,4 @@ TRADE_AMOUNT=300
|
|||
SPREAD_TARGET=4
|
||||
AMOUNT_MULTIPLIER=1.2
|
||||
ACTIVE_ORDER_LIMIT=50
|
||||
LOGLEVEL=INFO
|
||||
|
|
70
trade.py
70
trade.py
|
@ -122,15 +122,15 @@ class Trader(TradeOgre):
|
|||
type = 'buy'
|
||||
else:
|
||||
type = 'sell'
|
||||
orders[type].append(Decimal(order.price))
|
||||
orders[type].append(Decimal(round(order.price * order.quantity, 12)))
|
||||
|
||||
orders['total_sell'] = sum(orders['sell'])
|
||||
orders['total_buy'] = sum(orders['buy'])
|
||||
earnings = orders['total_sell'] - orders['total_buy']
|
||||
orders['total_earnings'] = orders['total_sell'] - orders['total_buy']
|
||||
|
||||
e = Earning(
|
||||
trade_pair=self.trade_pair,
|
||||
quantity=earnings
|
||||
quantity=orders['total_earnings']
|
||||
)
|
||||
e.save()
|
||||
|
||||
|
@ -144,41 +144,57 @@ class Trader(TradeOgre):
|
|||
logging.info(f'[MARKET MAKER] Too many active orders in place ({active_orders}). Skipping.')
|
||||
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 * self.amount_multiplier)
|
||||
ask_amount = uniform(self.trade_amount, self.trade_amount * self.amount_multiplier)
|
||||
bid_price = '{:.8f}'.format(latest.bid + self.satoshi * 100)
|
||||
ask_price = '{:.8f}'.format(latest.ask - self.satoshi * 100)
|
||||
bid_price = '{:.8f}'.format(latest.bid + self.satoshi)
|
||||
ask_price = '{:.8f}'.format(latest.ask - self.satoshi)
|
||||
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)
|
||||
logging.debug(buy)
|
||||
if 'uuid' in buy:
|
||||
uuid = buy['uuid']
|
||||
active = True
|
||||
else:
|
||||
uuid = None
|
||||
active = False
|
||||
if buy['success']:
|
||||
o = Order(
|
||||
_bo = Order(
|
||||
trade_pair=self.trade_pair,
|
||||
trade_type=trade_type,
|
||||
buy=True,
|
||||
quantity=bid_amount,
|
||||
price=bid_price,
|
||||
uuid=buy['uuid']
|
||||
uuid=uuid,
|
||||
active=active
|
||||
)
|
||||
o.save()
|
||||
logging.info(f'[MARKET MAKER] Stored buy order as ID {o.id}')
|
||||
_bo.save()
|
||||
logging.info(f'[MARKET MAKER] Stored buy order as ID {_bo.id}')
|
||||
sleep(3)
|
||||
|
||||
logging.info(f'[MARKET MAKER] Submitting sell order for {ask_amount} at {ask_price} {self.trade_pair}')
|
||||
sell = self.submit_order('sell', self.trade_pair, ask_amount, ask_price)
|
||||
logging.debug(sell)
|
||||
if 'uuid' in sell:
|
||||
uuid = sell['uuid']
|
||||
active = True
|
||||
else:
|
||||
uuid = None
|
||||
active = False
|
||||
if sell['success']:
|
||||
o = Order(
|
||||
_so = Order(
|
||||
trade_pair=self.trade_pair,
|
||||
trade_type=trade_type,
|
||||
buy=False,
|
||||
quantity=ask_amount,
|
||||
price=ask_price,
|
||||
uuid=sell['uuid']
|
||||
uuid=uuid,
|
||||
active=active
|
||||
)
|
||||
o.save()
|
||||
logging.info(f'[MARKET MAKER] Stored sell order as ID {o.id}')
|
||||
_so.save()
|
||||
logging.info(f'[MARKET MAKER] Stored sell order as ID {_so.id}')
|
||||
else:
|
||||
logging.info(sell)
|
||||
else:
|
||||
logging.info(buy)
|
||||
else:
|
||||
|
@ -197,9 +213,7 @@ if __name__ == '__main__':
|
|||
|
||||
t = Trader()
|
||||
orders_counter = 0
|
||||
earnings_counter = 0
|
||||
balances_counter = 0
|
||||
market_maker_counter = 0
|
||||
|
||||
if not args.run and args.update_orders:
|
||||
t.reconcile_orders()
|
||||
|
@ -224,7 +238,7 @@ if __name__ == '__main__':
|
|||
except Exception as e:
|
||||
logging.info('[ERROR] Unable to store market data!', e)
|
||||
|
||||
# update orders every 4 minutes
|
||||
# update orders every 4 runs
|
||||
if args.update_orders:
|
||||
if orders_counter == 4:
|
||||
try:
|
||||
|
@ -235,7 +249,7 @@ if __name__ == '__main__':
|
|||
except Exception as e:
|
||||
logging.info('[ERROR] Unable to update orders!', e)
|
||||
|
||||
# update balances every 2 minutes
|
||||
# update balances every 2 runs
|
||||
if args.balances:
|
||||
if balances_counter == 2:
|
||||
try:
|
||||
|
@ -245,19 +259,17 @@ if __name__ == '__main__':
|
|||
except Exception as e:
|
||||
logging.info('[ERROR] Unable to update balances!', e)
|
||||
|
||||
# start market makers every 3 minutes
|
||||
# start market maker every run
|
||||
if args.market_maker:
|
||||
if market_maker_counter == 3:
|
||||
try:
|
||||
t.start_market_maker()
|
||||
logging.info('[MARKET MAKER] Resetting market maker counter')
|
||||
market_maker_counter = 0
|
||||
except Exception as e:
|
||||
logging.info('[ERROR] Unable to start market maker!', e)
|
||||
try:
|
||||
t.start_market_maker()
|
||||
except Exception as e:
|
||||
logging.info('[ERROR] Unable to start market maker!', e)
|
||||
|
||||
orders_counter += 1
|
||||
balances_counter += 1
|
||||
market_maker_counter += 1
|
||||
|
||||
# sleep 1 minute
|
||||
sleep(60)
|
||||
# sleep
|
||||
sleep_time = int(getenv('SLEEP_TIME', 20))
|
||||
logging.info(f'Sleeping for {sleep_time} seconds')
|
||||
sleep(sleep_time)
|
||||
|
|
Loading…
Reference in a new issue