Live on - https://datafeed.fun
A high-performance, low-latency market data feed server supporting multiple cryptocurrency exchanges with WebSocket and HTTP interfaces.
The Datafeed Server is designed to aggregate real-time market data from various cryptocurrency exchanges (Binance, Jupiter, Birdeye) and distribute it to connected clients via WebSocket subscriptions. The server features:
- Multi-exchange support: Connect to Binance, Jupiter (Solana), and Birdeye exchanges
- WebSocket API: Real-time data streaming with topic-based subscriptions
- HTTP API: REST endpoints for configuration and monitoring
- PostgreSQL persistence: Comprehensive logging and metrics storage
- Horizontal scalability: Designed for multiple instances behind a load balancer
- Comprehensive monitoring: Built-in metrics, health checks, and audit trails
- Dockerized deployment: Easy containerized deployment with docker-compose
- Real-time ticker data from multiple exchanges
- Topic-based WebSocket subscriptions (ticker_, price_, bid_, ask_, etc.)
- Live and backtest data modes
- Exchange failover and reconnection handling
- Message rate limiting and backpressure management
- Real-time performance metrics (latency, throughput, error rates)
- Per-exchange health monitoring
- Detailed audit logging of all actions
- API request logging with latency tracking
- Prometheus-compatible metrics endpoint (planned)
- Runtime exchange switching without downtime
- Dynamic symbol subscription management
- Configuration via environment variables or config files
- Comprehensive PostgreSQL schema for persistence
- Health check endpoints for load balancer integration
- Modular design with separate exchange adapters
- Session management for tracking client connections
- Event-driven architecture using Boost.Asio and Boost.Beast
- Thread-safe data structures for high concurrency
- Zero-copy message passing where possible
- Docker and Docker Compose (for containerized deployment)
- OR:
- C++17 compiler (GCC 9+ or Clang 10+)
- CMake 3.10+
- Boost 1.74+
- OpenSSL 1.1.1+
- PostgreSQL 12+
- nlohmann_json 3.0+
- libpqxx 7.0+
-
Clone the repository:
git clone <repository-url> cd datafeed
-
Build and start the services:
docker compose up --build
-
The server will be available at:
- WebSocket:
ws://localhost:4444 - HTTP health check:
http://localhost:4444/health(if implemented)
- WebSocket:
-
Install dependencies:
# Ubuntu/Debian sudo apt-get install build-essential cmake libboost-all-dev libssl-dev libpq-dev libnlohmann-json-dev # macOS (using Homebrew) brew install boost openssl postgresql nlohmann-json libpqxx
-
Build the project:
mkdir -p build && cd build cmake .. make -j$(nproc)
-
Run the server:
./datafeed 0.0.0.0 4444 1
Arguments:
<address> <port> <thread-count> -
Ensure PostgreSQL is running and configured:
# Initialize database psql -h localhost -U postgres -f init/schema.sql psql -h localhost -U postgres -f init/seed.sql
The server can be configured via environment variables:
| Variable | Description | Default |
|---|---|---|
EXCHANGE |
Default exchange to connect to (BINANCE, JUPITER, BIRDEYE) | BINANCE |
PORT |
Server port | 4444 |
ADDRESS |
Bind address | 0.0.0.0 |
THREADS |
Number of I/O threads | 1 |
DATABASE_URL |
PostgreSQL connection string | postgres://localhost/datafeed |
LOG_LEVEL |
Logging level (trace, debug, info, warn, error) | info |
JUPITER_API_KEY |
API key for Jupiter exchange (optional) | (none) |
ENABLE_METRICS |
Enable Prometheus metrics endpoint | false |
Example .env file:
EXCHANGE=BINANCE
PORT=4444
ADDRESS=0.0.0.0
THREADS=2
DATABASE_URL=postgres://user:password@localhost:5432/datafeed
LOG_LEVEL=info
ENABLE_METRICS=trueConnect to ws://<host>:<port> using any WebSocket client.
All messages are JSON objects.
{
"action": "subscribe",
"topic": "ticker_"
}Available actions:
subscribe: Subscribe to one or more topicsunsubscribe: Unsubscribe from topicsswitch_exchange: Change the exchange being used (requires symbols)set_mode: Switch between live and backtest modes
{
"topic": "ticker_",
"symbol": "BTCUSDT",
"price": 43250.12,
"bid": 43249.88,
"ask": 43250.36,
"timestamp": 1640995200000
}Topics:
ticker_: Latest price, bid, ask for a symbolprice_: Price updates onlybid_: Bid price updatesask_: Ask price updatestrade_: Individual trades (if available from exchange)orderbook_: Order book updates (if available)
Subscribe to ticker updates for BTC and ETH:
{"action": "subscribe", "topic": "ticker_", "symbols": ["BTCUSDT", "ETHUSDT"]}Subscribe to all available topics:
{"action": "subscribe", "topic": "all_"}Switch to Jupiter exchange with Solana symbols:
{
"action": "switch_exchange",
"exchange": "JUPITER",
"symbols": ["SOL", "BTC", "ETH"]
}The following endpoints are planned for future implementation:
GET /health- Health check endpointGET /metrics- Prometheus metricsGET /instances- List active feed instancesGET /clients/{id}- Get client informationPOST /clients- Create new clientGET /subscriptions- List active subscriptionsPOST /subscriptions- Create new subscriptionDELETE /subscriptions/{id}- Delete subscriptionGET /events- Query audit eventsGET /exchange-health- Get health of all exchanges
The server uses PostgreSQL for persistence. See init/schema.sql for the complete schema.
Key tables:
clients- Tenant/client informationsessions- WebSocket/HTTP session trackingsubscriptions- Client subscriptions to market datafeed_instances- Runtime feed health per instancefeed_metrics_snapshots- Time-series performance metricsfeed_events- Audit/action logapi_requests- HTTP request loggingexchange_health- Per-exchange health monitoringbacktest_jobs- Backtest/replay job trackingconfig_versions- Configuration and version tracking
The server exposes several mechanisms for monitoring:
- Structured logging with severity levels
- Console and file output options
- JSON log format available
- Feed instance health stored in
feed_instancestable - Time-series metrics in
feed_metrics_snapshotstable - Error counts and rates in various tables
- Audit trail in
feed_events
- TCP connection health (port 4444)
- Exchange connectivity status
- Database connection status
- Memory and CPU usage (via external monitoring)
When enabled (ENABLE_METRICS=true), the server will expose:
datafeed_messages_sent_totaldatafeed_messages_received_totaldatafeed_latency_milliseconds(histogram)datafeed_exchange_connection_status(gauge)datafeed_subscriptions_active(gauge)datafeed_cpu_usage_ratiodatafeed_memory_usage_bytes
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j$(nproc)# Unit tests (when implemented)
ctest --output-on-failure
# Stress test
python3 stress_test.py --clients 50 --duration 60- Follows Google C++ Style Guide with exceptions
- clang-format configuration in
.clang-format - Lint with
clang-tidy
# docker-compose.prod.yml
version: '3.8'
services:
datafeed:
build: .
ports:
- "4444:4444"
environment:
- EXCHANGE=BINANCE
- DATABASE_URL=postgres://user:password@postgres:5432/datafeed
- LOG_LEVEL=info
depends_on:
- postgres
restart: unless-stopped
postgres:
image: postgres:14
environment:
- POSTGRES_DB=datafeed
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
volumes:
postgres_data:See k8s/ directory for example manifests (when available).
- Run multiple instances behind a TCP load balancer (HAProxy, NGINX, cloud LB)
- Use sticky sessions or Redis-backed session store if needed
- Each instance maintains its own exchange connections
- Consider sharding by symbol or client for very large deployments
The included stress_test.py script can simulate multiple clients:
python3 stress_test.py --helpExample: 100 clients for 2 minutes
python3 stress_test.py --clients 100 --duration 120- Start the server
- Use
wscator similar WebSocket client:wscat -c ws://localhost:4444
- Send subscription commands:
> {"action": "subscribe", "topic": "ticker_"} < {"topic":"ticker_","symbol":"BTCUSDT","price":43250.12,"bid":43249.88,"ask":43250.36,"timestamp":1640995200000}
- Verify server is running:
docker compose psorps aux | grep datafeed - Check port binding:
netstat -tlnp | grep 4444 - Review logs:
docker compose logs datafeedorcat server.log
- Ensure PostgreSQL is running and accessible
- Verify connection string in
DATABASE_URL - Check that schema has been applied:
psql -c "\dt"in datafeed database - Look for errors in server startup logs
- Confirm exchange connection: Look for "[Exchange1] Connected to Binance WebSocket" in logs
- Check subscription was processed: Look for "[EAdapter] Subscribed to 3 symbols"
- Verify topic matching in client subscription
- Check firewall/network restrictions to exchange endpoints
- Check system resources (CPU, memory, network)
- Verify exchange WebSocket connection stability
- Look for garbage collection pauses or thread contention
- Consider increasing thread count if CPU-bound
- Monitor database write performance if logging is enabled
For issues, questions, or contributions:
- Check existing issues in the repository
- Submit a new issue with detailed reproduction steps
- For security concerns, contact security@yourcompany.com
This project is licensed under the MIT License - see the LICENSE file for details.
- Boost.Asio and Boost.Beast for networking
- nlohmann_json for JSON parsing
- libpqxx for PostgreSQL C++ interface
- The cryptocurrency exchange APIs (Binance, Jupiter, Birdeye) for providing market data