nautechsystems/nautilus_trader · error · anyhow::Error
Binance instrument filter
Error message
Binance instrument filter {name:?} must be a non-empty string or array of strings What it means
Each Binance instrument provider filter value must be either a non-empty string or a non-empty array of non-empty strings. validate_filter_strings() rejects values of any other JSON type (number, bool, object, null) or empty/whitespace-only strings. This ensures filter values serialize into valid REST query parameters.
Solutions
- Provide a non-empty string value for the filter, e.g. symbols="BTCUSDT".
- Provide a non-empty array of non-empty strings, e.g. symbols=["BTCUSDT","ETHUSDT"] with all entries trimmed non-empty.
- Remove the filter entirely if you do not intend to filter.
- Trim and check user-supplied filter values before constructing the config.
Example fix
// before
filters.insert("symbols", json!([]));
// after
filters.insert("symbols", json!(["BTCUSDT", "ETHUSDT"])); Defensive patterns
Strategy: validation
Validate before calling
fn filter_value_ok(v: &serde_json::Value) -> bool {
match v {
serde_json::Value::String(s) => !s.trim().is_empty(),
serde_json::Value::Array(a) => {
!a.is_empty()
&& a.iter().all(|x| x.as_str().is_some_and(|s| !s.trim().is_empty()))
}
_ => false,
}
} Prevention
- Never insert empty strings or empty arrays as filter values; omit the filter instead.
- Normalize/trim values loaded from env vars before building filters.
- Store symbol lists as Vec<String> in your own config and serialize only when non-empty.
When it happens
Trigger: Setting an instrument filter value to an empty string (""), an empty array ([]), a non-string type (number/bool/object), or an array containing empty strings, then calling validate().
Common situations: Environment-variable-driven config where an optional filter resolves to an empty string; deserialized JSON where the filter value was a number; building filters programmatically with an uninitialized empty list.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Binance load_ids value
- invalid Binance load_ids value
- recv_window_ms must be in the inclusive range 1..=60000, was
- unsupported Binance instrument filter
- ws_trading_setup_timeout_ms must be greater than 0, was
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/df1a7898f2bb7e63.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/binance/src/config.rs:138
}
Ok(())
}
}
fn validate_filter_strings(name: &str, value: &serde_json::Value) -> anyhow::Result<()> {
let valid = match value {
serde_json::Value::String(value) => !value.trim().is_empty(),
serde_json::Value::Array(values) => {
!values.is_empty()
&& values
.iter()
.all(|value| value.as_str().is_some_and(|value| !value.trim().is_empty()))
}
_ => false,
};
anyhow::ensure!(
valid,
"Binance instrument filter {name:?} must be a non-empty string or array of strings"
);
Ok(())
}
/// Spot market-data transport mode.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.adapters.binance", eq, from_py_object)
)]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.binance")
)]
pub enum BinanceSpotMarketDataMode {
#[default]View on GitHub (pinned to 18893faf8b)