|
64 | 64 | "list_rfqs", |
65 | 65 | ], |
66 | 66 | ) |
| 67 | +register( |
| 68 | + "RFQsResource", |
| 69 | + ["create", "delete", "get", "list", "list_all"], |
| 70 | +) |
| 71 | +register( |
| 72 | + "QuotesResource", |
| 73 | + ["accept", "confirm", "create", "delete", "get", "list", "list_all"], |
| 74 | +) |
67 | 75 |
|
68 | 76 |
|
69 | 77 | @pytest.fixture |
@@ -179,6 +187,139 @@ def test_get_unknown_quote_errors(self, sync_client: KalshiClient) -> None: |
179 | 187 | sync_client.communications.get_quote("q-nonexistent-00000000") |
180 | 188 |
|
181 | 189 |
|
| 190 | +@pytest.mark.integration |
| 191 | +class TestRFQsV3Sync: |
| 192 | + """v3 namespaced surface: ``client.communications.rfqs.*``. |
| 193 | +
|
| 194 | + These calls forward to the same endpoints as the deprecated |
| 195 | + top-level methods; this class proves the new public path works |
| 196 | + end-to-end on demo. |
| 197 | + """ |
| 198 | + |
| 199 | + def test_list(self, sync_client: KalshiClient) -> None: |
| 200 | + page = sync_client.communications.rfqs.list(limit=10) |
| 201 | + assert isinstance(page, Page) |
| 202 | + for rfq in page.items: |
| 203 | + assert isinstance(rfq, RFQ) |
| 204 | + |
| 205 | + def test_list_all(self, sync_client: KalshiClient) -> None: |
| 206 | + for i, rfq in enumerate( |
| 207 | + sync_client.communications.rfqs.list_all(limit=10), |
| 208 | + ): |
| 209 | + assert isinstance(rfq, RFQ) |
| 210 | + if i >= 4: |
| 211 | + break |
| 212 | + |
| 213 | + def test_create_get_delete( |
| 214 | + self, sync_client: KalshiClient, demo_market_ticker: str, |
| 215 | + ) -> None: |
| 216 | + try: |
| 217 | + created = sync_client.communications.rfqs.create( |
| 218 | + market_ticker=demo_market_ticker, |
| 219 | + rest_remainder=False, |
| 220 | + contracts=1, |
| 221 | + ) |
| 222 | + except (KalshiValidationError, KalshiAuthError) as e: |
| 223 | + pytest.skip(f"demo refused rfqs.create: {e}") |
| 224 | + assert isinstance(created, CreateRFQResponse) |
| 225 | + try: |
| 226 | + time.sleep(0.5) # eventual consistency on demo |
| 227 | + got = sync_client.communications.rfqs.get(created.id) |
| 228 | + assert isinstance(got, GetRFQResponse) |
| 229 | + assert got.rfq.id == created.id |
| 230 | + finally: |
| 231 | + sync_client.communications.rfqs.delete(created.id) |
| 232 | + |
| 233 | + |
| 234 | +@pytest.mark.integration |
| 235 | +class TestQuotesV3Sync: |
| 236 | + """v3 namespaced surface: ``client.communications.quotes.*``. |
| 237 | +
|
| 238 | + ``list`` and ``list_all`` need a creator filter on demo; ``accept`` and |
| 239 | + ``confirm`` require two parties — both live behind the real-API gate to |
| 240 | + mirror ``TestCommunicationsRealApiOnly``. The lifecycle test exercises |
| 241 | + ``create`` / ``get`` / ``delete`` which the demo supports for self-quoting. |
| 242 | + """ |
| 243 | + |
| 244 | + def test_quote_lifecycle( |
| 245 | + self, sync_client: KalshiClient, ephemeral_rfq: str, |
| 246 | + ) -> None: |
| 247 | + try: |
| 248 | + created = sync_client.communications.quotes.create( |
| 249 | + rfq_id=ephemeral_rfq, |
| 250 | + yes_bid="0.50", |
| 251 | + no_bid="0.50", |
| 252 | + rest_remainder=False, |
| 253 | + ) |
| 254 | + except (KalshiValidationError, KalshiAuthError) as e: |
| 255 | + pytest.skip(f"demo refused quotes.create: {e}") |
| 256 | + quote_id = created.id |
| 257 | + try: |
| 258 | + time.sleep(0.5) |
| 259 | + got = sync_client.communications.quotes.get(quote_id) |
| 260 | + assert got.quote.id == quote_id |
| 261 | + assert got.quote.rfq_id == ephemeral_rfq |
| 262 | + finally: |
| 263 | + try: |
| 264 | + sync_client.communications.quotes.delete(quote_id) |
| 265 | + except Exception: |
| 266 | + logger.warning("cleanup: failed to delete quote %s", quote_id) |
| 267 | + |
| 268 | + |
| 269 | +@pytest.mark.integration |
| 270 | +@pytest.mark.integration_real_api_only |
| 271 | +class TestQuotesV3RealApiOnly: |
| 272 | + """v3 namespaced surface for endpoints the demo can't service. |
| 273 | +
|
| 274 | + See ``TestCommunicationsRealApiOnly`` for the underlying demo |
| 275 | + constraints — these tests mirror that gating against the new |
| 276 | + ``client.communications.quotes`` namespace. |
| 277 | + """ |
| 278 | + |
| 279 | + def test_list(self, sync_client: KalshiClient) -> None: |
| 280 | + comms_id = sync_client.communications.get_id().communications_id |
| 281 | + page = sync_client.communications.quotes.list( |
| 282 | + limit=10, quote_creator_user_id=comms_id, |
| 283 | + ) |
| 284 | + assert isinstance(page, Page) |
| 285 | + |
| 286 | + def test_list_all(self, sync_client: KalshiClient) -> None: |
| 287 | + comms_id = sync_client.communications.get_id().communications_id |
| 288 | + for i, quote in enumerate( |
| 289 | + sync_client.communications.quotes.list_all( |
| 290 | + limit=10, quote_creator_user_id=comms_id, |
| 291 | + ), |
| 292 | + ): |
| 293 | + assert isinstance(quote, Quote) |
| 294 | + if i >= 4: |
| 295 | + break |
| 296 | + |
| 297 | + def test_accept_and_confirm( |
| 298 | + self, sync_client: KalshiClient, demo_market_ticker: str, |
| 299 | + ) -> None: |
| 300 | + rfq = sync_client.communications.rfqs.create( |
| 301 | + market_ticker=demo_market_ticker, |
| 302 | + rest_remainder=False, |
| 303 | + contracts=1, |
| 304 | + ) |
| 305 | + try: |
| 306 | + quote = sync_client.communications.quotes.create( |
| 307 | + rfq_id=rfq.id, |
| 308 | + yes_bid="0.50", |
| 309 | + no_bid="0.50", |
| 310 | + rest_remainder=False, |
| 311 | + ) |
| 312 | + sync_client.communications.quotes.accept( |
| 313 | + quote.id, accepted_side="yes", |
| 314 | + ) |
| 315 | + sync_client.communications.quotes.confirm(quote.id) |
| 316 | + finally: |
| 317 | + try: |
| 318 | + sync_client.communications.rfqs.delete(rfq.id) |
| 319 | + except Exception: |
| 320 | + logger.warning("cleanup: failed to delete rfq %s", rfq.id) |
| 321 | + |
| 322 | + |
182 | 323 | @pytest.mark.integration |
183 | 324 | @pytest.mark.integration_real_api_only |
184 | 325 | class TestCommunicationsRealApiOnly: |
|
0 commit comments