From 838d9cd4d0430566f890598a23425a4479a816ce Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 17 Mar 2024 15:17:04 +0100 Subject: [PATCH] Improve stop fills order handling on gate closes #9940 --- freqtrade/exchange/gate.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/freqtrade/exchange/gate.py b/freqtrade/exchange/gate.py index ffef21402..860a9faee 100644 --- a/freqtrade/exchange/gate.py +++ b/freqtrade/exchange/gate.py @@ -96,9 +96,7 @@ class Gate(Exchange): return trades def get_order_id_conditional(self, order: Dict[str, Any]) -> str: - if self.trading_mode == TradingMode.FUTURES: - return safe_value_fallback2(order, order, 'id_stop', 'id') - return order['id'] + return safe_value_fallback2(order, order, 'id_stop', 'id') def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: order = self.fetch_order( @@ -106,17 +104,18 @@ class Gate(Exchange): pair=pair, params={'stop': True} ) - if self.trading_mode == TradingMode.FUTURES: - if order['status'] == 'closed': - # Places a real order - which we need to fetch explicitly. - new_orderid = order.get('info', {}).get('trade_id') - if new_orderid: - order1 = self.fetch_order(order_id=new_orderid, pair=pair, params=params) - order1['id_stop'] = order1['id'] - order1['id'] = order_id - order1['stopPrice'] = order.get('stopPrice') + if order.get('status', 'open') == 'closed': + # Places a real order - which we need to fetch explicitly. + val = 'trade_id' if self.trading_mode == TradingMode.FUTURES else 'fired_order_id' - return order1 + if new_orderid := order.get('info', {}).get(val): + order1 = self.fetch_order(order_id=new_orderid, pair=pair, params=params) + order1['id_stop'] = order1['id'] + order1['id'] = order_id + order1['type'] = 'stoploss' + order1['stopPrice'] = order.get('stopPrice') + + return order1 return order def cancel_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: