nautechsystems/nautilus_trader · error
Conditional order types must use OKXAlgoOrderType
Error message
Conditional order types must use OKXAlgoOrderType
What it means
On OKX, conditional order types (stop, take-profit, trailing) are submitted through a separate algo-order API using OKXAlgoOrderType. The From<OrderType> conversion for regular orders deliberately panics when handed a conditional type, telling you to use OKXAlgoOrderType instead. It guards against silently mis-mapping trigger orders onto the plain order endpoint.
Source
Thrown at crates/adapters/okx/src/common/enums.rs:1331
OKXOrderType::Trigger => Ok(Self::StopMarket),
OKXOrderType::Other => Err(value),
}
}
}
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,View on GitHub (pinned to 18893faf8b)
Solutions
- Convert conditional order types to OKXAlgoOrderType and submit via the algo-order request path
- Check the OrderType before submission and branch: regular types via the standard conversion, conditional via algo orders
- If the order was not intended to be conditional, use Market or Limit instead
Example fix
// before let okx_type = OKXOrderType::from(OrderType::StopMarket); // panics // after let okx_algo = OKXAlgoOrderType::from(OrderType::StopMarket); // submit as algo order
Defensive patterns
Strategy: validation
Validate before calling
const OKX_ALGO_TYPES: &[OrderType] = &[
OrderType::StopMarket, OrderType::StopLimit,
OrderType::MarketIfTouched, OrderType::LimitIfTouched,
OrderType::TrailingStopMarket,
];
fn needs_algo_path(t: &OrderType) -> bool { OKX_ALGO_TYPES.contains(t) } Type guard
fn is_conditional_okx(t: &OrderType) -> bool {
matches!(t, OrderType::StopMarket | OrderType::StopLimit | OrderType::MarketIfTouched | OrderType::LimitIfTouched | OrderType::TrailingStopMarket)
} Prevention
- Split order submission into regular and algo paths and dispatch on OrderType early
- Never pass conditional OrderTypes through the plain OKX order conversion
- Keep OKXAlgoOrderType mappings in sync with core OrderType variants
When it happens
Trigger: Converting OrderType::StopMarket, StopLimit, MarketIfTouched, LimitIfTouched, or TrailingStopMarket into the OKX order-type enum during regular order request construction.
Common situations: A strategy emits conditional orders and the execution client funnels them through the standard order submission path; porting code from another venue where conditional types are ordinary order params.
Related errors
- Invalid `OrderType` cannot be represented on OKX: {value:?}
- Not a conditional order type: {order_type:?}
- instrument update lock poisoned
- Unsupported OrderType for conditional orders: {value:?}
- Invalid OKX websocket channel
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/c603dcda134ef4db.
Report an issue: GitHub.