Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/polymarket/rfq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
15 changes: 13 additions & 2 deletions tests/integration/test_rfq.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from polymarket.errors import TransportError, UnexpectedResponseError
from polymarket.rfq import (
RfqConfirmationRequestEvent,
RfqErrorCode,
RfqExecutionStatus,
RfqQuoteRejectedError,
RfqQuoteRequestEvent,
Expand Down Expand Up @@ -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:
Expand All @@ -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",
}
)
Expand All @@ -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


Expand Down
Loading