separating unfulfilled timeouts for buy and sell

This commit is contained in:
Nullart
2018-06-14 09:32:52 +08:00
committed by xmatthias
parent 6dd5f85fb6
commit 98108a78f1
6 changed files with 36 additions and 15 deletions

View File

@@ -160,7 +160,7 @@ class FreqtradeBot(object):
if 'unfilledtimeout' in self.config:
# Check and handle any timed out open orders
self.check_handle_timedout(self.config['unfilledtimeout'])
self.check_handle_timedout()
Trade.session.flush()
except TemporaryError as error:
@@ -492,13 +492,16 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
logger.info('Found no sell signals for whitelisted currencies. Trying again..')
return False
def check_handle_timedout(self, timeoutvalue: int) -> None:
def check_handle_timedout(self) -> None:
"""
Check if any orders are timed out and cancel if neccessary
:param timeoutvalue: Number of minutes until order is considered timed out
:return: None
"""
timeoutthreashold = arrow.utcnow().shift(minutes=-timeoutvalue).datetime
buy_timeout = self.config['unfilledtimeout']['buy']
sell_timeout = self.config['unfilledtimeout']['sell']
buy_timeoutthreashold = arrow.utcnow().shift(minutes=-buy_timeout).datetime
sell_timeoutthreashold = arrow.utcnow().shift(minutes=-sell_timeout).datetime
for trade in Trade.query.filter(Trade.open_order_id.isnot(None)).all():
try:
@@ -521,10 +524,12 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
if int(order['remaining']) == 0:
continue
if order['side'] == 'buy' and ordertime < timeoutthreashold:
self.handle_timedout_limit_buy(trade, order)
elif order['side'] == 'sell' and ordertime < timeoutthreashold:
self.handle_timedout_limit_sell(trade, order)
# Check if trade is still actually open
if (order['status'] == 'open'):
if order['side'] == 'buy' and ordertime < buy_timeoutthreashold:
self.handle_timedout_limit_buy(trade, order)
elif order['side'] == 'sell' and ordertime < sell_timeoutthreashold:
self.handle_timedout_limit_sell(trade, order)
# FIX: 20180110, why is cancel.order unconditionally here, whereas
# it is conditionally called in the