From 7f881cce8571379a119571bd2c39608e363f04b7 Mon Sep 17 00:00:00 2001 From: gcarq Date: Fri, 8 Jun 2018 02:34:44 +0200 Subject: [PATCH 1/3] add additional None check for trade.open_order_id --- freqtrade/freqtradebot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index cd0c4b6d4..e0f71fea7 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -254,8 +254,6 @@ class FreqtradeBot(object): """ Checks the implemented trading indicator(s) for a randomly picked pair, if one pair triggers the buy_signal a new trade record gets created - :param stake_amount: amount of btc to spend - :param interval: Ticker interval used for Analyze :return: True if a trade object has been created and persisted, False otherwise """ stake_amount = self.config['stake_amount'] @@ -455,6 +453,10 @@ class FreqtradeBot(object): for trade in Trade.query.filter(Trade.open_order_id.isnot(None)).all(): try: + # FIXME: Somehow the query above returns results where the open_order_id is in fact None. + # This is probably because the record got updated via /forcesell in a different thread. + if not trade.open_order_id: + continue order = exchange.get_order(trade.open_order_id, trade.pair) except requests.exceptions.RequestException: logger.info( @@ -484,8 +486,6 @@ class FreqtradeBot(object): if order['remaining'] == order['amount']: # if trade is not partially completed, just delete the trade Trade.session.delete(trade) - # FIX? do we really need to flush, caller of - # check_handle_timedout will flush afterwards Trade.session.flush() logger.info('Buy order timeout for %s.', trade) self.rpc.send_msg('*Timeout:* Unfilled buy order for {} cancelled'.format( From 61b2373dd14eecbcdb86d3872df7923fe10008c0 Mon Sep 17 00:00:00 2001 From: gcarq Date: Fri, 8 Jun 2018 02:35:10 +0200 Subject: [PATCH 2/3] flush db connection after forcesell --- freqtrade/rpc/rpc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index c2f097319..abe9f6169 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -354,6 +354,7 @@ class RPC(object): return True, 'Invalid argument.' _exec_forcesell(trade) + Trade.session.flush() return False, '' def rpc_performance(self) -> Tuple[bool, Any]: From 10e12ec1b9ded5a83cf7fc4f241f9e24655ccc0d Mon Sep 17 00:00:00 2001 From: gcarq Date: Fri, 8 Jun 2018 02:37:12 +0200 Subject: [PATCH 3/3] fix flake8 warning --- freqtrade/freqtradebot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index e0f71fea7..b7f646114 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -453,8 +453,10 @@ class FreqtradeBot(object): for trade in Trade.query.filter(Trade.open_order_id.isnot(None)).all(): try: - # FIXME: Somehow the query above returns results where the open_order_id is in fact None. - # This is probably because the record got updated via /forcesell in a different thread. + # FIXME: Somehow the query above returns results + # where the open_order_id is in fact None. + # This is probably because the record got + # updated via /forcesell in a different thread. if not trade.open_order_id: continue order = exchange.get_order(trade.open_order_id, trade.pair)