separating unfulfilled timeouts for buy and sell

This commit is contained in:
Nullart 2018-06-14 09:32:52 +08:00
parent 60ade25449
commit 5ed7008933
4 changed files with 26 additions and 10 deletions

View File

@ -5,7 +5,10 @@
"fiat_display_currency": "USD", "fiat_display_currency": "USD",
"ticker_interval" : "5m", "ticker_interval" : "5m",
"dry_run": false, "dry_run": false,
"unfilledtimeout": 600, "unfilledtimeout": {
"buy":10,
"sell":30
}
"bid_strategy": { "bid_strategy": {
"ask_last_balance": 0.0, "ask_last_balance": 0.0,
"use_book_order": true, "use_book_order": true,

View File

@ -12,7 +12,10 @@
"0": 0.04 "0": 0.04
}, },
"stoploss": -0.10, "stoploss": -0.10,
"unfilledtimeout": 600, "unfilledtimeout": {
"buy":10,
"sell":30
}
"bid_strategy": { "bid_strategy": {
"ask_last_balance": 0.0, "ask_last_balance": 0.0,
"use_book_order": true, "use_book_order": true,

View File

@ -55,7 +55,14 @@ CONF_SCHEMA = {
'minProperties': 1 'minProperties': 1
}, },
'stoploss': {'type': 'number', 'maximum': 0, 'exclusiveMaximum': True}, 'stoploss': {'type': 'number', 'maximum': 0, 'exclusiveMaximum': True},
'unfilledtimeout': {'type': 'integer', 'minimum': 0}, 'unfilledtimeout': {
'type': 'object',
'properties': {
'use_book_order': {'type': 'boolean'},
'buy': {'type': 'number', 'minimum':3},
'sell': {'type': 'number', 'minimum':10}
}
},
'bid_strategy': { 'bid_strategy': {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
@ -76,7 +83,7 @@ CONF_SCHEMA = {
'use_book_order': {'type': 'boolean'}, 'use_book_order': {'type': 'boolean'},
'book_order_min': {'type': 'number', 'minimum':1}, 'book_order_min': {'type': 'number', 'minimum':1},
'book_order_max': {'type': 'number', 'minimum':1} 'book_order_max': {'type': 'number', 'minimum':1}
}, }
}, },
'exchange': {'$ref': '#/definitions/exchange'}, 'exchange': {'$ref': '#/definitions/exchange'},
'experimental': { 'experimental': {

View File

@ -164,7 +164,7 @@ class FreqtradeBot(object):
if 'unfilledtimeout' in self.config: if 'unfilledtimeout' in self.config:
# Check and handle any timed out open orders # Check and handle any timed out open orders
self.check_handle_timedout(self.config['unfilledtimeout']) self.check_handle_timedout()
Trade.session.flush() Trade.session.flush()
except TemporaryError as error: except TemporaryError as error:
@ -461,19 +461,22 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
return True return True
return False 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 Check if any orders are timed out and cancel if neccessary
:param timeoutvalue: Number of minutes until order is considered timed out :param timeoutvalue: Number of minutes until order is considered timed out
:return: None :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(): for trade in Trade.query.filter(Trade.open_order_id.isnot(None)).all():
try: try:
# FIXME: Somehow the query above returns results # FIXME: Somehow the query above returns results
# where the open_order_id is in fact None. # where the open_order_id is in fact None.
# This is probably because the record got # This is probably because the record got
# updated via /forcesell in a different thread. # updated via /forcesell in a different thread.
if not trade.open_order_id: if not trade.open_order_id:
continue continue
@ -488,9 +491,9 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
# Check if trade is still actually open # Check if trade is still actually open
if (int(order['filled']) == 0) and (order['status']=='open'): if (int(order['filled']) == 0) and (order['status']=='open'):
if order['side'] == 'buy' and ordertime < timeoutthreashold: if order['side'] == 'buy' and ordertime < buy_timeoutthreashold:
self.handle_timedout_limit_buy(trade, order) self.handle_timedout_limit_buy(trade, order)
elif order['side'] == 'sell' and ordertime < timeoutthreashold: elif order['side'] == 'sell' and ordertime < sell_timeoutthreashold:
self.handle_timedout_limit_sell(trade, order) self.handle_timedout_limit_sell(trade, order)
# FIX: 20180110, why is cancel.order unconditionally here, whereas # FIX: 20180110, why is cancel.order unconditionally here, whereas