{"record":{"id":"24754c3e02dd5250","repo":"nautechsystems/nautilus_trader","slug":"unknown-order-direction","errorCode":null,"errorMessage":"Unknown order direction: {}","messagePattern":"Unknown order direction: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/websocket/parse.rs","lineNumber":721,"sourceCode":"\n/// Parses a Deribit user order message into a Nautilus `OrderStatusReport`.\n///\n/// # Errors\n///\n/// Returns an error if the order data cannot be parsed.\npub fn parse_user_order_msg(\n    msg: &DeribitOrderMsg,\n    instrument: &InstrumentAny,\n    account_id: AccountId,\n    ts_init: UnixNanos,\n) -> anyhow::Result<OrderStatusReport> {\n    let instrument_id = instrument.id();\n    let venue_order_id = VenueOrderId::new(&msg.order_id);\n\n    let order_side = match msg.direction.as_str() {\n        \"buy\" => OrderSide::Buy,\n        \"sell\" => OrderSide::Sell,\n        _ => anyhow::bail!(\"Unknown order direction: {}\", msg.direction),\n    };\n\n    // Map Deribit order type to Nautilus\n    let order_type = parse_deribit_order_type(&msg.order_type);\n\n    // Deribit supports: good_til_cancelled, good_til_day, fill_or_kill, immediate_or_cancel\n    let time_in_force = match msg.time_in_force.as_str() {\n        \"good_til_cancelled\" => TimeInForce::Gtc,\n        \"good_til_day\" => TimeInForce::Gtd,\n        \"fill_or_kill\" => TimeInForce::Fok,\n        \"immediate_or_cancel\" => TimeInForce::Ioc,\n        other => {\n            log::warn!(\"Unknown time_in_force '{other}', defaulting to GTC\");\n            TimeInForce::Gtc\n        }\n    };\n\n    // Map Deribit order state to Nautilus status","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/websocket/parse.rs#L703-L739","documentation":"Deribit user-order websocket messages include a `direction` field that must be \"buy\" or \"sell\". `parse_user_order_msg` maps this to Nautilus `OrderSide::Buy`/`Sell`. Any other string means the message cannot be translated into an OrderStatusReport, so the parse fails with this error.","triggerScenarios":"Calling `parse_user_order_msg` (directly or via `process_raw_message`/`generate_order_status_report`) with an order message whose `direction` is neither \"buy\" nor \"sell\" — e.g. an empty string, a changed/renamed field from Deribit, or a hand-crafted test payload.","commonSituations":"Deribit protocol changes or new order message variants; bugs in locally deserialized JSON (wrong field mapped to `direction`); constructing synthetic Deribit messages in tests or simulators with incorrect casing like \"Buy\".","solutions":["Log the raw message and inspect the actual `direction` value to see why it deviates","Normalize direction to lowercase \"buy\"/\"sell\" before passing the message to the parser","Update/patch the adapter if Deribit introduced a new direction value; otherwise treat the message as unparseable and skip it"],"exampleFix":"// before\nlet msg = DeribitOrderMsg { direction: \"Buy\".to_string(), .. };\nlet report = parse_user_order_msg(&msg, &instrument)?; // errors\n// after\nlet msg = DeribitOrderMsg { direction: msg.direction.to_lowercase(), .. };\nlet report = parse_user_order_msg(&msg, &instrument)?;","handlingStrategy":"validation","validationCode":"fn is_valid_direction(d: &str) -> bool { matches!(d, \"buy\" | \"sell\") }","typeGuard":"fn is_valid_direction(d: &str) -> bool { matches!(d, \"buy\" | \"sell\") }","tryCatchPattern":"match parse_user_order_msg(&msg, &instrument) {\n    Ok(report) => { /* use report */ }\n    Err(e) => tracing::error!(order_id = %msg.order_id, %e, \"dropping unparseable order message\"),\n}","preventionTips":["Normalize direction to lowercase before parsing","Log raw payloads for dropped messages to catch Deribit schema changes","Favor the adapter's own deserialization over hand-built test messages"],"tags":["rust","deribit","websocket","parsing","orders"],"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"}