Skip to content

Execution Engine & System Wiring Plan (Phase 4)

Goal

Implement the ExecutionActor to drive the Saga and wire the full system in main.rs.

Components

1. Exchange Clients (src/market/client.rs)

We need a unified trait for execution commands, distinct from Monitors (data).

#[async_trait]
pub trait ExchangeClient: Send + Sync {
    async fn place_order(&self, order: OrderRequest) -> Result<FillDetails, ExecutionError>;
    // async fn cancel_order...
}

Implementations: - PolymarketClient (Mock/Real HTTP) - KalshiClient (Mock/Real HTTP)

2. Execution Actor (src/actors/executor.rs)

  • State:
  • sagas: Map
  • poly_client: Arc
  • kalshi_client: Arc
  • Behavior:
  • On StartSaga(Opportunity):
    1. Initialize new Saga.
    2. Execute Leg 1 (Polymarket) via Client.
    3. On Result -> Update State -> Execute Leg 2 (Kalshi).
    4. Handle Compensation if needed.

3. Wiring (src/main.rs)

  • Initialize PolymarketMonitor, KalshiMonitor.
  • Initialize ArbiterActor (with Mappings).
  • Initialize ExecutionActor (with Clients).
  • Wire Channels:
  • Monitor -> Arbiter (MarketUpdate)
  • Arbiter -> Executor (Opportunity)

Verification

  • Safety: Verify ExecutionActor atomic state updates.
  • Mocking: Test full flow with Mock Clients.