{"record":{"id":"c86b7e6652341b71","repo":"nautechsystems/nautilus_trader","slug":"invalid-type-for-smp-type-value-expected-str","errorCode":null,"errorMessage":"invalid type for 'smp_type': {value}, expected string","messagePattern":"invalid type for 'smp_type': (.+?), expected string","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/common/parse.rs","lineNumber":1907,"sourceCode":"    if let Some(value) = params.get(\"order_iv\") {\n        match get_price_str(params, \"order_iv\") {\n            Some(s) => result.order_iv = Some(s),\n            None => {\n                anyhow::bail!(\"invalid type for 'order_iv': {value}, expected string or number\")\n            }\n        }\n    }\n\n    if let Some(value) = params.get(\"mmp\") {\n        match value.as_bool() {\n            Some(b) => result.mmp = Some(b),\n            None => anyhow::bail!(\"invalid type for 'mmp': {value}, expected bool\"),\n        }\n    }\n\n    if let Some(value) = params.get(\"smp_type\") {\n        let smp_type = value.as_str().ok_or_else(|| {\n            anyhow::anyhow!(\"invalid type for 'smp_type': {value}, expected string\")\n        })?;\n        result.smp_type = Some(parse_smp_type(smp_type)?);\n    }\n\n    if let Some(value) = params.get(\"position_idx\") {\n        let idx = value.as_i64().ok_or_else(|| {\n            anyhow::anyhow!(\"invalid type for 'position_idx': {value}, expected integer\")\n        })?;\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();","sourceCodeStart":1889,"sourceCodeEnd":1925,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/common/parse.rs#L1889-L1925","documentation":"parse_bybit_tp_sl_params validates optional 'smp_type' entries in a TP/SL params map. The key was present, but the JSON/serde value is not a string, so the parser refuses to interpret it and bails instead of guessing a coercion. The message interpolates the offending value so the caller can see what was passed.","triggerScenarios":"Passing params[\"smp_type\"] as a non-string JSON value, e.g. an integer 1, a bool, or a nested object, into the Bybit TP/SL params builder.","commonSituations":"Building the params map from untyped config files, environment variables, or deserialized JSON where the value was not normalized to a string like \"None\" before calling the parser.","solutions":["Pass smp_type as a string (e.g. \"None\", \"Cancel\") in the params map","Coerce numeric/bool config values to strings before calling parse_bybit_tp_sl_params","Fix the config source (YAML/JSON/env) so smp_type is quoted"],"exampleFix":"// before\nlet params = serde_json::json!({\"smp_type\": 1});\n// after\nlet params = serde_json::json!({\"smp_type\": \"None\"});","handlingStrategy":"validation","validationCode":"fn ensure_string_param(params: &serde_json::Value, key: &str) -> anyhow::Result<&str> {\n    params.get(key)\n        .and_then(|v| v.as_str())\n        .ok_or_else(|| anyhow::anyhow!(\"{key} must be a string\"))\n}","typeGuard":"fn as_str_param(v: &serde_json::Value) -> Option<&str> {\n    if v.is_string() { v.as_str() } else { None }\n}","tryCatchPattern":"match parse_bybit_tp_sl_params(&params) {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"smp_type\") => {\n        eprintln!(\"smp_type must be a string: {e}\");\n        Default::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Quote string config values in YAML/JSON","Build params maps with typed builders instead of raw JSON","Add a schema check over params keys before parsing"],"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-14T05:17:10.506Z"}