|
| 1 | +# Migrating from v2.x to v3.0.0 |
| 2 | + |
| 3 | +v3.0.0 renames three groups of public methods. All old names continue to work |
| 4 | +in v3.0.0 as `@typing_extensions.deprecated` aliases that emit |
| 5 | +`DeprecationWarning` on every call. The aliases will be removed no sooner than |
| 6 | +**v3.1.0**, so migrate before then. |
| 7 | + |
| 8 | +The wire protocol is unchanged. v3 is purely a Python-API ergonomics break. |
| 9 | + |
| 10 | +## TL;DR — search and replace cheat sheet |
| 11 | + |
| 12 | +| Find | Replace | |
| 13 | +|---|---| |
| 14 | +| `.communications.list_rfqs(` | `.communications.rfqs.list(` | |
| 15 | +| `.communications.list_all_rfqs(` | `.communications.rfqs.list_all(` | |
| 16 | +| `.communications.get_rfq(` | `.communications.rfqs.get(` | |
| 17 | +| `.communications.create_rfq(` | `.communications.rfqs.create(` | |
| 18 | +| `.communications.delete_rfq(` | `.communications.rfqs.delete(` | |
| 19 | +| `.communications.list_quotes(` | `.communications.quotes.list(` | |
| 20 | +| `.communications.list_all_quotes(` | `.communications.quotes.list_all(` | |
| 21 | +| `.communications.get_quote(` | `.communications.quotes.get(` | |
| 22 | +| `.communications.create_quote(` | `.communications.quotes.create(` | |
| 23 | +| `.communications.delete_quote(` | `.communications.quotes.delete(` | |
| 24 | +| `.communications.accept_quote(` | `.communications.quotes.accept(` | |
| 25 | +| `.communications.confirm_quote(` | `.communications.quotes.confirm(` | |
| 26 | +| `.markets.list_trades_all(` | `.markets.list_all_trades(` | |
| 27 | +| `.orders.fills(` | `.portfolio.fills(` | |
| 28 | +| `.orders.fills_all(` | `.portfolio.fills_all(` | |
| 29 | + |
| 30 | +These map 1:1 — argument signatures and return types are identical. The only |
| 31 | +behavioral difference is that the old names emit a `DeprecationWarning`. |
| 32 | + |
| 33 | +## 1. CommunicationsResource sub-namespaces (#348) |
| 34 | + |
| 35 | +The flat noun-prefixed methods on `CommunicationsResource` collapse into two |
| 36 | +sub-resources matching the OpenAPI v3.18.0 tag structure. |
| 37 | + |
| 38 | +### Before (v2.x) |
| 39 | + |
| 40 | +```python |
| 41 | +from kalshi import KalshiClient |
| 42 | + |
| 43 | +client = KalshiClient.from_env() |
| 44 | + |
| 45 | +rfqs = client.communications.list_rfqs(limit=50) |
| 46 | +rfq = client.communications.get_rfq("rfq-123") |
| 47 | +new = client.communications.create_rfq(market_ticker="MKT-1", rest_remainder=True) |
| 48 | +client.communications.delete_rfq("rfq-123") |
| 49 | + |
| 50 | +quotes = client.communications.list_quotes(quote_creator_user_id="u1") |
| 51 | +client.communications.accept_quote("q-456", accepted_side="yes") |
| 52 | +client.communications.confirm_quote("q-456") |
| 53 | +``` |
| 54 | + |
| 55 | +### After (v3.0.0) |
| 56 | + |
| 57 | +```python |
| 58 | +from kalshi import KalshiClient |
| 59 | + |
| 60 | +client = KalshiClient.from_env() |
| 61 | + |
| 62 | +rfqs = client.communications.rfqs.list(limit=50) |
| 63 | +rfq = client.communications.rfqs.get("rfq-123") |
| 64 | +new = client.communications.rfqs.create(market_ticker="MKT-1", rest_remainder=True) |
| 65 | +client.communications.rfqs.delete("rfq-123") |
| 66 | + |
| 67 | +quotes = client.communications.quotes.list(quote_creator_user_id="u1") |
| 68 | +client.communications.quotes.accept("q-456", accepted_side="yes") |
| 69 | +client.communications.quotes.confirm("q-456") |
| 70 | +``` |
| 71 | + |
| 72 | +### Notes |
| 73 | + |
| 74 | +- `client.communications.get_id(...)` (the misc endpoint) **stays at the top |
| 75 | + level** — no sub-noun. |
| 76 | +- The async API mirrors the sync API: `async_client.communications.rfqs.list(...)`. |
| 77 | +- If you type-annotate sub-resource attributes, import the new classes from the |
| 78 | + top level: |
| 79 | + ```python |
| 80 | + from kalshi import RFQsResource, QuotesResource, AsyncRFQsResource, AsyncQuotesResource |
| 81 | + ``` |
| 82 | + |
| 83 | +## 2. `*_all` naming standardization (#349) |
| 84 | + |
| 85 | +`MarketsResource.list_trades_all` was the only outlier still using the |
| 86 | +`list_<noun>_all` suffix form. Renamed to `list_all_<noun>` (prefix form) to |
| 87 | +match the other three resources. |
| 88 | + |
| 89 | +### Before (v2.x) |
| 90 | + |
| 91 | +```python |
| 92 | +for trade in client.markets.list_trades_all(ticker="MKT-1", limit=200): |
| 93 | + process(trade) |
| 94 | +``` |
| 95 | + |
| 96 | +### After (v3.0.0) |
| 97 | + |
| 98 | +```python |
| 99 | +for trade in client.markets.list_all_trades(ticker="MKT-1", limit=200): |
| 100 | + process(trade) |
| 101 | +``` |
| 102 | + |
| 103 | +Same iterator semantics, same filter kwargs. |
| 104 | + |
| 105 | +## 3. `fills` relocation: orders → portfolio (#351) |
| 106 | + |
| 107 | +The `/portfolio/fills` endpoint now sits on `PortfolioResource` alongside |
| 108 | +`settlements`, `deposits`, and `withdrawals` — matching the URL family. |
| 109 | + |
| 110 | +### Before (v2.x) |
| 111 | + |
| 112 | +```python |
| 113 | +page = client.orders.fills(ticker="MKT-1", min_ts=since) |
| 114 | +for fill in client.orders.fills_all(order_id="ord-1"): |
| 115 | + process(fill) |
| 116 | +``` |
| 117 | + |
| 118 | +### After (v3.0.0) |
| 119 | + |
| 120 | +```python |
| 121 | +page = client.portfolio.fills(ticker="MKT-1", min_ts=since) |
| 122 | +for fill in client.portfolio.fills_all(order_id="ord-1"): |
| 123 | + process(fill) |
| 124 | +``` |
| 125 | + |
| 126 | +Signatures and return types are identical (`Page[Fill]` with `cursor`, |
| 127 | +`min_ts`, `max_ts`, `ticker`, `order_id`, etc.). |
| 128 | + |
| 129 | +## Detecting deprecated calls during migration |
| 130 | + |
| 131 | +The aliases use `@typing_extensions.deprecated` (PEP 702), which type checkers |
| 132 | +recognize. Add a stricter pytest config for the duration of your migration: |
| 133 | + |
| 134 | +```toml |
| 135 | +# pyproject.toml |
| 136 | +[tool.pytest.ini_options] |
| 137 | +filterwarnings = [ |
| 138 | + "error::DeprecationWarning:kalshi.*", |
| 139 | +] |
| 140 | +``` |
| 141 | + |
| 142 | +This turns every deprecated kalshi call into a test failure until you update. |
| 143 | + |
| 144 | +For a softer approach, log warnings instead of erroring: |
| 145 | + |
| 146 | +```python |
| 147 | +import warnings |
| 148 | +warnings.filterwarnings("default", category=DeprecationWarning, module=r"kalshi(\..*)?") |
| 149 | +``` |
| 150 | + |
| 151 | +## Why a major version for renames? |
| 152 | + |
| 153 | +Per project policy (CHANGELOG §2.7.0), bug-surfacing behavioral fences ship in |
| 154 | +minor releases; intentional public-API renames are reserved for major releases. |
| 155 | +v3.0.0 is the first major version under this policy. v2.5–v2.7 each shipped |
| 156 | +behavioral fences in minor versions because they surfaced silent bugs; |
| 157 | +v3.0.0 renames previously-correct method names purely for API ergonomics. |
| 158 | + |
| 159 | +## Removal schedule |
| 160 | + |
| 161 | +The deprecated aliases will be removed no sooner than **v3.1.0**. Migration |
| 162 | +done before then is forward-compatible across all v3.x. |
0 commit comments