From 75a649956d7222e0d5020e0bdddd8216623db194 Mon Sep 17 00:00:00 2001 From: Death916 Date: Sun, 9 Sep 2018 21:01:34 -0700 Subject: [PATCH] live --- getsignal.py | 20 ++++++++++++-------- trade.py | 16 +++++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/getsignal.py b/getsignal.py index 2b090b7..c557e7b 100644 --- a/getsignal.py +++ b/getsignal.py @@ -90,14 +90,18 @@ def main(): if trade.open_orders() != None: print(trade.open_orders()) - if time.time() - start_time > 1000: - - s.idle_done() - print('restarting connection') - s = gconnect() - s.idle() - start_time = time.time() - + if time.time() - start_time > 1740: + try: + s.idle_done() + print('restarting connection') + s = gconnect() + s.idle() + start_time = time.time() + except: + print('restart failed trying again') + s = gconnect() + s.idle() + start_time = time.time() diff --git a/trade.py b/trade.py index e5df1d3..c94e902 100644 --- a/trade.py +++ b/trade.py @@ -15,7 +15,7 @@ trex = Bittrex(api_key, priv_key) def marketcheck(ticker): - markets = trex.get_ticker(ticker) + markets = trex.get_ticker(ticker) price = markets['result']['Ask'] print(ticker, 'price is ', price) return price @@ -25,7 +25,8 @@ def open_trade(): global buyprice buyprice = marketcheck(ticker) global buy_amount - buy_amount = .0005 / buyprice + balance = trex.get_balance('BTC')['result']['Available'] + buy_amount = balance / buyprice # print(trex.buy_limit(ticker, amount, rate=buyprice)) print('buying', buy_amount, 'of', ticker) hist.tradehist('bought ' + str(buy_amount) + ' of ' + ticker + ' at ' + str(buyprice)) @@ -34,12 +35,13 @@ def open_trade(): def close_trade(): global sellprice sellprice = marketcheck(ticker) - amount = .0005 / sellprice - # print(trex.sell_limit(ticker, amount, rate=sellprice)) - print('selling', amount, 'of', ticker) - hist.tradehist('sold ' + str(amount) + ' of ' + ticker + ' at ' + str(sellprice)) global buy_amount - hist.tradehist('profit = ' + '{:.25f}'.format((sellprice * amount) - (buyprice * amount))) + sell_amount = buy_amount + #sell_amount = trex.get_balance('ETH')['result']['Available'] + # print(trex.sell_limit(ticker, amount, rate=sellprice)) + print('selling', sell_amount, 'of', ticker) + hist.tradehist('sold ' + str(sell_amount) + ' of ' + ticker + ' at ' + str(sellprice)) + hist.tradehist('profit = ' + '{:.25f}'.format((sellprice * sell_amount) - (buyprice * sell_amount))) def open_orders(): trex.get_open_orders()