feat: async client pilot (httpx) for cex.candle + cex.ticker (#142)#149
Merged
Conversation
Closes #142 Add datamaxi.aio.AsyncDatamaxi (optional 'async' extra, httpx). Pilot scope: cex.candle + cex.ticker, async context manager, bounded retry of transient 5xx, ClientError/ServerError parity, and last_response. To avoid sync/async drift, extract endpoint resolution + error handling into datamaxi._dispatch (resolve_endpoint, raise_for_error, extract_limit_usage) and have the sync API delegate to them (behavior-preserving; full sync suite still green). httpx is an optional dependency (datamaxi[async]); importing the sync client never loads it, and using the async client without it raises a clear install hint. Query params are str()-encoded so bools match the sync urlencode output ('True', not httpx's 'true').
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 #142
Async client pilot — the scoped approach we agreed on (candle + ticker first, httpx as an optional extra), not the full mirror.
What's added
datamaxi.aio.AsyncDatamaxi(httpx-based):AsyncAPItransport: async context manager (aclose), bounded retry of transient 5xx,ClientError/ServerErrorparity,last_responsemetadata — mirrors the sync client.cex.candle+cex.ticker.get(same validation + DataFrame/pandas=Falsebehavior as sync).No sync/async drift
Extracted the shared request core into
datamaxi/_dispatch.py—resolve_endpoint(op_id → method/url/query),raise_for_error,extract_limit_usage— and made the syncAPIdelegate to them. Behavior-preserving: the full sync suite stays green. Both clients now build requests and raise errors through the exact same code.httpx = optional extra
pip install "datamaxi[async]"(added to[project.optional-dependencies]).pip install 'datamaxi[async]'hint.str()-encoded so bools serialize as"True"(matching the sync urlencode output), not httpx's"true".Tests
tests/test_async.py(7) viahttpx.MockTransport(no network/extra deps,importorskipguard): candle→DataFrame,pandas=False→envelope, bool-param encoding,last_response,ClientErroron 4xx, retry503,503,200, and validation-before-request. httpx added torequirements-test.txtso CI runs them.pytest -m "not integration": 162 passed, 11 skipped (155 + 7).import datamaxidoesn't pull httpx.Scope / next steps
Deliberately small. Expanding to the full resource tree (~17 classes / ~50 methods) is the follow-on if the pattern lands well — each endpoint's async method is a thin duplicate of its sync validation/shaping over the shared transport. Same hand-maintenance/drift caveat as the typed models applies.
Known failures
None.