Multi-process trading simulation that mirrors a miniature trading desk:
[ Gateway ] -> [ OrderBook ] -> (Shared Memory) -> [ Strategy ] -> [ OrderManager ]
^ |
|-------- news sentiment -------|
- Gateway streams random-walk prices plus random news sentiment over TCP sockets.
- OrderBook consumes prices and writes them into a NumPy-backed shared memory segment protected by a lock.
- Strategy reads shared memory, ingests news, runs a moving-average crossover + sentiment filter, and sends orders only when both agree.
- OrderManager is a TCP server that logs deserialized orders in real time.
main.pyorchestrates all processes with the Windows-safespawncontext.
python -m venv .venv
.venv\Scripts\activate # Windows
pip install -r requirements.txtpython main.pyStop with Ctrl+C. Each process logs to the console; keep the window wide enough to see the interleaved output.
python gateway.py
python orderbook.py
python strategy.py
python order_manager.pyThese commands are useful when recording the demo video because you can place each in its own terminal.
pytestTests cover shared-memory propagation and strategy signal logic.
All tunables (ports, symbols, thresholds, rolling-window sizes, etc.) live in config.py. Update that file to add symbols or tweak behaviour. Ensure you delete the shared memory segment (or let OrderBook recreate it) when changing symbol counts.
See performance_report.md for the latest numbers plus methodology. In short:
- Use
scripts/snippets (ornc) to connect to each socket and measure throughput. - Capture strategy logs filtered on
Sent orderto derive latency between a price tick and an order decision. - Shared memory footprint is deterministic:
len(SYMBOLS) * 8 bytes.