nautechsystems/nautilus_trader · error · anyhow::Error

No currency_code in account details

Error message

No currency_code in account details

What it means

get_account_currency received a successful AccountDetailsResponse whose currency_code field was None. Betfair did not report the account's currency, so the method cannot return a Currency and raises an explicit error.

Solutions

  1. Configure the currency explicitly in the adapter/factory config instead of auto-detecting from the account.
  2. Log in to the Betfair site and complete account setup so the API returns a currency_code.
  3. Verify with a raw getAccountDetails call that Betfair really omits currency_code for this account.
  4. Fall back to a default currency constant if the deployment permits.

Example fix

// before
let currency = client.get_account_currency().await?;
// after
let currency = match client.get_account_currency().await {
    Ok(c) => c,
    Err(e) => {
        log::warn!("currency auto-detect failed ({e}); using configured default");
        Currency::GBP()
    }
};
Defensive patterns

Strategy: fallback

Validate before calling

// prefer an explicitly configured currency when available
let currency: Option<Currency> = cfg.currency.clone();

Try / catch

let currency = match client.get_account_currency().await {
    Ok(c) => c,
    Err(e) if e.to_string().contains("No currency_code") => {
        log::warn!("account currency missing; using configured default");
        cfg.default_currency.clone().ok_or(e)?
    }
    Err(e) => return Err(e.into()),
};

Prevention

When it happens

Trigger: Calling get_account_currency when Betfair's getAccountDetails returns without a currency_code, typically for accounts with undetermined currency, certain demo/promotional accounts, or unusual account types.

Common situations: New Betfair accounts before first deposit; accounts in jurisdictions where currency is hidden; API responses during account migration; test/integration accounts.

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


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

Appendix: source

Thrown at crates/adapters/betfair/src/provider.rs:405

    pub fn min_notional(&self) -> Option<Money> {
        self.min_notional
    }

    /// Fetches the account currency from the Betfair Account API.
    ///
    /// # Errors
    ///
    /// Returns an error if the API call fails or the currency code is missing/unknown.
    pub async fn get_account_currency(&self) -> anyhow::Result<Currency> {
        let details: AccountDetailsResponse = self
            .http_client
            .send_accounts(METHOD_GET_ACCOUNT_DETAILS, &serde_json::json!({}))
            .await
            .map_err(|e| anyhow::anyhow!("{e}"))?;

        let code = details
            .currency_code
            .ok_or_else(|| anyhow::anyhow!("No currency_code in account details"))?;
        Ok(code.parse::<Currency>()?)
    }

    /// Builds an effective filter by merging runtime overrides with the base filter.
    fn build_effective_filter(
        &self,
        overrides: Option<&HashMap<String, String>>,
    ) -> NavigationFilter {
        let Some(overrides) = overrides else {
            return self.nav_filter.clone();
        };

        let parse_csv = |key: &str| -> Option<Vec<String>> {
            overrides
                .get(key)
                .map(|v| v.split(',').map(|s| s.trim().to_string()).collect())
        };

View on GitHub (pinned to 18893faf8b)