A Rust-based market data collection and processing system for exploring cryptocurrency market making concepts. Connects to Binance WebSocket streams to collect real-time market data, process order books, track trades, and calculate market metrics.
This project serves as an educational tool to understand market making principles, order book dynamics, and real-time market data processing. It streams live data from Binance, maintains local order book state, and stores metrics in a time-series database for analysis.
Note: This is a demonstration project intended for learning purposes only. It is not optimized for actual trading or production use.
- Multi-stream market data collection from Binance WebSocket API
- Differential order book depth updates
- Individual and rolling window ticker data
- Aggregate trade streams
- Real-time order book reconstruction with configurable snapshot limits
- Trade aggregation and analysis with windowed volatility calculations
- Message queue integration (Apache Iggy) for event streaming
- Time-series persistence (TimescaleDB) for historical analysis
- Monitoring dashboards (Grafana) with pre-configured visualizations
- Multi-symbol support with configurable stream parameters per trading pair
The system is organized as a Cargo workspace with layered architecture:
domain- Core business logic and models (order books, trades, market data)infrastructure- External integrations (Binance, Iggy, TimescaleDB)application- Orchestration and stream processing handlerssupport- Cross-cutting utilities (shutdown coordination, logging)market-data-engine- Main binary that wires everything together
Data flows from Binance WebSocket streams → handlers → message queue (Iggy) + database (TimescaleDB) + in-memory processors for derived metrics.
- Rust (edition 2024) - Install from rustup.rs
- Docker & Docker Compose - For running infrastructure services
- Just - Task runner (
cargo install just)
- Clone the repository:
git clone https://github.com/SamBroomy/market-making.git
cd market-making- Copy the environment file and configure as needed:
cp .env.example .env- Start infrastructure services (TimescaleDB, Iggy, Grafana):
just infra-upOption 1: Full Docker deployment (recommended for testing the complete system)
just startThis starts all services including the market data engine in Docker.
Option 2: Local development (infrastructure in Docker, engine runs locally)
# Start infrastructure only
just infra-up
# Run the market data engine locally with development config
just producer-localOnce running, access the web interfaces:
- Iggy Web UI: http://localhost:3050 (message queue monitoring)
- Grafana: http://localhost:3000 (username:
admin, password:admin)- Pre-configured with TimescaleDB datasource and market data dashboards
Trading pairs and stream settings are configured in TOML files under configuration/:
base.toml- Base configuration with trading pairsdevelopment.toml- Development overrides (debug logging)production.toml- Production settings
Control which config is loaded via the MARKET_ENVIRONMENT environment variable:
MARKET_ENVIRONMENT=development just producer-localTo add new trading pairs, edit configuration/base.toml and add a [trading.market.SYMBOL] section.
# View all available commands
just
# Format code
just fmt
# Run lints
just check
# Run tests
just test
# View logs
just producer-logs
just all-logs
# Stop all services
just stopSee the justfile for all available commands.
crates/
├── domain/ # Core models and business logic
├── infrastructure/ # Binance, Iggy, TimescaleDB implementations
├── application/ # Stream handlers and orchestration
├── support/ # Utilities (shutdown, logging)
└── bin-market-data-engine/ # Main binary
For detailed development guidance, see CLAUDE.md.
Market data is stored in TimescaleDB (PostgreSQL with time-series extensions):
- Order book depth updates
- Individual ticker snapshots
- Rolling window ticker data
- Aggregate trade data
- Trade summaries and volatility metrics
Run database migrations with:
just migrateThe system publishes processed data to Apache Iggy message queue streams:
diff_book_depth- Order book depth updatesorderbook_state- Reconstructed order book snapshotsorderbook_signals- Order book imbalance signalsticker- Individual ticker updatesrolling_window_ticker_*- Windowed ticker dataagg_trade- Aggregate tradesagg_trade_summary_*- Trade summaries with volatility metrics
Grafana dashboards provide real-time visualization of:
- Market data ingestion rates
- Order book depth and spread
- Trade volume and volatility
- System performance metrics
Access Grafana at http://localhost:3000 after running just start.
This project explores concepts from academic research on market making, including:
When the order book is highly imbalanced the order value is lower. The lowest values appear when both of the limit queues are short. When the queue length is short, the probability that the queue will become empty increases before other limit orders arrive behind the MM's orders; when his order is executed on one side of the order book but not on the opposite side, the MM will have to close the position at a loss with a market order.
The implementation connects to real market data to observe and analyze these order book dynamics in real-time.
This setup is intended for local development and learning. Infrastructure services are exposed on localhost without production-grade security. Only run on trusted networks.