{"record":{"id":"efc6dbb518372419","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-trades-e","errorCode":null,"errorMessage":"Failed to load trades: {e}","messagePattern":"Failed to load trades: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1282,"sourceCode":"    }\n\n    /// Loads all `TradeTick` entries for `instrument_id` via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the SQL SELECT or deserialization fails.\n    pub async fn load_trades(\n        pool: &PgPool,\n        instrument_id: &InstrumentId,\n    ) -> anyhow::Result<Vec<TradeTick>> {\n        sqlx::query_as::<_, TradeTickRow>(\n            r#\"SELECT * FROM \"trade\" WHERE instrument_id = $1 ORDER BY ts_event ASC\"#,\n        )\n        .bind(instrument_id.to_string())\n        .fetch_all(pool)\n        .await\n        .map(|rows| rows.into_iter().map(|row| row.0).collect())\n        .map_err(|e| anyhow::anyhow!(\"Failed to load trades: {e}\"))\n    }\n\n    /// Inserts a `QuoteTick` entry via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the SQL INSERT operation fails.\n    pub async fn add_quote(pool: &PgPool, quote: &QuoteTick) -> anyhow::Result<()> {\n        sqlx::query(r#\"\n            INSERT INTO \"quote\" (\n                instrument_id, bid_price, ask_price, bid_size, ask_size, ts_event, ts_init, created_at, updated_at\n            ) VALUES (\n                $1, $2, $3, $4, $5, $6, $7, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP\n            )\n            ON CONFLICT (id)\n            DO UPDATE\n            SET\n                instrument_id = $1, bid_price = $2, ask_price = $3, bid_size = $4, ask_size = $5,","sourceCodeStart":1264,"sourceCodeEnd":1300,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1264-L1300","documentation":"This error wraps sqlx failures from `SELECT * FROM \"trade\" WHERE instrument_id = $1 ORDER BY ts_event ASC` in `load_trades`. It signals the trade rows could not be fetched from PostgreSQL; the raw sqlx error is embedded in the message.","triggerScenarios":"Calling `load_trades(pool, instrument_id)` with the DB unreachable, `trade` table missing, query timeout, or pool exhausted.","commonSituations":"New environment without migrations; network or auth failures; statement timeouts on large trade tables; connection pool contention.","solutions":["Apply migrations so the `trade` table exists","Verify connectivity and pool config (DSN, timeout, pool size)","Read the inner sqlx error for the precise cause and fix it","Retry transient errors with backoff; consider indexing instrument_id/ts_event for large datasets"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"sqlx::query(\"SELECT 1 FROM trade LIMIT 1\").fetch_optional(pool).await?;","typeGuard":null,"tryCatchPattern":"let trades = match load_trades(&pool, &instrument_id).await {\n    Ok(t) => t,\n    Err(e) => { tracing::error!(\"load_trades: {e:#}\"); return Err(e); }\n};","preventionTips":["Run migrations at deployment","Index (instrument_id, ts_event) for large tables","Retry transient errors with backoff"],"tags":["database","sql","postgres"],"backgroundTag":"database-query-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}