Skip to content

feat: typed response-model pilot for candle + ticker (#141)#146

Merged
martinkersner merged 1 commit into
mainfrom
feat/typed-response-models-pilot
Jul 3, 2026
Merged

feat: typed response-model pilot for candle + ticker (#141)#146
martinkersner merged 1 commit into
mainfrom
feat/typed-response-models-pilot

Conversation

@martinkersner

Copy link
Copy Markdown
Member

Closes #141

Summary

Pilot for typed response models (the scoped approach we agreed on). Adds hint-only TypedDicts for the pandas=False return of the two highest-traffic endpoints and annotates their return types.

  • datamaxi/resources/responses.py: CandleRow / CandleResponse, TickerData / TickerResponse.
  • CexCandle.__call__Union[pd.DataFrame, CandleResponse]; CexTicker.getUnion[pd.DataFrame, TickerResponse].
  • Exported from the top level (from datamaxi import CandleRow, TickerData, ...) so callers can annotate their own code.

Accuracy notes

  • Fields sourced from the live API docs (docs.datamaxiplus.com/rest/cex/{candle,ticker}/data), not guessed — candle: d,o,h,l,c,v; ticker: b,d,e,hb,la,ld,m,p,p24h,pc,q,s,ud,v.
  • Typed as str: numeric values arrive as strings on the wire (missing → the literal "NaN", which is why the converter does df.replace("NaN", pd.NA)); only the pandas=True path coerces to numbers. So the raw dict is faithfully str-valued.
  • Hint-onlyTypedDict has no runtime cost/validation. Zero behavior change; the pandas=True default still returns a DataFrame.

Scope

Deliberately small (2 endpoints) per our discussion — DataFrames are the default interface, so typed models only help the pandas=False path. Other endpoints can be typed the same way incrementally; a full, drift-proof version would require emitting response schemas from the upstream OpenAPI codegen (bigger, cross-repo).

Tests

  • New tests/test_response_models.py (4): assert documented field sets, that a pandas=False candle call matches the typed envelope shape at runtime, and that pandas=True still returns a DataFrame.
  • pytest -m "not integration": 149 passed, 11 skipped (145 + 4).
  • black + flake8 clean.

Known failures

None.

Closes #141

Add hint-only TypedDicts (CandleRow/CandleResponse, TickerData/TickerResponse)
describing the raw pandas=False JSON of the candle and ticker endpoints, and
annotate those two methods' return types with them. Fields sourced from the
live API docs; typed as str because numeric values arrive as strings on the
wire (missing -> "NaN", coerced only on the pandas=True path).

Hint-only: no runtime cost, no validation, no behavior change. Exported from
the top level so callers can annotate their own code. Deliberately small pilot;
other endpoints can be typed the same way incrementally.
@martinkersner martinkersner merged commit 615ecb6 into main Jul 3, 2026
5 checks passed
@martinkersner martinkersner deleted the feat/typed-response-models-pilot branch July 3, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed response models (TypedDict/dataclasses) for endpoint returns

1 participant