Search code examples
pythonapiccxt

Creating OKEx orders using ccxt


I'm trying to make program for creating SWAP orders in OKEx with StopLoss and TakeProfit in DEMO trading mode using ccxt module. But I got error: The current account mode does not support this API interface. How I can solve it, and is there some examples of creating orders? My attempt:

params = {
        'tdMode': 'isolated',
        'tpOrdPx': '-1',
        'slOrdPx': '-1',
        'tpTriggerPx': take_profit,
        'slTriggerPx': stop_loss,
        'headers': {
            'x-simulated-trading': '1'
        }

    }
order = exchange.create_order(
        f"XRP/USDT:USDT", 'market', 'buy', summa, price, params=params)

Error code:

File "/home/excl/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 561, in throw_exactly_matched_exception
    raise exact[string](message)
ccxt.base.errors.AccountNotEnabled: okx {"code":"1","data":[{"clOrdId":"*id*","ordId":"","sCode":"51010","sMsg":"The current account mode does not support this API interface. ","tag":""}],"msg":"Operation failed."}


Solution

  • Solved by changing account mode from simple to portfolio mode. https://www.okx.com/academy/en/guide-to-portfolio-margin-mode-on-okex