Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Event Bus

The EventBus is the central nervous system of Mercury. It is a thin wrapper around a crossbeam bounded channel.

Design

  • Capacity: 100,000 events (configurable at construction).
  • Back-pressure: producers block when the channel is full, providing natural flow control.
  • Lock-free: no mutex on the hot path — crossbeam’s channel uses atomic operations internally.
  • Single channel: all event types share one channel. Components filter by EventPayload variant.

Event types (EventPayload)

VariantPublished byConsumed by
BookUpdate(Arc<BookUpdate>)FeedManagerStrategyRunner, PaperGateway
Trade(Trade)FeedManagerStrategyRunner
Signal(Signal)StrategyRunnerOrderManager
Fill(Fill)OrderManagerStorageManager, StrategyRunner, IpcServer
OrderUpdate(Order)OrderManagerIpcServer

Arc wrapping

BookUpdate is wrapped in Arc before publishing so that multiple subscribers can hold a reference to the same allocation without copying the order-book snapshot.

Usage

#![allow(unused)]
fn main() {
// Publish
bus.publish(EventPayload::Signal(signal));

// Subscribe (returns a Receiver)
let rx = bus.subscribe();
while let Ok(event) = rx.recv() {
    match event.payload {
        EventPayload::Fill(fill) => { /* handle */ }
        _ => {}
    }
}
}