nautechsystems/nautilus_trader · error

Invalid `OrderType` cannot be represented on OKX

Error message

Invalid `OrderType` cannot be represented on OKX: {value:?}

What it means

This is the catch-all arm of the same From<OrderType> conversion for OKX: any OrderType not explicitly mapped (and not one of the conditional types) cannot be represented on OKX, so the conversion panics with the debug-formatted value. It indicates an unmapped or invalid core order type reached the OKX adapter.

Solutions

  1. Use an OrderType the OKX adapter explicitly supports (Market, Limit, and mapped variants)
  2. Update/align the core nautilus crate and OKX adapter versions so all variants are mapped
  3. Add a match arm mapping the new variant if OKX supports it
  4. Pre-validate OrderType against the adapter's supported set before submission

Example fix

// before
let okx_type = OKXOrderType::from(order_type); // panics for unmapped variant
// after
match order_type {
    OrderType::Market | OrderType::Limit => OKXOrderType::from(order_type),
    _ => return Err("order type not supported on OKX"),
}
Defensive patterns

Strategy: validation

Validate before calling

fn is_okx_supported(t: &OrderType) -> bool {
    matches!(t, OrderType::Market | OrderType::Limit | OrderType::StopMarket | OrderType::StopLimit | OrderType::MarketIfTouched | OrderType::LimitIfTouched | OrderType::TrailingStopMarket)
}

Prevention

When it happens

Trigger: Converting an OrderType variant with no OKX equivalent (e.g. a newly added core enum variant, or an invalid/default value) into OKXOrderType during order request building.

Common situations: Core enum gained a new variant the adapter was not updated for; corrupted or deserialized-invalid OrderType values flowing from strategy logic; version mismatch between core crate and OKX adapter crate.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/0d5e5314ce40a1e9. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/okx/src/common/enums.rs:1333

        }
    }
}

impl From<OrderType> for OKXOrderType {
    fn from(value: OrderType) -> Self {
        match value {
            OrderType::Market => Self::Market,
            OrderType::Limit => Self::Limit,
            OrderType::MarketToLimit => Self::Ioc,
            // Conditional orders will be handled separately via algo orders
            OrderType::StopMarket
            | OrderType::StopLimit
            | OrderType::MarketIfTouched
            | OrderType::LimitIfTouched
            | OrderType::TrailingStopMarket => {
                panic!("Conditional order types must use OKXAlgoOrderType")
            }
            _ => panic!("Invalid `OrderType` cannot be represented on OKX: {value:?}"),
        }
    }
}

impl From<PositionSide> for OKXPositionSide {
    fn from(value: PositionSide) -> Self {
        match value {
            PositionSide::Long => Self::Long,
            PositionSide::Short => Self::Short,
            PositionSide::Flat => Self::None,
        }
    }
}

#[derive(
    Copy,
    Clone,
    Debug,

View on GitHub (pinned to 18893faf8b)