Repository navigation
Support live Lighter WebSocket channels (1.11.0) - #11
Merged
Merged
Conversation
lighter_orderbook, lighter_trades, lighter_open_interest and lighter_funding now accept live subscriptions. lighter_candles and lighter_l3_orderbook stay replay-only, and replay of all six channels is unchanged. - subscribe() and subscribe_async() take an interval_ms keyword for lighter_orderbook (100 to 5000 ms, one book a second when omitted). It is validated before anything is sent and re-sent on reconnect. - subscribe_lighter_* / unsubscribe_lighter_* helpers. - on_lighter_orderbook, on_lighter_trades and on_lighter_market_context handlers, so Lighter BTC is not mixed up with Hyperliquid BTC. Lighter books and trades still reach on_orderbook / on_trades when the dedicated handlers are not set. - Typed live payloads: LighterLiveTrade, LighterMarketContext and LighterMarketContextUpdate. Live trade legs map the Lighter account index to the new Trade.account_index field, which Lighter REST trades also carry. - symbol on WsSubscribed, WsUnsubscribed and WsData. - README WebSocket section, CHANGELOG and version 1.11.0.
- Live Lighter subscriptions are keyed by the uppercase symbol, as the server treats them. Subscribing as btc and unsubscribing as BTC now removes the subscription and its interval_ms, so a reconnect does not restore it, and a resubscribe in another case replaces the earlier interval. - A non-integer interval_ms (for example 250.0 or True) raises "interval_ms must be an integer number of milliseconds" instead of the out-of-range message. Out-of-range integers keep the server's wording.
… versions The README listed the Hyperliquid open_interest and funding WebSocket channels as replay only. Both stream live as well, so the channel table, the replay section and the real-time streaming section now say so and show how to subscribe. HIP-3 wording is unchanged. The 1.11.0 changelog entry now states that 1.7.1 through 1.10.0 were not published to PyPI, so upgrading from PyPI goes straight from 1.7.0 to 1.11.0.
The server has discontinued WebSocket bulk streaming and answers
{"op": "stream"} with an error that points to the S3 Parquet bulk export.
stream(), multi_stream() and stream_stop() stay for compatibility but now
emit a DeprecationWarning, and their docstrings say the call returns the
server's error and that large downloads use the bulk export at
https://0xarchive.io/data. The bulk stream handler setters and message
models are marked deprecated with them, and the bulk streaming example is
gone from the module docstring.
The WsChannel docstring now lists Hyperliquid open_interest and funding as
live and replayable. The HIP-3 wording is unchanged. The README drops the
"replay/stream" wording and notes that bulk streaming is discontinued.
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.
Summary
Live subscriptions now work for four Lighter channels:
lighter_orderbook,lighter_trades,lighter_open_interestandlighter_funding.lighter_candlesandlighter_l3_orderbookstay replay-only, and replay of all six Lighter channels is unchanged.Client
subscribe()andsubscribe_async()take aninterval_mskeyword forlighter_orderbook. Books default to one per second; 100 to 5000 ms is accepted. The SDK raisesValueErrorwith the server's wording if it is passed on another channel or is out of range, and with its own message if it is not an integer (the server ignores such a subscribe without replying). It is re-sent on reconnect, and a later subscribe without it goes back to the default, which matches how the server replaces a subscription.btcand unsubscribing asBTCremoves the subscription and it is not restored on reconnect.subscribe_lighter_orderbook(coin, interval_ms=None),subscribe_lighter_trades,subscribe_lighter_open_interest,subscribe_lighter_fundingand the matchingunsubscribe_*methods.on_lighter_orderbook,on_lighter_tradesandon_lighter_market_context. When the first two are set they take precedence overon_orderbookandon_trades, so LighterBTCis not mixed up with HyperliquidBTC. When they are not set, Lighter books and trades still reach the generic handlers.Types
LighterLiveTrademodels one live trade leg: two legs per trade sharetid,usersholds the Lighter account index, and the fee fields anddirare always null.LighterMarketContextandLighterMarketContextUpdatemodel the message that bothlighter_open_interestandlighter_fundingcarry. Fields use the SDK's snake_case names, and the wire camelCase keys are accepted as aliases.OrderBook.Trade.account_indexfield. Live Lighter legs set it, and so do Lighter REST trades, which already returnaccount_index.symboladded toWsSubscribed,WsUnsubscribedandWsData.Docs and release
Checks
pytest(Python 3.12): 85 passed. This includes new tests for subscribe serialization with and withoutinterval_ms, boundary and rejection cases, case-insensitive subscription tracking, the replay-only rules, re-sending on reconnect, handler precedence and fallback, and parsing of real production frames for all three payload types.tests/test_websocket_capabilities.pyon Python 3.9: 60 passed.ruff check oxarchive testsandmypy oxarchive: no new findings compared withmaster. The existing findings are unchanged.python -m build: sdist and wheel build. I reproduced the package-contents workflow on a clean clone, with stray files planted as the workflow does. Every packaged file is tracked source or build metadata.wss://api.0xarchive.io/ws:n=1. BTC arrived about every 250 ms withinterval_ms=250and ETH about once a second by default.tid.interval_mserror messages match the client-side ones for a wrong channel and an out-of-range value.btcsubscribe is acked asBTC, and aBTCunsubscribe stops it.