How deveshc23/market_exchange works
Market Exchange is a multithreaded simulated trading engine. Market-data and bot producers submit orders to the shared queue; the main exchange loop matches them, updates bot portfolio risk, and forwards executions to an asynchronous logger. The README documents price-time priority and SQLite persistence. The sampled source confirms the main-loop dispatch and portfolio calculations; producer internals and logger implementation were not excerpted, so those links rely on README documentation.
Main entry points: main.cpp Exchange loop · ThreadSafeQueue.h Exchange queue · DatabaseLogger.cpp Database logger · MarketDataPublisher.cpp Market publisher
Components 14
Order producers
- Market publisher
src/MarketDataPublisher.cpp - Trading bot
src/TradingBot.cpp
Exchange matching
- Exchange loop
src/main.cpp - Price-time book
src/OrderBook.cpp - Order model
src/Order.cpp - Trade model
src/Trade.cpp
Portfolio risk
- Portfolio manager
src/PortfolioManager.cpp
Trade persistence
- Database logger
src/DatabaseLogger.cpp - SQLite engine
lib/sqlite3.c - Trade ledger
exchange.db
Shared runtime
- Exchange queue
include/ThreadSafeQueue.h - Database queue
include/ThreadSafeQueue.h
Other components
- Market activity
- Bot strategy
Connections 13
- Market activity → Market publisher: simulates activity
README.md - Market publisher → Exchange queue: publishes orders
README.md - Bot strategy → Trading bot: generates orders
README.md - Trading bot → Exchange queue: publishes orders
README.md - Exchange loop → Exchange queue: pops orders
src/main.cpp - Exchange loop → Price-time book: submits order
src/main.cpp - Price-time book → Trade model: creates executions
README.md - Exchange loop → Database queue: queues executions
src/main.cpp - Exchange loop → Portfolio manager: updates risk
src/main.cpp - Portfolio manager → Trade model: reads execution
src/PortfolioManager.cpp - Database logger → Database queue: consumes executions
README.md - Database logger → SQLite engine: writes trades
README.md - SQLite engine → Trade ledger: persists ledger
README.md