nautechsystems/nautilus_trader · error
Order {primary_id} already being executed
Error message
Order {primary_id} already being executed What it means
TwapAlgorithm::on_order rejects an order whose client_order_id is already present in scheduled_orders, since each primary order can be scheduled for TWAP execution only once. A duplicate on_order call for the same order would double-count executions.
Source
Thrown at crates/trading/src/algorithm/twap.rs:120
fn on_stop(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_stop(self)
}
fn on_resume(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_resume(self)
}
fn on_reset(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_reset(self)
}
}
nautilus_execution_algorithm!(TwapAlgorithm, {
fn on_order(&mut self, order: OrderAny) -> anyhow::Result<()> {
let primary_id = order.client_order_id();
if self.scheduled_orders.contains_key(&primary_id) {
anyhow::bail!("Order {primary_id} already being executed");
}
log::info!("Received order for TWAP execution: {order:?}");
// Only market orders supported
if order.order_type() != OrderType::Market {
let reason = OrderDeniedReason::UnsupportedOrderType {
order_type: order.order_type(),
}
.to_string();
return self.deny_order(&order, Ustr::from(&reason));
}
let instrument = {
let cache = ExecutionAlgorithmNative::exec_algorithm_core(self).cache_ref();
cache.instrument(&order.instrument_id()).cloned()
};
View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure the order is only routed to the exec algorithm once; check algorithm state before resubmitting
- Generate a unique client_order_id per submission instead of reusing IDs
- Deduplicate order events on replay/reconnect before invoking on_order
- Check twap.scheduled_orders.contains_key(&client_order_id) before submitting
Example fix
// before
exec_algorithm.submit(order);
// after
if !exec_algorithm.is_scheduled(&order.client_order_id()) {
exec_algorithm.submit(order);
} Defensive patterns
Strategy: validation
Validate before calling
if exec_algorithm.scheduled_orders().contains_key(&order.client_order_id()) { return; } Prevention
- Submit each order to the exec algorithm exactly once
- Deduplicate replayed/reconnected order events
- Always generate fresh client_order_ids per submission
When it happens
Trigger: Submitting the same order to the TWAP algorithm twice, re-processing an order event (e.g. after a reconnect/replay), or reusing a client_order_id for a new submission routed to the same algorithm.
Common situations: Event replay after a crash/restart without deduplication; strategy retry logic re-emitting the order; client_order_id reuse across sessions.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Correlation ID <{correlation_id}> already has a registered h
- OrderList denied: duplicate {}
- Order in list denied: duplicate {}
- Invalid config type for AxExecutionClientFactory. Expected A
- Instrument not found in cache: {symbol}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9127efe4d50c44b8.
Report an issue: GitHub.