nautechsystems/nautilus_trader · error · anyhow::Error

filter contains a non-string value

Error message

filter {key:?} contains a non-string value

What it means

filter_values extracts string values from an exchange filter JSON object. When the value is an array, every element must be a JSON string; this error means at least one array element was a non-string type (number, bool, object, null), which the parser cannot turn into a filter value.

Solutions

  1. Fix the filter JSON so all array elements are strings.
  2. Update the adapter if Binance changed the filter schema to a non-string representation.
  3. Log the offending filter object to identify which exchange symbol/filter produced the bad value.
  4. Validate test fixtures against the real exchangeInfo response shape.

Example fix

// before
let filter = json!({"orderTypes": ["LIMIT", 1]});

// after
let filter = json!({"orderTypes": ["LIMIT", "MARKET"]});
Defensive patterns

Strategy: validation

Validate before calling

fn all_strings(v: &serde_json::Value) -> bool {
    v.as_array()
        .map(|a| a.iter().all(|e| e.is_string()))
        .unwrap_or(false)
}

Prevention

When it happens

Trigger: Parsing exchangeInfo filters (e.g. orderTypes-like arrays) where an element is not a string — malformed or unexpected exchange metadata, or custom/synthetic filter JSON fed to the instrument parser.

Common situations: Binance changing or extending the exchangeInfo filter schema; mocked/test filter fixtures with numeric values; proxy or caching layers re-serializing strings as numbers.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/2bbdd127e45c54c4. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/binance/src/common/instruments.rs:100

    }
}

fn filter_values(
    config: &BinanceInstrumentProviderConfig,
    key: &str,
) -> anyhow::Result<Option<AHashSet<String>>> {
    let Some(value) = config.filters.get(key) else {
        return Ok(None);
    };

    let values = match value {
        serde_json::Value::String(value) => vec![value.as_str()],
        serde_json::Value::Array(values) => values
            .iter()
            .map(|value| {
                value
                    .as_str()
                    .ok_or_else(|| anyhow::anyhow!("filter {key:?} contains a non-string value"))
            })
            .collect::<anyhow::Result<Vec<_>>>()?,
        _ => anyhow::bail!("filter {key:?} is not a string or array"),
    };

    Ok(Some(
        values
            .into_iter()
            .map(|value| value.trim().to_ascii_uppercase())
            .collect(),
    ))
}

fn matches_filter(values: &Option<AHashSet<String>>, value: &str) -> bool {
    values.as_ref().is_none_or(|values| contains(values, value))
}

fn contains(values: &AHashSet<String>, value: &str) -> bool {

View on GitHub (pinned to 18893faf8b)