A real-time LOB (live order book) reconstruction tool written in pure C, using WebSockets to stream live market data from centralized exchanges like Binance.
- Real-time LOB Assembly: Reconstructs the order book from WebSocket depth update streams
- Live Display: Prints the top-of-book levels to the screen in real-time
- Data Persistence: Writes LOB snapshots to local CSV files in LOBSTER format
- Efficient Hash Table Management: Uses uthash for O(1) hash table operations on price levels
- REST API Integration: Fetches initial depth snapshots via Binance REST API, then applies delta updates from WebSocket streams
clang -o lob-stream ini.c lob-stream.c -v -L/usr/local/lib -I/usr/local/opt/openssl/include -Wall -Wextra -lwebsockets -lcurl -lcjson -pthreadWith address sanitizer for memory debugging:
clang -o lob-stream ini.c lob-stream.c -fsanitize=address -L/usr/local/lib -I/usr/local/opt/openssl/include -Wall -Wextra -lwebsockets -lcurl -lcjson -pthreadEdit config.ini to set WebSocket connection details and asset parameters:
port: WebSocket server portaddress: WebSocket server addresspath: WebSocket stream pathdepth_snapshot_url: REST API endpoint for initial depth snapshotsymbol: Trading pair (e.g., BTCUSDT)stream: Stream type (e.g., FUTURES, SPOT)num_levels: Number of price levels to track
- uthash (https://troydhanson.github.io/uthash/) - Hash table library for O(1) price level lookups
- libwebsockets (https://libwebsockets.org) - WebSocket client library
- cJSON (https://github.com/DaveGamble/cJSON) - JSON parsing
- libcurl - HTTP client for REST API calls
- POSIX threads (pthread) - Multi-threaded processing
To check for memory leaks:
leaks -atExit -- ./lob-stream > report.txt