Execution Engine¶
The execution engine manages order lifecycle from risk-approved intent to exchange fill.
Order Flow¶
sequenceDiagram
participant C as Coordinator
participant R as Risk Engine
participant O as OMS
participant E as Exchange Provider
participant F as Fill Tracker
C->>R: validate(order)
R-->>C: Order (APPROVED + HMAC)
C->>O: submit(order)
O->>O: Verify HMAC token
O->>O: Check token TTL (5 min)
O->>O: Transition APPROVED → SUBMITTED
O->>E: execute(order)
alt Paper Mode
E->>E: simulate_paper_fill(order, price)
else Shadow Mode
E->>E: fetch real price, simulate fill
else Live Mode
E->>E: submit to exchange
end
E-->>F: ExecutionResult
F->>F: Record fill
F-->>O: Update order status
Order Management System (OMS)¶
The OMS is the final gate before order submission. It performs:
- Token presence check — Order must have
risk_approval_token - HMAC verification — Token signature must match using
AIS_RISK_HMAC_SECRET - TTL check — Token must not be older than 5 minutes
- Status transition —
APPROVEDtoSUBMITTED
Orders without valid tokens are rejected.
Execution Modes¶
| Mode | Exchange Connection | Order Submission | Use Case |
|---|---|---|---|
paper |
None | Simulated fills | Development, strategy testing |
shadow |
Read-only | Simulated against real prices | Pre-live validation |
live |
Full access | Real orders | Production |
All modes share the same execution pipeline. The difference is only at the exchange provider level.
Order Status Lifecycle¶
stateDiagram-v2
[*] --> PENDING: Created by allocator
PENDING --> APPROVED: Risk engine signs
PENDING --> REJECTED: Risk engine vetoes
APPROVED --> SUBMITTED: OMS accepts
SUBMITTED --> FILLED: Exchange confirms
SUBMITTED --> CANCELLED: Cancel request
REJECTED --> [*]
FILLED --> [*]
CANCELLED --> [*]
Safety Gates¶
- Risk token — HMAC-SHA256 signed, 5-minute TTL, constant-time comparison
- Live mode env var —
AIS_ENABLE_LIVE_TRADING=truemust be explicitly set - Account ID —
ASTER_ACCOUNT_IDrequired for live mode - Leverage enforcement — Must call
set_leveragebefore first order - Margin mode — Must call
set_margin_mode(ISOLATED recommended)
Exchange Provider¶
Orders are executed through the ExchangeProvider abstraction:
prepare_futures_order(order)— Futures order parametersprepare_spot_order(order)— Spot order parametersprepare_cancel_order(symbol, order_id)— Single cancelprepare_cancel_all(symbol)— Cancel all for a symbolprepare_emergency_cancel_all(symbols)— Kill switch cancelsimulate_paper_fill(order, price)— Simulated fill for paper mode
See Exchange Layer for multi-exchange details.