nautechsystems/nautilus_trader · error · anyhow::Error
Failed to fetch accounts: {e}
Error message
Failed to fetch accounts: {e} What it means
Raised by request_account_state when fetch_all_accounts() fails while building an AccountState from Coinbase /accounts. It aggregates paginated account fetching; any HTTP or pagination error aborts the account state request.
Source
Thrown at crates/adapters/coinbase/src/http/client.rs:1124
///
/// Builds a cash-type [`AccountState`] from `/accounts` with one balance
/// per currency. Follows Coinbase's cursor pagination so multi-wallet
/// accounts are reported in full. `reported` is set to `true` since the
/// values come from the venue.
///
/// # Errors
///
/// Returns an error when the HTTP request fails or the response cannot
/// be parsed.
pub async fn request_account_state(
&self,
account_id: AccountId,
) -> anyhow::Result<AccountState> {
let accounts = self
.inner
.fetch_all_accounts()
.await
.map_err(|e| anyhow::anyhow!("Failed to fetch accounts: {e}"))?;
let ts_event = self.ts_now();
parse_account_state(&accounts, account_id, true, ts_event, ts_event)
}
/// Requests a single order status report by venue or client order ID.
///
/// Resolves venue order IDs first via `/orders/historical/{id}`. When only a
/// `client_order_id` is provided, paginates the order history filtered to
/// that client ID.
///
/// # Errors
///
/// Returns an error when the HTTP request fails, the order cannot be found,
/// or the response cannot be parsed.
pub async fn request_order_status_report(
&self,
account_id: AccountId,
client_order_id: Option<ClientOrderId>,View on GitHub (pinned to 18893faf8b)
Solutions
- Verify API key/secret are valid and have the 'view' (accounts) scope.
- Check the wrapped {e}: retry 5xx/429 with backoff; fix auth for 401/403.
- Ensure system clock is NTP-synced so request signatures validate.
- Test the key with a direct curl to /api/v3/brokerage/accounts.
Example fix
// before let state = client.request_account_state(account_id).await?; // after (pre-check credentials) anyhow::ensure!(config.api_key.is_some() && config.api_secret.is_some(), "Coinbase credentials missing"); let state = client.request_account_state(account_id).await?;
Defensive patterns
Strategy: validation
Validate before calling
anyhow::ensure!(config.api_key.is_some() && config.api_secret.is_some(), "credentials required for /accounts"); // plus a startup curl to /api/v3/brokerage/accounts to confirm scopes
Try / catch
match client.request_account_state(account_id).await {
Ok(s) => s,
Err(e) if e.to_string().contains("401") => bail!("invalid/expired Coinbase credentials"),
Err(e) => { retry_with_backoff(|| client.request_account_state(account_id)).await? }
} Prevention
- Provision API keys with account-view scope and test them before trading.
- Keep server clocks NTP-synced for request signing.
- Rotate secrets through config/env without restarting mid-request.
When it happens
Trigger: Calling request_account_state(account_id) where the authenticated GET /accounts call fails: invalid or expired API key, missing required scopes, network error, or 4xx/5xx responses during pagination.
Common situations: API keys without the required accounts scope, rotated/expired Coinbase API secrets, clock skew breaking request signing, or connectivity problems on a trading server.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- failed to request AX whoami: {e}
- {e}
- Coinbase credentials not available; set COINBASE_API_KEY and
- Failed to create Coinbase HTTP client: {e}
- Failed to fetch products: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/1d8a96d7cf43353c.
Report an issue: GitHub.