feat: add WebSocket order book feed with reconnection and heartbeat#26
Open
alexanderxfgl-bit wants to merge 1 commit intokcolbchain:mainfrom
Open
feat: add WebSocket order book feed with reconnection and heartbeat#26alexanderxfgl-bit wants to merge 1 commit intokcolbchain:mainfrom
alexanderxfgl-bit wants to merge 1 commit intokcolbchain:mainfrom
Conversation
Closes kcolbchain#7 Implements transport-agnostic order book streaming via WebSocket: ## Changes - **src/connectors/orderbook_feed.py** — Full order book feed system: - BaseOrderBookFeed: Abstract interface for strategies to consume L2 data - WebSocketOrderBookFeed: Core WS transport with: - Exponential backoff reconnection - Heartbeat monitoring (ping/pong) - Snapshot + incremental delta merging - Delta queuing before initial snapshot - Zero-quantity level removal (filled/cancelled orders) - BinanceOrderBookFeed: Binance partial book depth stream adapter - UniswapV3OrderBookFeed: Reconstructed order book from slot0 data - OrderBookSnapshot with best_bid/ask, spread, mid_price, depth_at_price ## Tests 28 new tests covering: - OrderBookSnapshot properties (best_bid, best_ask, spread, mid_price, depth) - WebSocket feed subscribe/unsubscribe - Symbol normalization - Full snapshot replacement - Delta queuing before snapshot - Delta merging after snapshot - Zero-quantity level removal - Static level update helper - Binance message parsing - Binance non-depth event filtering - Uniswap V3 slot0 order book reconstruction - Sequence incrementing - Factory function create_binance_feed - Config defaults and custom values All 106 tests passing (1 pre-existing integration failure).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7
What
Adds a transport-agnostic WebSocket order book feed system that allows strategies to consume real-time L2 data without caring about the underlying transport.
Changes
src/connectors/orderbook_feed.py— Complete order book feed system:BaseOrderBookFeed— Abstract interface withsubscribe(),unsubscribe(),get_orderbook(), andon_update()callbacks. Strategies depend on this, not specific transports.WebSocketOrderBookFeed— Core WebSocket transport:ping_intervalandping_timeoutwait_for_snapshot()async helper for initial dataBinanceOrderBookFeed— Binance partial book depth stream:UniswapV3OrderBookFeed— Reconstructed order book from on-chain data:OrderBookSnapshot— Rich data model:best_bid,best_ask,spread,mid_pricepropertiesdepth_at_price()for analyzing liquidity at a levelcreate_binance_feed()— Factory function for quick setupTests
28 new tests covering:
All 106 tests passing (1 pre-existing integration failure).