diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index f532b681e..6058b7242 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -252,8 +252,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'] @@ -448,6 +446,12 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \ 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( @@ -478,8 +482,6 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \ 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(f'*Timeout:* Unfilled buy order for {pair_s} cancelled') 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]: