From 0a0387ec735d244e4787cc53a26013bfedabf358 Mon Sep 17 00:00:00 2001 From: Cesare Naldi <3353250+cesarenaldi@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:36:52 +0200 Subject: [PATCH 1/2] fix(rfq): support balance error codes --- src/polymarket/rfq.py | 3 +++ tests/integration/test_rfq.py | 15 +++++++++++++-- tests/unit/test_rfq_error_codes.py | 10 ++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_rfq_error_codes.py diff --git a/src/polymarket/rfq.py b/src/polymarket/rfq.py index 237c182..d94118c 100644 --- a/src/polymarket/rfq.py +++ b/src/polymarket/rfq.py @@ -50,6 +50,8 @@ class RfqExecutionStatus(StrEnum): class RfqErrorCode(StrEnum): ADDRESS_MISMATCH = "ADDRESS_MISMATCH" + ALLOWANCE_VALIDATION_FAILED = "ALLOWANCE_VALIDATION_FAILED" + BALANCE_VALIDATION_FAILED = "BALANCE_VALIDATION_FAILED" CONTRADICTORY_LEGS = "CONTRADICTORY_LEGS" EXPIRED_RFQ = "EXPIRED_RFQ" INVALID_ACCEPTANCE = "INVALID_ACCEPTANCE" @@ -64,6 +66,7 @@ class RfqErrorCode(StrEnum): LEG_METADATA_UNAVAILABLE = "LEG_METADATA_UNAVAILABLE" MAKER_ALREADY_RESPONDED = "MAKER_ALREADY_RESPONDED" MAKER_NOT_REQUIRED = "MAKER_NOT_REQUIRED" + PRE_EXECUTION_BALANCE_RESERVATION_FAILED = "PRE_EXECUTION_BALANCE_RESERVATION_FAILED" QUOTE_MISMATCH = "QUOTE_MISMATCH" QUOTE_UNAVAILABLE = "QUOTE_UNAVAILABLE" RATE_LIMITED = "RATE_LIMITED" diff --git a/tests/integration/test_rfq.py b/tests/integration/test_rfq.py index a462a9e..02af98d 100644 --- a/tests/integration/test_rfq.py +++ b/tests/integration/test_rfq.py @@ -14,6 +14,7 @@ from polymarket.errors import TransportError, UnexpectedResponseError from polymarket.rfq import ( RfqConfirmationRequestEvent, + RfqErrorCode, RfqExecutionStatus, RfqQuoteRejectedError, RfqQuoteRequestEvent, @@ -363,8 +364,17 @@ async def handler(ws: ServerConnection) -> None: @pytest.mark.integration +@pytest.mark.parametrize( + "code", + [ + RfqErrorCode.ALLOWANCE_VALIDATION_FAILED, + RfqErrorCode.BALANCE_VALIDATION_FAILED, + RfqErrorCode.PRE_EXECUTION_BALANCE_RESERVATION_FAILED, + ], +) async def test_rfq_session_quote_rejection_raises_typed_error( require_env: Callable[[str], str], + code: RfqErrorCode, ) -> None: async def handler(ws: ServerConnection) -> None: async for raw in ws: @@ -380,7 +390,7 @@ async def handler(ws: ServerConnection) -> None: "type": "RFQ_ERROR", "request_type": "RFQ_QUOTE", "rfq_id": RFQ_ID, - "code": "INVALID_QUOTE", + "code": code, "error": "quote rejected", } ) @@ -393,8 +403,9 @@ async def handler(ws: ServerConnection) -> None: ): async for event in session: assert isinstance(event, RfqQuoteRequestEvent) - with pytest.raises(RfqQuoteRejectedError, match="quote rejected"): + with pytest.raises(RfqQuoteRejectedError, match="quote rejected") as exc_info: await event.quote(price=Decimal("0.45")) + assert exc_info.value.code == code break diff --git a/tests/unit/test_rfq_error_codes.py b/tests/unit/test_rfq_error_codes.py new file mode 100644 index 0000000..bf48b64 --- /dev/null +++ b/tests/unit/test_rfq_error_codes.py @@ -0,0 +1,10 @@ +from polymarket.rfq import RfqErrorCode + + +def test_balance_and_reservation_rfq_error_codes_are_supported() -> None: + assert RfqErrorCode("ALLOWANCE_VALIDATION_FAILED") is RfqErrorCode.ALLOWANCE_VALIDATION_FAILED + assert RfqErrorCode("BALANCE_VALIDATION_FAILED") is RfqErrorCode.BALANCE_VALIDATION_FAILED + assert ( + RfqErrorCode("PRE_EXECUTION_BALANCE_RESERVATION_FAILED") + is RfqErrorCode.PRE_EXECUTION_BALANCE_RESERVATION_FAILED + ) From 2b71c99556b45eff3c3f3be36112e5847dfb905d Mon Sep 17 00:00:00 2001 From: Cesare Naldi <3353250+cesarenaldi@users.noreply.github.com> Date: Thu, 11 Jun 2026 17:18:28 +0200 Subject: [PATCH 2/2] test(rfq): remove enum-only coverage --- tests/unit/test_rfq_error_codes.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 tests/unit/test_rfq_error_codes.py diff --git a/tests/unit/test_rfq_error_codes.py b/tests/unit/test_rfq_error_codes.py deleted file mode 100644 index bf48b64..0000000 --- a/tests/unit/test_rfq_error_codes.py +++ /dev/null @@ -1,10 +0,0 @@ -from polymarket.rfq import RfqErrorCode - - -def test_balance_and_reservation_rfq_error_codes_are_supported() -> None: - assert RfqErrorCode("ALLOWANCE_VALIDATION_FAILED") is RfqErrorCode.ALLOWANCE_VALIDATION_FAILED - assert RfqErrorCode("BALANCE_VALIDATION_FAILED") is RfqErrorCode.BALANCE_VALIDATION_FAILED - assert ( - RfqErrorCode("PRE_EXECUTION_BALANCE_RESERVATION_FAILED") - is RfqErrorCode.PRE_EXECUTION_BALANCE_RESERVATION_FAILED - )