Repository: freqtrade/freqtrade

Issue:
Problem with closing trade processing on OKX
## Describe your environment

  * Operating system: Ubuntu 22.04.2 LTS
  * Python Version: Python 3.10.6
  * CCXT version: 3.1.5
  * Freqtrade Version: 2023.5.dev-09aaf894c
  
## Describe the problem:

Bot can not correctly handle the completion of the trade on OKX when closing through the stoploss

```
2023-05-23 06:44:19,845 - urllib3.connectionpool - DEBUG - https://www.okx.com:443 "GET /api/v5/trade/order-algo?instId=BTC-USDT-SWAP&algoId=580485014375514124 HTTP/1.1" 200 892
2023-05-23 06:44:19,847 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: {'info': {'activePx': '', 'actualPx': '27670.8', 'actualSide': 'sl', 'actualSz': '97', 'algoClOrdId': 'ffb5405ad327SUDEcc58fcc3e7f72696', 'algoId': '580485014375514124', 'cTime': '1684670412317', 'callbackRatio': '', 'callbackSpread': '', 'ccy': '', 'clOrdId': 'ffb5405ad327SUDEcc58fcc3e7f72696', 'closeFraction': '', 'failCode': '', 'instId': 'BTC-USDT-SWAP', 'instType': 'SWAP', 'last': '26821.1', 'lever': '3', 'moveTriggerPx': '', 'ordId': '581079085670350884', 'ordPx': '', 'ordType': 'conditional', 'posSide': 'net', 'pxLimit': '', 'pxSpread': '', 'pxVar': '', 'quickMgnType': '', 'reduceOnly': 'true', 'side': 'buy', 'slOrdPx': '27670.8', 'slTriggerPx': '27396.8', 'slTriggerPxType': 'last', 'state': 'effective', 'sz': '97', 'szLimit': '', 'tag': 'ffb5405ad327SUDE', 'tdMode': 'isolated', 'tgtCcy': '', 'timeInterval': '', 'tpOrdPx': '', 'tpTriggerPx': '', 'tpTriggerPxType': '', 'triggerPx': '', 'triggerPxType': '', 'triggerTime': '1684812049951'}, 'id': '580485014375514124', 'clientOrderId': 'ffb5405ad327SUDEcc58fcc3e7f72696', 'timestamp': 1684670412317, 'datetime': '2023-05-21T12:00:12.317Z', 'lastTradeTimestamp': None, 'symbol': 'BTC/USDT:USDT', 'type': 'conditional', 'timeInForce': None, 'postOnly': None, 'side': 'buy', 'price': None, 'stopLossPrice': 27396.8, 'takeProfitPrice': None, 'stopPrice': None, 'triggerPrice': None, 'average': None, 'cost': None, 'amount': 97.0, 'filled': None, 'remaining': None, 'status': 'closed', 'fee': None, 'trades': [], 'reduceOnly': True, 'fees': []}
2023-05-23 06:44:20,045 - urllib3.connectionpool - DEBUG - https://www.okx.com:443 "GET /api/v5/trade/fills-history?instId=BTC-USDT-SWAP&instType=SWAP HTTP/1.1" 200 None
2023-05-23 06:44:20,049 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
2023-05-23 06:44:20,050 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=1, pair=BTC/USDT:USDT, amount=0.97000000, is_short=True, leverage=3.0, open_rate=26824.50000000, open_since=closed) failed: myTrade-Dict empty found
2023-05-23 06:44:20,050 - freqtrade.persistence.trade_model - INFO - Updating trade (id=1) ...
2023-05-23 06:44:20,051 - freqtrade.persistence.trade_model - DEBUG - BTC/USDT:USDT - Adjusting stoploss...
2023-05-23 06:44:20,051 - freqtrade.persistence.trade_model - DEBUG - BTC/USDT:USDT - Stoploss adjusted. current_price=26824.50000000, open_rate=26824.50000000, max_rate=27376.00000000, initial_stop_loss=27396.80000000, stop_loss=27396.80000000. Trailing stoploss saved us: 0.00000000.
2023-05-23 06:44:20,052 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=1, pair=BTC/USDT:USDT, amount=0.97000000, is_short=True, leverage=3.0, open_rate=26824.50000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
2023-05-23 06:44:20,238 - urllib3.connectionpool - DEBUG - https://www.okx.com:443 "GET /api/v5/account/balance HTTP/1.1" 200 630
2023-05-23 06:44:20,445 - urllib3.connectionpool - DEBUG - https://www.okx.com:443 "GET /api/v5/account/positions HTTP/1.1" 200 31
2023-05-23 06:44:20,446 - freqtrade.exchange.exchange - INFO - API fetch_positions: []
2023-05-23 06:44:20,447 - freqtrade.wallets - INFO - Wallets synced.
2023-05-23 06:44:20,455 - freqtrade.plugins.pairlistmanager - DEBUG - Whitelist with 1 pairs: ['BTC/USDT:USDT']
2023-05-23 06:44:20,456 - freqtrade.exchange.exchange - DEBUG - Refreshing candle (OHLCV) data for 1 pairs
2023-05-23 06:44:20,457 - freqtrade.exchange.exchange - DEBUG - Using cached candle (OHLCV) data for BTC/USDT:USDT, 4h, futures ...
2023-05-23 06:44:20,458 - freqtrade.strategy.interface - DEBUG - Skipping TA Analysis for already analyzed candle
2023-05-23 06:44:20,460 - freqtrade.strategy.interface - DEBUG - Loop Analysis Launched
2023-05-23 06:44:20,463 - freqtrade.freqtradebot - DEBUG - create_trade for pair BTC/USDT:USDT
2023-05-23 06:44:20,467 - freqtrade.strategy.interface - DEBUG - entry trigger: 2023-05-23 00:00:00+00:00 (pair=BTC/USDT:USDT) enter=False enter_tag_value=None
2023-05-23 06:44:20,467 - freqtrade.freqtradebot - DEBUG - Found no enter signals for whitelisted currencies. Trying again...
2023-05-23 06:44:20,468 - freqtrade.worker - DEBUG - Throttling with '_process_running()': sleep for 4.35 s, last iteration took 0.65 s.
2023-05-23 06:44:24,827 - freqtrade.worker - DEBUG - ========================================
```


