nautechsystems/nautilus_trader · error
invalid type for 'order_iv': {value}, expected string or num
Error message
invalid type for 'order_iv': {value}, expected string or number What it means
'order_iv' (implied volatility for Bybit options orders) must be convertible to a price string. The parser tries get_price_str which accepts strings or numbers; any other JSON value type causes this bail, embedding the offending value in the message.
Source
Thrown at crates/adapters/bybit/src/common/parse.rs:1893
if result.sl_order_type == Some(BybitOrderType::Limit) && result.sl_limit_price.is_none() {
anyhow::bail!("'sl_order_type' is 'Limit' but 'sl_limit_price' was not provided");
}
if result.tp_limit_price.is_some() && result.tp_order_type != Some(BybitOrderType::Limit) {
anyhow::bail!("'tp_limit_price' requires 'tp_order_type' to be 'Limit'");
}
if result.sl_limit_price.is_some() && result.sl_order_type != Some(BybitOrderType::Limit) {
anyhow::bail!("'sl_limit_price' requires 'sl_order_type' to be 'Limit'");
}
result.close_on_trigger = params.get_bool("close_on_trigger");
if let Some(value) = params.get("order_iv") {
match get_price_str(params, "order_iv") {
Some(s) => result.order_iv = Some(s),
None => {
anyhow::bail!("invalid type for 'order_iv': {value}, expected string or number")
}
}
}
if let Some(value) = params.get("mmp") {
match value.as_bool() {
Some(b) => result.mmp = Some(b),
None => anyhow::bail!("invalid type for 'mmp': {value}, expected bool"),
}
}
if let Some(value) = params.get("smp_type") {
let smp_type = value.as_str().ok_or_else(|| {
anyhow::anyhow!("invalid type for 'smp_type': {value}, expected string")
})?;
result.smp_type = Some(parse_smp_type(smp_type)?);
}
View on GitHub (pinned to 18893faf8b)
Solutions
- Pass 'order_iv' as a string (e.g. "0.42") or a JSON number
- Sanitize the source value before inserting it into params
Example fix
// before
params.set("order_iv", true);
// after
params.set("order_iv", "0.42"); Defensive patterns
Strategy: type-guard
Validate before calling
fn validate_order_iv(params: &Params) -> Result<(), String> {
if let Some(v) = params.get("order_iv") {
if !matches!(v, Value::String(_) | Value::Number(_)) {
return Err(format!("order_iv must be string or number, got {v}"));
}
}
Ok(())
} Type guard
fn is_iv_like(v: &Value) -> bool {
matches!(v, Value::String(_) | Value::Number(_))
} Try / catch
match parse_bybit_tp_sl_params(¶ms) {
Ok(p) => submit(p),
Err(e) if e.to_string().contains("invalid type for 'order_iv'") => {
log::warn("order_iv must be a string or number");
}
Err(e) => return Err(e),
} Prevention
- Serialize order_iv as string or number, never bool/null/nested
- Coerce untyped config values to string before inserting into params
- Restrict the options-order config schema for order_iv types
When it happens
Trigger: Passing 'order_iv' as a bool, null, array, or object in the params map.
Common situations: Programmatically built params where order_iv came from a loosely typed config or an untyped JSON blob (e.g. 0.42 parsed as bool-like or nested value).
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- invalid type for 'mmp': {value}, expected bool
- invalid type for 'bbo_level': {value}, expected string or in
- SL override fields require 'stop_loss' to be set
- 'tp_order_type' is 'Limit' but 'tp_limit_price' was not prov
- 'sl_order_type' is 'Limit' but 'sl_limit_price' was not prov
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/20d41809ec5168d6.
Report an issue: GitHub.