nautechsystems/nautilus_trader · error
No persisted order events found for
Error message
No persisted order events found for {client_order_id} What it means
Thrown by `index_order_clients` when the INSERT into the order-client index affects zero rows, meaning no persisted order events exist for the given client_order_id. The index can only be written for orders already persisted; otherwise it bails.
Solutions
- Persist the order's events before calling `index_order_clients` — verify the order row exists with a SELECT on client_order_id.
- Check the client_order_id for correctness (truncation, venue-prefixed vs client-prefixed formats).
- Confirm you are connected to the database the order was written to.
Example fix
// before: indexing first queries.index_order_clients(&pool, &client_order_id, &client_id).await?; queries.add_order(&pool, &order).await?; // after: persist order events first queries.add_order(&pool, &order).await?; queries.index_order_clients(&pool, &client_order_id, &client_id).await?;
Defensive patterns
Strategy: validation
Validate before calling
let order_exists = sqlx::query_scalar::<_, bool>(
"SELECT EXISTS(SELECT 1 FROM orders WHERE client_order_id = $1)",
)
.bind(client_order_id.to_string())
.fetch_one(&pool).await?;
if !order_exists {
// persist order events before indexing
} Try / catch
if let Err(e) = queries.index_order_clients(&pool, &client_order_id, &client_id).await {
if e.to_string().contains("No persisted order events") {
// persist the order first, then retry the index call
} else { return Err(e); }
} Prevention
- Always persist order events before indexing the order-client mapping.
- Validate client_order_id formats (never truncate or mix venue/client prefixes).
- Confirm the target database actually contains the order before indexing.
When it happens
Trigger: Calling `index_order_clients` with a client_order_id that was never persisted to the order events tables (e.g. indexing before the order is written, or the order_id is wrong/typos in venue vs client order id).
Common situations: Calling the indexing step out of order (before persisting order events); using a stale client_order_id after order modification; pointing at a database that does not contain the order (different environment).
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Account event does not exist for account
- Account not found after cache update
- Active verified-action intent was not found
- Cannot persist account with no events
- Cannot persist bar with composite bar type
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/50acd0dbd6259689.
Report an issue: GitHub.
Appendix: source
Thrown at crates/infrastructure/src/sql/queries.rs:1497
.await
.map_err(|e| anyhow::anyhow!("Failed to persist execution client {client_id}: {e}"))?;
let result = sqlx::query(
r#"
UPDATE "order_event"
SET client_id = $2
WHERE client_order_id = $1
AND (client_id IS NULL OR client_id = $2)
"#,
)
.bind(client_order_id.to_string())
.bind(client_id.to_string())
.execute(&mut *transaction)
.await
.map_err(|e| anyhow::anyhow!("Failed to index order client origin: {e}"))?;
if result.rows_affected() == 0 {
anyhow::bail!("No persisted order events found for {client_order_id}");
}
}
transaction
.commit()
.await
.map_err(|e| anyhow::anyhow!("Failed to commit order client origins: {e}"))
}
/// Inserts or updates an order ID to position ID index entry via the provided `pool`.
///
/// # Errors
///
/// Returns an error if the SQL INSERT or UPDATE operation fails.
pub async fn index_order_position(
pool: &PgPool,
client_order_id: ClientOrderId,
position_id: PositionId,View on GitHub (pinned to 18893faf8b)