Skip to content

docs: document OrderBook.bids/asks sort convention #42

@Nexory

Description

@Nexory

The OrderBook model in src/polymarket/models/clob/order_book.py defines bids and asks as tuple[OrderBookLevel, ...] but does not document the sort order returned by the CLOB API.

The convention is non-obvious — _calculate_buy_market_price in src/polymarket/_internal/actions/orders/estimate.py:139 walks reversed(asks) starting from the cheapest level, which implies asks are returned highest-price-first. Similarly bids in _calculate_sell_market_price are reversed to walk from highest, implying bids are returned lowest-price-first.

This is non-obvious for new users and easy to get wrong when writing custom orderbook-walking logic outside the provided estimate_market_price helper.

Suggested change: Add field docstrings on OrderBook.bids and OrderBook.asks noting the sort order:

bids: tuple[OrderBookLevel, ...]
"""Returned by the CLOB API in ascending price order (lowest bid first)."""
asks: tuple[OrderBookLevel, ...]
"""Returned by the CLOB API in descending price order (highest ask first)."""

Happy to send a small docs PR if welcome.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions