{"record":{"id":"5fc7de570a3bf7f2","repo":"nautechsystems/nautilus_trader","slug":"invalid-type-for-bbo-side-type-value-expecte","errorCode":null,"errorMessage":"invalid type for 'bbo_side_type': {value}, expected string","messagePattern":"invalid type for 'bbo_side_type': (.+?), expected string","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/common/parse.rs","lineNumber":1933,"sourceCode":"        })?;\n        result.position_idx = Some(match idx {\n            0 => BybitPositionIdx::OneWay,\n            1 => BybitPositionIdx::BuyHedge,\n            2 => BybitPositionIdx::SellHedge,\n            _ => anyhow::bail!(\"invalid 'position_idx': {idx}, expected 0, 1, or 2\"),\n        });\n    }\n\n    let has_bbo_side_type = params.get(\"bbo_side_type\").is_some();\n    let has_bbo_level = params.get(\"bbo_level\").is_some();\n\n    if has_bbo_side_type != has_bbo_level {\n        anyhow::bail!(\"'bbo_side_type' and 'bbo_level' must be provided together\");\n    }\n\n    if let Some(value) = params.get(\"bbo_side_type\") {\n        let side_type = value.as_str().ok_or_else(|| {\n            anyhow::anyhow!(\"invalid type for 'bbo_side_type': {value}, expected string\")\n        })?;\n        result.bbo_side_type = Some(parse_bbo_side_type(side_type)?);\n    }\n\n    if let Some(value) = params.get(\"bbo_level\") {\n        let level = if let Some(s) = value.as_str() {\n            s.to_string()\n        } else if let Some(i) = value.as_i64() {\n            i.to_string()\n        } else if let Some(u) = value.as_u64() {\n            u.to_string()\n        } else {\n            anyhow::bail!(\"invalid type for 'bbo_level': {value}, expected string or integer\");\n        };\n        result.bbo_level = Some(parse_bbo_level(level)?);\n    }\n\n    Ok(result)","sourceCodeStart":1915,"sourceCodeEnd":1951,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/common/parse.rs#L1915-L1951","documentation":"parse_bybit_tp_sl_params requires 'bbo_side_type' to be a string because it is subsequently parsed into the BybitBboSideType enum. If the value exists but is not a string, the parser bails early rather than attempting coercions.","triggerScenarios":"Passing params[\"bbo_side_type\"] as a non-string value (number, bool, object) in the Bybit TP/SL params map.","commonSituations":"Programmatic params construction or config deserialization where bbo_side_type lost its string type; also forgetting that bbo_side_type must be paired with bbo_level.","solutions":["Pass bbo_side_type as a string (the expected enum representation)","Coerce the config value with .to_string()/as_str before inserting it","Also ensure bbo_level is supplied together with bbo_side_type, or you hit the pairing error next"],"exampleFix":"// before\nlet params = serde_json::json!({\"bbo_side_type\": 2, \"bbo_level\": 1});\n// after\nlet params = serde_json::json!({\"bbo_side_type\": \"Spot\", \"bbo_level\": 1});","handlingStrategy":"validation","validationCode":"if let Some(v) = params.get(\"bbo_side_type\") {\n    anyhow::ensure!(v.is_string(), \"bbo_side_type must be a string\");\n    anyhow::ensure!(params.contains_key(\"bbo_level\"), \"bbo_level required with bbo_side_type\");\n}","typeGuard":"fn is_valid_bbo_side_type(v: &serde_json::Value) -> bool {\n    v.as_str().is_some()\n}","tryCatchPattern":"match parse_bybit_tp_sl_params(&params) {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"bbo\") => {\n        eprintln!(\"invalid BBO params: {e}\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always pair bbo_side_type with bbo_level","Serialize enum variants with their string representation (serde) before inserting into params","Unit-test params builders with representative payloads"],"tags":["bybit","parsing","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}