nautechsystems/nautilus_trader · error · ValueError

height must be positive, was {self.height}

Error message

height must be positive, was {self.height}

What it means

Thrown when the account_currency string in a Betfair data or execution client config cannot be parsed into a NautilusTrader Currency. Currency parsing only accepts ISO 4217 alpha-3 codes (for Betfair typically "GBP" or "EUR"), so unrecognized, mistyped, or whitespace-padded strings fail immediately. The parse runs from BetfairDataClientConfig::currency()/BetfairExecutionClientConfig::currency() and is enforced by validate().

Source

Thrown at python/nautilus_trader/analysis/config.py:233

    height : int, default 1500
        Total height of the tearsheet in pixels.
    show_logo : bool, default True
        Whether to display NautilusTrader logo in the tearsheet.

    """

    charts: list[TearsheetChart] = field(default_factory=_default_charts)
    theme: str = "plotly_white"
    layout: GridLayout | None = None
    title: str = "NautilusTrader Backtest Results"
    include_benchmark: bool = True
    benchmark_name: str = "Benchmark"
    height: int = 1500
    show_logo: bool = True

    def __post_init__(self) -> None:
        if self.height <= 0:
            raise ValueError(f"height must be positive, was {self.height}")

    @property
    def chart_names(self) -> list[str]:
        return [c.name for c in self.charts]

View on GitHub (pinned to a4b06ed870)

Solutions

  1. Set account_currency to an uppercase ISO 4217 alpha-3 code, e.g. "GBP" for UK Betfair accounts
  2. Trim whitespace and uppercase the value before constructing the config
  3. Call config.validate() right after loading config so the failure names the field before the client starts

Example fix

// before
let config = BetfairDataClientConfig::builder()
    .account_currency("Pounds Sterling".to_string())
    .build()?;

// after
let config = BetfairDataClientConfig::builder()
    .account_currency("GBP".to_string())
    .build()?;
config.validate()?;
Defensive patterns

Strategy: validation

Validate before calling

let code = "GBP";
if code.parse::<Currency>().is_err() {
    anyhow::bail!("account_currency '{code}' is not a valid ISO 4217 alpha-3 code");
}
let config = BetfairDataClientConfig::builder().account_currency(code.to_string()).build()?;
config.validate()?;

Type guard

fn is_valid_currency_code(code: &str) -> bool {
    code.parse::<Currency>().is_ok()
}

Prevention

When it happens

Trigger: Building BetfairDataClientConfig or BetfairExecutionClientConfig (or their Python wrappers) with account_currency set to a non-ISO-4217 value such as "POUND", "gbp " with a trailing space, "£", or a 4-letter code; loading a YAML/TOML/JSON config where the currency key is mistyped or interpolated with whitespace; calling config.validate() or starting the client, which parses the field.

Common situations: Hand-written strategy config files using currency names instead of codes; env-var or template interpolation adding whitespace/newlines; porting configs between exchange adapters with different code spellings.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16). Data as JSON: /api/errors/454c80115fbe0312. Report an issue: GitHub.