WS: structured subscribe helpers (generic param builder) - #179
Merged
Conversation
Add build_param() that assembles a wire subscribe param from keyword tokens named after the generated WS_CHANNELS[path]['param'] format string. Generic (registry-driven), zero per-channel code: new channels get structured helpers for free. Token->kwarg rule: all-upper tokens lower-cased (SYMBOL->symbol), others verbatim (exchange, tokenId, srcQuote). Handles @/: separators and the optional [@...] both-or-neither group. Wire into Subscription/MarketSubscription subscribe+unsubscribe; raw positional path unchanged, mixing raw+tokens rejected.
Unit-test build_param for every format (forex SYMBOL, SYMBOL@exchange, ticker with/without optional currency@conversionBase, premium 7 tokens), the SYMBOL->symbol lowercase rule, and error cases (missing required, unknown token, partial optional group, None channel, mixing raw+tokens). Round-trip: structured == raw wire string. Integration: structured ws.ticker.subscribe(...) sends BTC-USDT@binance over a fake conn.
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 #170
What
Adds structured WS subscribe helpers driven by the generated registry, keeping the raw-string path fully backward-compatible.
build_param(param_format, **tokens) -> strindatamaxi/aio/ws.py: assembles a wire subscribe param from keyword tokens whose names ARE the raw tokens inWS_CHANNELS[path]["param"].SYMBOL->symbol); every other token is verbatim (exchange,tokenId,srcQuote, ...). Documented in the docstring.None(no params -> reject kwargs), singleSYMBOL(no separator),@/:separated tokens (separator inferred), and a trailing[@...]optional both-or-neither group.Subscription.subscribe/unsubscribeandMarketSubscription.subscribe/unsubscribevia a small_resolve_paramsguard.market=on ticker stays a control kwarg (not a param token).Usage
Why
Ergonomic named-arg subscribe without hand-writing per-channel mappings (issue's Option 1). Raw wire-string path preserved.
Decisions / notes
source_exchange/token_id) per the maintainer's Option 1 — zero per-channel code.ValueError.param: Nonechannel raiseValueError.Test plan
python -m pytest tests/test_ws.py -q-> 27 passed (13 pre-existing + 14 new).flake8clean;blackclean.build_paramper format; SYMBOL->symbol rule; errors (missing required, unknown token, partial optional group, None channel, mixing raw+tokens); round-trip structured == raw wire string; integration structuredws.ticker.subscribe(...)sendsBTC-USDT@binanceover a fake conn.Known failures
None.