Skip to content

Market Simulator Service

The Market Simulator Service generates synthetic trading activity — order placements, cancellations, and fills — that flows through the standard Kafka pipeline. Downstream services (Market Data, Position, Order) consume these events identically to real trading activity, making it suitable for integration testing, load testing, and running demo environments without real capital.

  • Synthetic Order Generation: Emit order.command.v1 events representing simulated order placements and cancellations at configurable rates and price ranges.
  • Price Walk: Simulate a realistic mid-price random walk within configurable bounds to produce meaningful OHLCV and order book data.
  • Volume Control: Configure order size, arrival rate, and spread to match the desired market depth and activity level.
  • Isolation: Operates purely through Kafka — no direct access to databases, wallets, or the matching engine’s internal state.
graph TB Sim[Market Simulator] -->|order.command.v1| Kafka[Kafka] Kafka --> ME[Matching Engine] ME -->|engine.event.v1| Kafka Kafka --> MD[Market Data Service] Kafka --> OrderSvc[Order Service] Kafka --> PosSvc[Position Service]

Because the simulator emits standard Kafka events, the entire downstream pipeline — matching, market data aggregation, position tracking, and WebSocket broadcasting — behaves exactly as it would with real orders.

Go

TopicDescription
order.command.v1Simulated order placement and cancellation commands
TopicDescription
engine.event.v1Fill events used to track simulated inventory and adjust quoting
md.mark.v1Mark price feed used as the mid-price reference for generated quotes
VariableDescriptionDefault
KAFKA_BROKERSKafka broker addressesRequired
SCHEMA_REGISTRY_URLConfluent Schema Registry URLRequired
SIM_SYMBOLInstrument symbol to simulate (e.g. BTCUSDT-PERP)Required
SIM_ACCOUNT_IDSystem account ID used for simulated ordersRequired
SIM_ORDER_RATE_MSInterval between order submissions in milliseconds500
SIM_SPREAD_BPSSimulated bid-ask spread in basis points20
SIM_ORDER_SIZE_USDTNotional size per simulated order in USDT100
SIM_MAX_DEPTHNumber of price levels to maintain on each side10
SIM_PRICE_WALK_BPSMaximum per-tick mid-price move in basis points5
SIM_BASE_PRICEStarting mid-price (used when no mark price is available)50000

Run the simulator against a local stack to produce real Kafka traffic without manual order placement. All services respond to the synthetic events identically to production, exercising the full order → match → settle → position update path.

Increase SIM_ORDER_RATE_MS (lower value = higher rate) and SIM_MAX_DEPTH to stress-test the matching engine throughput, Kafka consumer lag tolerance, and WebSocket broadcast latency under load.

Deploy the simulator alongside a demo instance to show a live-looking order book, trade feed, and candlestick charts without requiring real users or capital.

  • ❌ Does NOT interact with real user wallets or balances
  • ❌ Does NOT bypass Order Service or Matching Engine
  • ❌ Does NOT read from or write to any service database directly
  • ✅ All simulated orders are tagged with a designated system account ID so they are identifiable in audit logs
  • ✅ Stops emitting orders immediately on shutdown (no lingering open orders in the book after restart unless the matching engine already accepted them)