Skip to content

[OKX] Add support for instIdCode parameter in WebSocket order operations #3507

@sronger

Description

@sronger

Feature Request

Problem Statement

OKX has announced a breaking API change that affects WebSocket order operations. Starting from January 29, 2026 (demo environment) and February 3, 2026 (production environment), the instId request parameter will be deprecated in favor of instIdCode.

Currently, NautilusTrader v1.222.0 uses the instId parameter for WebSocket order operations, which now causes order rejections in the OKX demo environment with the error:

Parameter instIdCode can not be empty

Affected WebSocket channels:

  • WS / Place order
  • WS / Place multiple orders
  • WS / Amend order
  • WS / Amend multiple orders
  • WS / Cancel order
  • WS / Cancel multiple orders

Reference: OKX API Changelog - Delist instId request parameter

Proposed Solution

Update the OKX adapter to:

  1. Fetch instIdCode when loading instruments via the GET /api/v5/public/instruments endpoint
  2. Store the instIdCode mapping in the OKXInstrumentProvider
  3. Use instIdCode instead of (or alongside) instId in all WebSocket order operations

The instIdCode is available in the instruments endpoint response and can be mapped to instId during instrument loading.

Example Usage

# No changes needed in user code - the adapter should handle this internally

# The OKXInstrumentProvider should cache instIdCode from instruments response:
# GET /api/v5/public/instruments returns:
# {
#     "instId": "BTC-USDT-SWAP",
#     "instIdCode": 12345,  # Numeric instrument ID code
#     ...
# }

# When submitting orders via WebSocket, the adapter should use:
# {
#     "instIdCode": 12345,  # Instead of "instId": "BTC-USDT-SWAP"
#     "tdMode": "isolated",
#     "side": "buy",
#     ...
# }

Alternatives Considered

Send both instId and instIdCode: According to OKX docs, if both are provided, instIdCode takes precedence. This could be a transitional approach.

Additional Context

Test Environment:

  • NautilusTrader version: 1.222.0
  • Python: 3.12.11
  • OKX Demo Mode: is_demo=True
  • Test Date: 2026-01-29 (first day of deprecation in demo environment)

Error Log:

[WARN] TEST-TRADER-001.TESTTRADE: <--[EVT] OrderRejected(
    instrument_id=BTC-USDT-SWAP.OKX, 
    client_order_id=O20260129081611001T1, 
    account_id=OKX-master, 
    reason='Parameter instIdCode can not be empty'
)

Timeline:

  • Demo environment deprecation: January 29, 2026
  • Production environment deprecation: February 3, 2026

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions