Commit 9de0cee
Issue #46: every body-endpoint method had a sync+async pair that differed
only by `def` vs `async def` and `self._post(...)` vs `await self._post(...)`.
The dispatcher logic (`_check_request_exclusive` + model construction +
`model_dump(...)`) was duplicated verbatim across the two classes, so each
new kwarg had to be added in two places.
Conservative dedup (option 1 in the issue): pull the identical parts of each
method-pair into module-level helpers; both sync and async methods call them.
- _build_*_body(...) helpers: dispatcher inputs (request | individual kwargs)
→ dict ready for transport. Owns the exclusive-arg check, the model
construction, and the `model_dump(...)` serialization.
- Per-resource query-param builders for GET-list endpoints whose param dicts
appeared 4× (sync list, sync list_all, async list, async list_all).
- _parse_orderbook + _parse_queue_position response helpers in markets/orders.
What stays per-class (unchanged): method signatures, @overload stubs from
#69 (per-class user-facing typed surface), transport call sites, return-type
wrapping. The dual-transport architecture and `async for` ergonomics are
preserved.
Files refactored: orders, api_keys, communications, multivariate,
order_groups, subaccounts (high-payoff body-endpoint resources) plus
markets, events, historical, series, portfolio, fcm, milestones
(meaningful GET-list dedup). incentive_programs and structured_targets
are left as-is — too small for a helper to be cleaner than the inline
`_params(...)`.
Notes
- subaccounts.transfer: UUID coercion stays inside _build_transfer_body
(was duplicated across sync+async); behavior identical.
- multivariate.lookup_tickers: the sync `if data is None: raise RuntimeError`
spec-drift guard is preserved on sync only (async never had it; this
is a latent inconsistency, not in scope to fix here).
Gates
- ruff: clean
- mypy --strict: clean (75 files)
- pytest (unit): 1405 passed, 48 skipped (no test changes)
Closes #46
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent dd72fea commit 9de0cee
13 files changed
Lines changed: 1337 additions & 1008 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
21 | 61 | | |
22 | 62 | | |
23 | 63 | | |
| |||
51 | 91 | | |
52 | 92 | | |
53 | 93 | | |
54 | | - | |
| 94 | + | |
55 | 95 | | |
56 | 96 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 97 | | |
68 | 98 | | |
69 | 99 | | |
| |||
84 | 114 | | |
85 | 115 | | |
86 | 116 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 117 | + | |
95 | 118 | | |
96 | 119 | | |
97 | 120 | | |
| |||
127 | 150 | | |
128 | 151 | | |
129 | 152 | | |
130 | | - | |
| 153 | + | |
131 | 154 | | |
132 | 155 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | 156 | | |
144 | 157 | | |
145 | 158 | | |
| |||
162 | 175 | | |
163 | 176 | | |
164 | 177 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 178 | + | |
173 | 179 | | |
174 | 180 | | |
175 | 181 | | |
| |||
0 commit comments