better templatize commands and run processes
This commit is contained in:
parent
2a1d22646c
commit
11ebd2261f
77
trade.py
77
trade.py
|
@ -158,9 +158,10 @@ class Trader(TradeOgre):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = ArgumentParser(description='Helpful TradeOgre trading script')
|
parser = ArgumentParser(description='Helpful TradeOgre trading script')
|
||||||
parser.add_argument('-m', '--market-maker', action='store_true', help='Put in buy/sell orders')
|
parser.add_argument('--market-maker', action='store_true', help='Put in buy/sell orders')
|
||||||
parser.add_argument('-b', '--balances', action='store_true', help='Update coin balances of both base and currency')
|
parser.add_argument('--balances', action='store_true', help='Update coin balances of both base and currency')
|
||||||
parser.add_argument('-u', '--update-orders', action='store_true', help='Update status of orders')
|
parser.add_argument('--update-orders', action='store_true', help='Update status of orders')
|
||||||
|
parser.add_argument('--run', action='store_true', help='Run continuously')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
t = Trader()
|
t = Trader()
|
||||||
|
@ -181,42 +182,46 @@ if __name__ == '__main__':
|
||||||
t.store_balances()
|
t.store_balances()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
while True:
|
if args.run:
|
||||||
try:
|
while True:
|
||||||
t.store_market_data()
|
|
||||||
except Exception as e:
|
|
||||||
logging.info('[ERROR] Unable to store market data!', e)
|
|
||||||
|
|
||||||
# update orders every 5 minutes
|
|
||||||
if orders_counter == 5:
|
|
||||||
try:
|
try:
|
||||||
t.update_orders()
|
t.store_market_data()
|
||||||
logging.info('[ORDERS] Resetting orders counter')
|
|
||||||
orders_counter = 0
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info('[ERROR] Unable to update orders!', e)
|
logging.info('[ERROR] Unable to store market data!', e)
|
||||||
|
|
||||||
# update balances every 6 minutes
|
# update orders every 5 minutes
|
||||||
if balances_counter == 6:
|
if args.update_orders:
|
||||||
try:
|
if orders_counter == 5:
|
||||||
t.store_balances()
|
try:
|
||||||
logging.info('[BALANCE] Resetting balances counter')
|
t.update_orders()
|
||||||
balances_counter = 0
|
logging.info('[ORDERS] Resetting orders counter')
|
||||||
except Exception as e:
|
orders_counter = 0
|
||||||
logging.info('[ERROR] Unable to update balances!', e)
|
except Exception as e:
|
||||||
|
logging.info('[ERROR] Unable to update orders!', e)
|
||||||
|
|
||||||
# start market makers every 2 minutes
|
# update balances every 6 minutes
|
||||||
if market_maker_counter == 2:
|
if args.balances:
|
||||||
try:
|
if balances_counter == 6:
|
||||||
t.start_market_maker()
|
try:
|
||||||
logging.info('[MARKET MAKER] Resetting market maker counter')
|
t.store_balances()
|
||||||
market_maker_counter = 0
|
logging.info('[BALANCE] Resetting balances counter')
|
||||||
except Exception as e:
|
balances_counter = 0
|
||||||
logging.info('[ERROR] Unable to start market maker!', e)
|
except Exception as e:
|
||||||
|
logging.info('[ERROR] Unable to update balances!', e)
|
||||||
|
|
||||||
orders_counter += 1
|
# start market makers every 2 minutes
|
||||||
balances_counter += 1
|
if args.market_maker:
|
||||||
market_maker_counter += 1
|
if market_maker_counter == 2:
|
||||||
|
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)
|
||||||
|
|
||||||
# sleep 1 minute
|
orders_counter += 1
|
||||||
sleep(60)
|
balances_counter += 1
|
||||||
|
market_maker_counter += 1
|
||||||
|
|
||||||
|
# sleep 1 minute
|
||||||
|
sleep(60)
|
||||||
|
|
Loading…
Reference in New Issue