diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 5696724b9..474eabcf3 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1239,6 +1239,9 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(e) from e + def get_order_id_conditional(self, order: Dict[str, Any]) -> str: + return order['id'] + @retrier def get_fee(self, symbol: str, type: str = '', side: str = '', amount: float = 1, price: float = 1, taker_or_maker: str = 'maker') -> float: diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index fdfd5a674..9009e9492 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -8,6 +8,7 @@ from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, Invali OperationalException, TemporaryError) from freqtrade.exchange import Exchange from freqtrade.exchange.common import API_FETCH_ORDER_RETRY_COUNT, retrier +from freqtrade.misc import safe_value_fallback2 logger = logging.getLogger(__name__) @@ -135,3 +136,8 @@ class Ftx(Exchange): f'Could not cancel order due to {e.__class__.__name__}. Message: {e}') from e except ccxt.BaseError as e: raise OperationalException(e) from e + + def get_order_id_conditional(self, order: Dict[str, Any]) -> str: + if order['type'] == 'stop': + return safe_value_fallback2(order['info'], order, 'orderId', 'id') + return order['id'] diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index b3379a462..f451741a2 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1427,8 +1427,8 @@ class FreqtradeBot(LoggingMixin): """ fee-detection fallback to Trades. Parses result of fetch_my_trades to get correct fee. """ - trades = self.exchange.get_trades_for_order(order['id'], trade.pair, - trade.open_date) + trades = self.exchange.get_trades_for_order(self.exchange.get_order_id_conditional(order), + trade.pair, trade.open_date) if len(trades) == 0: logger.info("Applying fee on amount for %s failed: myTrade-Dict empty found", trade) diff --git a/tests/exchange/test_ftx.py b/tests/exchange/test_ftx.py index 494d86e56..63d99acdf 100644 --- a/tests/exchange/test_ftx.py +++ b/tests/exchange/test_ftx.py @@ -157,3 +157,26 @@ def test_fetch_stoploss_order(default_conf, mocker): 'fetch_stoploss_order', 'fetch_orders', retries=API_FETCH_ORDER_RETRY_COUNT + 1, order_id='_', pair='TKN/BTC') + + +def test_get_order_id(mocker, default_conf): + exchange = get_patched_exchange(mocker, default_conf, id='ftx') + order = { + 'type': STOPLOSS_ORDERTYPE, + 'price': 1500, + 'id': '1111', + 'info': { + 'orderId': '1234' + } + } + assert exchange.get_order_id_conditional(order) == '1234' + + order = { + 'type': 'limit', + 'price': 1500, + 'id': '1111', + 'info': { + 'orderId': '1234' + } + } + assert exchange.get_order_id_conditional(order) == '1111'