{"record":{"id":"a7e4f01cc05b4a57","repo":"nautechsystems/nautilus_trader","slug":"invalid-instrument-type-for-okx-instrument","errorCode":null,"errorMessage":"Invalid instrument type for OKX: {instrument:?}","messagePattern":"Invalid instrument type for OKX: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/common/parse.rs","lineNumber":228,"sourceCode":"        .map_err(|e| serde::de::Error::custom(format!(\"Invalid VIP level '{s}': {e}\")))?;\n\n    Ok(OKXVipLevel::from(level_num))\n}\n\n/// Returns the [`OKXInstrumentType`] that corresponds to the supplied\n/// [`InstrumentAny`].\n///\n/// # Errors\n///\n/// Returns an error if the instrument variant is not supported by OKX.\npub fn okx_instrument_type(instrument: &InstrumentAny) -> anyhow::Result<OKXInstrumentType> {\n    match instrument {\n        InstrumentAny::BinaryOption(_) => Ok(OKXInstrumentType::Events),\n        InstrumentAny::CurrencyPair(_) => Ok(OKXInstrumentType::Spot),\n        InstrumentAny::CryptoPerpetual(_) => Ok(OKXInstrumentType::Swap),\n        InstrumentAny::CryptoFuture(_) => Ok(OKXInstrumentType::Futures),\n        InstrumentAny::CryptoOption(_) => Ok(OKXInstrumentType::Option),\n        _ => anyhow::bail!(\"Invalid instrument type for OKX: {instrument:?}\"),\n    }\n}\n\n/// Returns whether the OKX symbol uses the spread ID format.\n#[must_use]\npub fn is_okx_spread_symbol(symbol: &str) -> bool {\n    symbol.contains('_')\n}\n\n/// Parses `OKXInstrumentType` from an instrument symbol.\n///\n/// OKX instrument symbol formats:\n/// - SPOT: {BASE}-{QUOTE} (e.g., BTC-USDT)\n/// - MARGIN: {BASE}-{QUOTE} (same as SPOT, determined by trade mode)\n/// - SWAP: {BASE}-{QUOTE}-SWAP (e.g., BTC-USDT-SWAP)\n/// - FUTURES: {BASE}-{QUOTE}-{YYMMDD} (e.g., BTC-USDT-250328)\n/// - OPTION: {BASE}-{QUOTE}-{YYMMDD}-{STRIKE}-{C/P} (e.g., BTC-USD-250328-50000-C)\n/// - EVENTS: venue-defined event contract IDs (e.g., BTC-ABOVE-DAILY-260224-1600-65000)","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/common/parse.rs#L210-L246","documentation":"okx_instrument_type maps Nautilus instrument kinds to OKX instrument types (BinaryOption→Events, CurrencyPair→Spot, CryptoPerpetual→Swap, CryptoFuture→Futures, CryptoOption→Option). Any other instrument kind (equities, futures, spreads as instruments, etc.) has no OKX equivalent and is rejected.","triggerScenarios":"Calling any of the dependent entry points (request_mark_price, request_order_status_reports_scoped, request_fill_reports_scoped, request_position_status_reports_scoped, cancel_all_orders, place_order_with_domain_types) with a non-crypto instrument, e.g. an Equity or Future loaded into an OKX-centric strategy.","commonSituations":"Mixing instruments from other adapters in one portfolio/strategy; loading the wrong catalog instrument for an OKX symbol; spread instruments hitting the generic path instead of the spread-specific handling.","solutions":["Ensure only OKX-compatible instruments (spot, perpetual, dated future, option, binary) reach the OKX adapter","Check instrument loading/mapping so the correct InstrumentAny variant is constructed for the OKX symbol","Handle spreads via the adapter's spread ID path rather than generic instruments"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Rust\nfn okx_supported(inst: &InstrumentAny) -> bool {\n    matches!(inst,\n        InstrumentAny::BinaryOption(_)\n        | InstrumentAny::CurrencyPair(_)\n        | InstrumentAny::CryptoPerpetual(_)\n        | InstrumentAny::CryptoFuture(_)\n        | InstrumentAny::CryptoOption(_))\n}","typeGuard":"fn is_crypto_instrument(inst: &InstrumentAny) -> bool {\n    matches!(inst,\n        InstrumentAny::CurrencyPair(_) | InstrumentAny::CryptoPerpetual(_)\n        | InstrumentAny::CryptoFuture(_) | InstrumentAny::CryptoOption(_)\n        | InstrumentAny::BinaryOption(_))\n}","tryCatchPattern":null,"preventionTips":["Filter the instrument catalog to OKX-compatible kinds","Verify instrument construction when symbols resolve unexpectedly","Handle spread instruments through the dedicated spread path"],"tags":["rust","okx","instrument-mapping"],"backgroundTag":"invalid-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}