config.json:
```
class MyStrat(IStrategy):
    INTERFACE_VERSION = 3
...
    # Optional order type mapping.
    order_types = {
        'entry': 'limit',
        'exit': 'limit',
        'stoploss': 'limit',
        'stoploss_on_exchange': True,
        'stoploss_on_exchange_limit_ratio': 0.99,
        'stoploss_on_exchange_interval': 60
    }
```

### Steps to reproduce:

  1. Open a position on OKX futures BTC/USDT
  2. Set stoploss-limit
  3. After the stoploss is triggered the position is closed
  4. The message above is repeated in the log without stopping. The bot is unable to process the closing of the trade.
  



Discussion:
i don't really find the above log helpful / saying anything, really.

I'd probably go with non-debug logs instead, and a bit "more" where more activity is shown.


Also, please provide the output of the following command for the affected trade:
`freqtrade show-trades --db-url sqlite:///<trades.sqlite> --print-json --trade-ids <tradeid>` 
Best use a "details block" to keep the issue itself kindof readable (see below for details on how to do that). 

<details>
<summary>Expand to see how to do details blocks</summary>

```
<details>
<summary>Expand full </summary>
(wrap in tripple ticks `)
Trades output ...
</details>
```
</details>
Full log after restart:
<details>
<summary>Expand full </summary>

```
2023-05-23 08:05:31,231 - freqtrade.commands.trade_commands - INFO - SIGINT received, aborting ...
2023-05-23 08:05:31,232 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
2023-05-23 08:05:31,232 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2023-05-23 08:05:31,233 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2023-05-23 08:05:31,236 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2023-05-23 08:05:31,247 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc.telegram ...
2023-05-23 08:05:31,251 - telegram.ext.Application - INFO - Application is stopping. This might take a moment.
2023-05-23 08:05:31,252 - telegram.ext.Application - INFO - Application.stop() complete
2023-05-23 08:05:36,684 - freqtrade.loggers - INFO - Verbosity set to 0
2023-05-23 08:05:36,685 - freqtrade.configuration.configuration - INFO - Runmode set to live.
2023-05-23 08:05:36,685 - freqtrade.configuration.configuration - INFO - Dry run is disabled
2023-05-23 08:05:36,686 - freqtrade.configuration.configuration - INFO - Using DB: "sqlite:///tradesv3.sqlite"
2023-05-23 08:05:36,686 - freqtrade.configuration.configuration - INFO - Using max_open_trades: 1 ...
2023-05-23 08:05:36,687 - freqtrade.configuration.configuration - INFO - Using user-data directory: /srv/freqtrade/user_data ...
2023-05-23 08:05:36,687 - freqtrade.configuration.configuration - INFO - Using data directory: /srv/freqtrade/user_data/data/okx ...
2023-05-23 08:05:36,688 - freqtrade.exchange.check_exchange - INFO - Checking exchange...
2023-05-23 08:05:36,693 - freqtrade.exchange.check_exchange - INFO - Exchange "okx" is officially supported by the Freqtrade development team.
2023-05-23 08:05:36,694 - freqtrade.configuration.configuration - INFO - Using pairlist from configuration.
2023-05-23 08:05:36,709 - freqtrade.resolvers.iresolver - INFO - Using resolved strategy MyStrat from '/srv/freqtrade/user_data/strategies/strat.py'...
2023-05-23 08:05:36,710 - freqtrade.strategy.hyper - INFO - Loading parameters from file /srv/freqtrade/user_data/strategies/strat.json
2023-05-23 08:05:36,711 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_currency' with value in config file: USDT.
2023-05-23 08:05:36,712 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_amount' with value in config file: unlimited.
2023-05-23 08:05:36,712 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'unfilledtimeout' with value in config file: {'entry': 10, 'exit': 10, 'exit_timeout_count': 0, 'unit': 'minutes'}.
2023-05-23 08:05:36,712 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'max_open_trades' with value in config file: 1.
2023-05-23 08:05:36,713 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using minimal_roi: {'0': 0.471, '1660': 0.32, '3320': 0.115, '7000': 0}
2023-05-23 08:05:36,713 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using timeframe: 4h
2023-05-23 08:05:36,713 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stoploss: -0.06
2023-05-23 08:05:36,713 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop: True
2023-05-23 08:05:36,715 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using use_custom_stoploss: True
2023-05-23 08:05:36,715 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using process_only_new_candles: True
2023-05-23 08:05:36,716 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_types: {'entry': 'limit', 'exit': 'limit', 'stoploss': 'limit', 'stoploss_on_exchange': True, 'stoploss_on_exchange_limit_ratio': 0.99, 'stoploss_on_exchange_interval': 60}
2023-05-23 08:05:36,716 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_time_in_force: {'entry': 'GTC', 'exit': 'GTC'}
2023-05-23 08:05:36,717 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_currency: USDT
2023-05-23 08:05:36,717 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_amount: unlimited
2023-05-23 08:05:36,717 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using protections: []
2023-05-23 08:05:36,717 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using startup_candle_count: 200
2023-05-23 08:05:36,718 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using unfilledtimeout: {'entry': 10, 'exit': 10, 'exit_timeout_count': 0, 'unit': 'minutes'}
2023-05-23 08:05:36,718 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using use_exit_signal: True
2023-05-23 08:05:36,718 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using exit_profit_only: False
2023-05-23 08:05:36,719 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ignore_roi_if_entry_signal: False
2023-05-23 08:05:36,719 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using exit_profit_offset: 0.0
2023-05-23 08:05:36,719 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using disable_dataframe_checks: False
2023-05-23 08:05:36,719 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ignore_buying_expired_candle_after: 0
2023-05-23 08:05:36,720 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using position_adjustment_enable: False
2023-05-23 08:05:36,720 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using max_entry_position_adjustment: -1
2023-05-23 08:05:36,720 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using max_open_trades: 1
2023-05-23 08:05:36,721 - freqtrade.configuration.config_validation - INFO - Validating configuration ...
2023-05-23 08:05:36,727 - freqtrade.exchange.exchange - INFO - Using CCXT 3.1.5
2023-05-23 08:05:36,728 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'options': {'defaultType': 'swap'}}
2023-05-23 08:05:36,735 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'options': {'defaultType': 'swap'}}
2023-05-23 08:05:36,742 - freqtrade.exchange.exchange - INFO - Using Exchange "OKX"
2023-05-23 08:05:38,167 - freqtrade.exchange.exchange - INFO - Using cached leverage_tiers.
2023-05-23 08:05:38,169 - freqtrade.exchange.exchange - INFO - Done initializing 132 markets.
2023-05-23 08:05:38,199 - freqtrade.exchange.exchange - INFO - API fetch_accounts: [{'id': '142906101556453376', 'type': '2', 'currency': None, 'info': {'acctLv': '2', 'autoLoan': False, 'ctIsoMode': 'automatic', 'greeksType': 'PA', 'ip': '45.136.197.129', 'label': 'Key', 'level': 'Lv1', 'levelTmp': '', 'liquidationGear': '2', 'mgnIsoMode': 'automatic', 'opAuth': '0', 'posMode': 'net_mode', 'roleType': '0', 'spotOffsetType': '', 'traderInsts': [], 'uid': '142906101556453376'}}]
2023-05-23 08:05:38,200 - freqtrade.resolvers.exchange_resolver - INFO - Using resolved exchange 'Okx'...
2023-05-23 08:05:38,600 - freqtrade.exchange.exchange - INFO - API fetch_positions: []
2023-05-23 08:05:38,602 - freqtrade.wallets - INFO - Wallets synced.
2023-05-23 08:05:38,612 - freqtrade.resolvers.iresolver - INFO - Using resolved pairlist StaticPairList from '/srv/freqtrade/freqtrade/plugins/pairlist/StaticPairList.py'...
2023-05-23 08:05:38,733 - freqtrade.rpc.rpc_manager - INFO - Enabling rpc.telegram ...
2023-05-23 08:05:38,965 - freqtrade.resolvers.iresolver - INFO - Using resolved pairlist StaticPairList from '/srv/freqtrade/freqtrade/plugins/pairlist/StaticPairList.py'...
2023-05-23 08:05:38,980 - freqtrade.plugins.pairlistmanager - INFO - Whitelist with 1 pairs: ['BTC/USDT:USDT']
2023-05-23 08:05:38,987 - freqtrade.strategy.hyper - INFO - No params for buy found, using default values.
2023-05-23 08:05:38,988 - freqtrade.strategy.hyper - INFO - No params for sell found, using default values.
2023-05-23 08:05:38,993 - freqtrade.strategy.hyper - INFO - Strategy Parameter(default): trailing_exit = 0.001
2023-05-23 08:05:38,994 - freqtrade.strategy.hyper - INFO - No params for protection found, using default values.
2023-05-23 08:05:38,994 - freqtrade.plugins.protectionmanager - INFO - No protection Handlers defined.
2023-05-23 08:05:38,995 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'running'}
2023-05-23 08:05:38,995 - freqtrade.worker - INFO - Changing state to: RUNNING
2023-05-23 08:05:39,010 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': startup, 'status': "*Exchange:* `okx`\n*Stake per trade:* `unlimited USDT`\n*Minimum ROI:* `{'0': 0.4, '1660': 0.3, '3320': 0.1, '7000': 0}`\n*Trailing Stoploss:* `-0.064`\n*Position adjustment:* `Off`\n*Timeframe:* `4h`\n*Strategy:* `MyStrat`"}
2023-05-23 08:05:39,011 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': startup, 'status': "Searching for USDT pairs to buy and sell based on [{'StaticPairList': 'StaticPairList'}]"}
2023-05-23 08:05:39,030 - freqtrade.freqtradebot - INFO - Updating 0 open orders.
2023-05-23 08:05:39,044 - freqtrade.freqtradebot - INFO - Updating buy-fee on trade Trade(id=1, pair=BTC/USDT:USDT, amount=0.97000000, is_short=True, leverage=3.0, open_rate=26824.50000000, open_since=closed)for order 580485014375514124.
2023-05-23 08:05:39,071 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: {'info': {'activePx': '', 'actualPx': '27670.8', 'actualSide': 'sl', 'actualSz': '97', 'algoClOrdId': 'ffb5405ad327SUDEcc58fcc3e7f72696', 'algoId': '580485014375514124', 'cTime': '1684670412317', 'callbackRatio': '', 'callbackSpread': '', 'ccy': '', 'clOrdId': 'ffb5405ad327SUDEcc58fcc3e7f72696', 'closeFraction': '', 'failCode': '', 'instId': 'BTC-USDT-SWAP', 'instType': 'SWAP', 'last': '26821.1', 'lever': '3', 'moveTriggerPx': '', 'ordId': '581079085670350884', 'ordPx': '', 'ordType': 'conditional', 'posSide': 'net', 'pxLimit': '', 'pxSpread': '', 'pxVar': '', 'quickMgnType': '', 'reduceOnly': 'true', 'side': 'buy', 'slOrdPx': '27670.8', 'slTriggerPx': '27396.8', 'slTriggerPxType': 'last', 'state': 'effective', 'sz': '97', 'szLimit': '', 'tag': 'ffb5405ad327SUDE', 'tdMode': 'isolated', 'tgtCcy': '', 'timeInterval': '', 'tpOrdPx': '', 'tpTriggerPx': '', 'tpTriggerPxType': '', 'triggerPx': '', 'triggerPxType': '', 'triggerTime': '1684812049951'}, 'id': '580485014375514124', 'clientOrderId': 'ffb5405ad327SUDEcc58fcc3e7f72696', 'timestamp': 1684670412317, 'datetime': '2023-05-21T12:00:12.317Z', 'lastTradeTimestamp': None, 'symbol': 'BTC/USDT:USDT', 'type': 'conditional', 'timeInForce': None, 'postOnly': None, 'side': 'buy', 'price': None, 'stopLossPrice': 27396.8, 'takeProfitPrice': None, 'stopPrice': None, 'triggerPrice': None, 'average': None, 'cost': None, 'amount': 97.0, 'filled': None, 'remaining': None, 'status': 'closed', 'fee': None, 'trades': [], 'reduceOnly': True, 'fees': []}
2023-05-23 08:05:39,152 - freqtrade.rpc.telegram - INFO - rpc.telegram is listening for following commands: [['status'], ['profit'], ['balance'], ['start'], ['stop'], ['forceexit', 'forcesell', 'fx'], ['forcebuy', 'forcelong'], ['forceshort'], ['reload_trade'], ['trades'], ['delete'], ['cancel_open_order', 'coo'], ['performance'], ['buys', 'entries'], ['exits', 'sells'], ['mix_tags'], ['stats'], ['daily'], ['weekly'], ['monthly'], ['count'], ['locks'], ['delete_locks', 'unlock'], ['reload_conf', 'reload_config'], ['show_conf', 'show_config'], ['stopbuy', 'stopentry'], ['whitelist'], ['blacklist'], ['bl_delete', 'blacklist_delete'], ['logs'], ['edge'], ['health'], ['help'], ['version'], ['marketdir']]
2023-05-23 08:05:39,269 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
2023-05-23 08:05:39,270 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=1, pair=BTC/USDT:USDT, amount=0.97000000, is_short=True, leverage=3.0, open_rate=26824.50000000, open_since=closed) failed: myTrade-Dict empty found
2023-05-23 08:05:39,271 - freqtrade.persistence.trade_model - INFO - Updating trade (id=1) ...
2023-05-23 08:05:39,272 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=1, pair=BTC/USDT:USDT, amount=0.97000000, is_short=True, leverage=3.0, open_rate=26824.50000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
2023-05-23 08:05:39,660 - freqtrade.exchange.exchange - INFO - API fetch_positions: []
2023-05-23 08:05:39,661 - freqtrade.wallets - INFO - Wallets synced.
...
```
</details>

(.env) root:/srv/freqtrade# freqtrade show-trades --db-url sqlite:///tradesv3.sqlite --print-json
<details>
<summary>Expand full </summary>

```
[
    {
        "trade_id": 1,
        "pair": "BTC/USDT:USDT",
        "base_currency": "BTC",
        "quote_currency": "USDT",
        "is_open": false,
        "exchange": "okx",
        "amount": 0.97,
        "amount_requested": 0.97102358,
        "stake_amount": 8673.255,
        "max_stake_amount": 26019.765,
        "strategy": "MyStrat",
        "enter_tag": null,
        "timeframe": 240,
        "fee_open": 0.0002,
        "fee_open_cost": 5.203953,
        "fee_open_currency": "USDT",
        "fee_close": 0.0002,
        "fee_close_cost": null,
        "fee_close_currency": null,
        "open_date": "2023-05-21 12:00:07",
        "open_timestamp": 1684670407355,
        "open_rate": 26824.5,
        "open_rate_requested": 26824.5,
        "open_trade_value": 26014.561047,
        "close_date": "2023-05-23 03:20:53",
        "close_timestamp": 1684812053150,
        "realized_profit": 0.0,
        "realized_profit_ratio": null,
        "close_rate": 27396.8,
        "close_rate_requested": 27396.8,
        "close_profit": null,
        "close_profit_pct": null,
        "close_profit_abs": null,
        "trade_duration_s": 141645,
        "trade_duration": 2360,
        "profit_ratio": null,
        "profit_pct": null,
        "profit_abs": null,
        "exit_reason": "stoploss_on_exchange",
        "exit_order_status": "closed",
        "stop_loss_abs": 27396.8,
        "stop_loss_ratio": -0.064,
        "stop_loss_pct": -6.4,
        "stoploss_order_id": null,
        "stoploss_last_update": "2023-05-21 12:00:12",
        "stoploss_last_update_timestamp": 1684670412393,
        "initial_stop_loss_abs": 27396.8,
        "initial_stop_loss_ratio": -0.064,
        "initial_stop_loss_pct": -6.4,
        "min_rate": 26540.3,
        "max_rate": 27376.0,
        "leverage": 3.0,
        "interest_rate": 0.0,
        "liquidation_price": 35166.61531607765,
        "is_short": true,
        "trading_mode": "futures",
        "funding_fees": 0.0,
        "open_order_id": null,
        "amount_precision": 1.0,
        "price_precision": 0.1,
        "precision_mode": 4,
        "orders": [
            {
                "amount": 0.97,
                "safe_price": 26824.5,
                "ft_order_side": "sell",
                "order_filled_timestamp": 1684670411202,
                "ft_is_entry": true,
                "pair": "BTC/USDT:USDT",
                "order_id": "580484993232027648",
                "status": "closed",
                "average": 26824.5,
                "cost": 260.19765,
                "filled": 0.97,
                "is_open": false,
                "order_date": "2023-05-21 12:00:07",
                "order_timestamp": 1684670407276,
                "order_filled_date": "2023-05-21 12:00:11",
                "order_type": "limit",
                "price": 26824.5,
                "remaining": 0.0
            }
        ]
    }
]
```

</details>


Resolving patch:
diff --git a/freqtrade/exchange/okx.py b/freqtrade/exchange/okx.py
--- a/freqtrade/exchange/okx.py
+++ b/freqtrade/exchange/okx.py
@@ -169,6 +169,22 @@ def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) ->
             params['posSide'] = self._get_posSide(side, True)
         return params
 
+    def _convert_stop_order(self, pair: str, order_id: str, order: Dict) -> Dict:
+        if (
+            order['status'] == 'closed'
+            and (real_order_id := order.get('info', {}).get('ordId')) is not None
+        ):
+            # Once a order triggered, we fetch the regular followup order.
+            order_reg = self.fetch_order(real_order_id, pair)
+            self._log_exchange_response('fetch_stoploss_order1', order_reg)
+            order_reg['id_stop'] = order_reg['id']
+            order_reg['id'] = order_id
+            order_reg['type'] = 'stoploss'
+            order_reg['status_stop'] = 'triggered'
+            return order_reg
+        order['type'] = 'stoploss'
+        return order
+
     def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict:
         if self._config['dry_run']:
             return self.fetch_dry_run_order(order_id)
@@ -177,7 +193,7 @@ def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> D
             params1 = {'stop': True}
             order_reg = self._api.fetch_order(order_id, pair, params=params1)
             self._log_exchange_response('fetch_stoploss_order', order_reg)
-            return order_reg
+            return self._convert_stop_order(pair, order_id, order_reg)
         except ccxt.OrderNotFound:
             pass
         params2 = {'stop': True, 'ordType': 'conditional'}
@@ -188,18 +204,7 @@ def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> D
                 orders_f = [order for order in orders if order['id'] == order_id]
                 if orders_f:
                     order = orders_f[0]
-                    if (order['status'] == 'closed'
-                            and (real_order_id := order.get('info', {}).get('ordId')) is not None):
-                        # Once a order triggered, we fetch the regular followup order.
-                        order_reg = self.fetch_order(real_order_id, pair)
-                        self._log_exchange_response('fetch_stoploss_order1', order_reg)
-                        order_reg['id_stop'] = order_reg['id']
-                        order_reg['id'] = order_id
-                        order_reg['type'] = 'stoploss'
-                        order_reg['status_stop'] = 'triggered'
-                        return order_reg
-                    order['type'] = 'stoploss'
-                    return order
+                    return self._convert_stop_order(pair, order_id, order)
             except ccxt.BaseError:
                 pass
         raise RetryableOrderError(


Test patch: