> ## Documentation Index
> Fetch the complete documentation index at: https://platform.trendlinelabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a market's order book on one venue

> A market's live L2 book on one venue: YES and NO ladders with at most `depth` levels a side. Prices are 0..1; sizes are in contracts.

**The NO side**

- `no_source: book`: the venue's own NO book, while it is live.
- `no_source: derived`: computed as 1 - YES. Approximate on Polymarket, whose YES and NO are two real books.

**Freshness**

- `ts_ms`: when the book last changed, so a quiet live book can be old.
- `age_ms`: how old the book is now; `max_age_s`: the oldest this venue's book may be before it is refused.

**Errors**

| Status | Code | When |
|---|---|---|
| 422 | `venue_unsupported` | A venue whose books are not served. |
| 404 | `not_found` | Unknown market. |
| 404 | `venue_not_listed` | The market has no leg on that venue. |
| 410 | `market_closed` | The leg no longer trades. |
| 503 | `dependency_unavailable` | Our store is unavailable. |
| 503 | `upstream_unavailable` | No live book, no timestamp, a timestamp in the future, older than the venue's bound, or market data unreadable. |

Any route can also answer 401, 403, 429, 500 or 503 `dependency_unavailable`, described on the Errors page.



## OpenAPI

````yaml /openapi.json get /public/v1/markets/{universal_id}/orderbook
openapi: 3.1.0
info:
  description: >-
    Read-only prediction-market data across Polymarket, Kalshi, Limitless and
    predict.fun over REST. Every request sends your key as `Authorization:
    Bearer tl_live_…`; try any endpoint from its page.
  title: TrendlineLabs Public API
  version: '1'
servers:
  - description: Production
    url: https://systems.trendlinelabs.ai
security: []
tags:
  - description: 'Read back the key you are calling with: its scopes, tier and rate limit.'
    name: Your key
  - description: Events group markets across venues; each carries a `universal_id`.
    name: Events
  - description: One market's order book, price history and trades on one venue.
    name: Markets
  - description: Current prices for a set of markets in one call.
    name: Prices
  - description: Live cross-venue price gaps on the same market.
    name: Opportunities
paths:
  /public/v1/markets/{universal_id}/orderbook:
    get:
      tags:
        - Markets
      summary: Get a market's order book on one venue
      description: >-
        A market's live L2 book on one venue: YES and NO ladders with at most
        `depth` levels a side. Prices are 0..1; sizes are in contracts.


        **The NO side**


        - `no_source: book`: the venue's own NO book, while it is live.

        - `no_source: derived`: computed as 1 - YES. Approximate on Polymarket,
        whose YES and NO are two real books.


        **Freshness**


        - `ts_ms`: when the book last changed, so a quiet live book can be old.

        - `age_ms`: how old the book is now; `max_age_s`: the oldest this
        venue's book may be before it is refused.


        **Errors**


        | Status | Code | When |

        |---|---|---|

        | 422 | `venue_unsupported` | A venue whose books are not served. |

        | 404 | `not_found` | Unknown market. |

        | 404 | `venue_not_listed` | The market has no leg on that venue. |

        | 410 | `market_closed` | The leg no longer trades. |

        | 503 | `dependency_unavailable` | Our store is unavailable. |

        | 503 | `upstream_unavailable` | No live book, no timestamp, a timestamp
        in the future, older than the venue's bound, or market data unreadable.
        |


        Any route can also answer 401, 403, 429, 500 or 503
        `dependency_unavailable`, described on the Errors page.
      operationId: getOrderbook
      parameters:
        - description: >-
            no control, format, private-use, unassigned, line or paragraph
            separator character
          in: path
          name: universal_id
          required: true
          schema:
            description: >-
              no control, format, private-use, unassigned, line or paragraph
              separator character
            maxLength: 256
            minLength: 1
            title: Universal Id
            type: string
        - description: the venue whose book to read
          in: query
          name: venue
          required: true
          schema:
            description: the venue whose book to read
            enum:
              - kalshi
              - polymarket
              - limitless
              - predictfun
            title: Venue
            type: string
        - description: levels per side
          in: query
          name: depth
          required: false
          schema:
            default: 10
            description: levels per side
            maximum: 10
            minimum: 1
            title: Depth
            type: integer
      responses:
        '200':
          content:
            application/json:
              example:
                age_ms: 1500
                as_of_ms: 1791266400000
                max_age_s: 1200
                'no':
                  asks:
                    - price: 0.6
                      size: 150
                  bids:
                    - price: 0.59
                      size: 310
                no_source: book
                ts_ms: 1791266398500
                universal_id: mk-btc-100k-2026
                venue: kalshi
                venue_market_id: KXBTC-26DEC31-B100000
                'yes':
                  asks:
                    - price: 0.41
                      size: 310
                    - price: 0.42
                      size: 90
                  bids:
                    - price: 0.4
                      size: 150
                    - price: 0.39
                      size: 400
              schema:
                $ref: '#/components/schemas/PublicOrderBook'
          description: Successful Response
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: 'unauthorized: no key, or a key that is unknown, revoked or expired.'
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            WWW-Authenticate:
              description: Bearer realm="public-api"
              schema:
                type: string
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: >-
            insufficient_scope: the key lacks the scope this route needs;
            ip_not_allowed: the request came from an address outside the key's
            allowlist; tier_required: the key owner's plan does not include API
            access; access_not_granted: API access is free but granted on
            request; request it on https://trendlinelabs.ai/developer.
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: >-
            not_found: no such event, market or key; venue_not_listed: the
            market has no leg on that venue.
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '410':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: 'market_closed: the market''s leg on that venue no longer trades.'
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: >-
            invalid_request: a parameter is missing, unknown, malformed or out
            of bounds, or a cursor does not match; venue_unsupported: the route
            does not serve that venue.
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: >-
            rate_limited: too many requests, or too many failed authentications;
            wait Retry-After seconds.
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            Retry-After:
              description: seconds to wait before retrying
              schema:
                type: integer
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: >-
            internal_error: an unexpected failure on our side; quote the request
            id. The body may instead be text/plain with no envelope and no
            X-RateLimit-* headers when a failure escapes the route's own
            handling.
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
          description: >-
            dependency_unavailable: one of our own stores could not be read;
            retry later; upstream_unavailable: the data source is unreadable,
            absent or older than its bound; never an empty 200.
          headers:
            Cache-Control:
              description: no-store on every answer
              schema:
                type: string
            X-RateLimit-Limit:
              description: >-
                requests allowed per window for this key; present once the key
                passed the limiter
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: >-
                requests left in this window; present once the key passed the
                limiter
              schema:
                type: integer
            X-RateLimit-Reset:
              description: >-
                seconds until the window resets; present once the key passed the
                limiter
              schema:
                type: integer
            X-Request-Id:
              description: >-
                this request's id (yours, when you sent X-Request-Id); equals
                the envelope's request_id
              schema:
                type: string
      security:
        - HTTPBearer: []
      x-codeSamples:
        - label: cURL
          lang: bash
          source: >
            #!/bin/sh

            # getOrderbook: Get a market's order book on one venue. Needs
            TRENDLINE_API_KEY; TRENDLINE_API_BASE overrides the base.

            curl -sS
            "${TRENDLINE_API_BASE:-https://systems.trendlinelabs.ai}/public/v1/markets/mk-btc-100k-2026/orderbook?venue=kalshi&depth=2"
            \
              -H "Authorization: Bearer $TRENDLINE_API_KEY"
        - label: Python
          lang: python
          source: >
            """getOrderbook: Get a market's order book on one venue. Needs
            TRENDLINE_API_KEY; TRENDLINE_API_BASE overrides the base."""

            import os


            import requests


            BASE = os.environ.get("TRENDLINE_API_BASE",
            "https://systems.trendlinelabs.ai")

            KEY = os.environ["TRENDLINE_API_KEY"]


            r =
            requests.get(f"{BASE}/public/v1/markets/mk-btc-100k-2026/orderbook",
            params={"venue": "kalshi", "depth": "2"},
                             headers={"Authorization": f"Bearer {KEY}"}, timeout=10)
            r.raise_for_status()

            print(r.json())
        - label: JavaScript
          lang: javascript
          source: >
            // getOrderbook: Get a market's order book on one venue. Needs
            TRENDLINE_API_KEY; TRENDLINE_API_BASE overrides the base.

            const BASE = process.env.TRENDLINE_API_BASE ??
            "https://systems.trendlinelabs.ai";

            const KEY = process.env.TRENDLINE_API_KEY;

            const r = await
            fetch(`${BASE}/public/v1/markets/mk-btc-100k-2026/orderbook?venue=kalshi&depth=2`,
            { headers: { Authorization: `Bearer ${KEY}` } });

            console.log(r.status, await r.json());
components:
  schemas:
    PublicOrderBook:
      properties:
        age_ms:
          description: now - ts_ms, floored at 0
          title: Age Ms
          type: integer
        as_of_ms:
          description: when the book was read, unix milliseconds
          title: As Of Ms
          type: integer
        max_age_s:
          description: the age bound applied to this venue
          title: Max Age S
          type: integer
        'no':
          $ref: '#/components/schemas/PublicBookSide'
          description: the NO book
        no_source:
          description: >-
            book: the venue's own NO book; derived: 1 - the YES book,
            approximate on Polymarket, whose YES and NO are two real books
          enum:
            - book
            - derived
          title: No Source
          type: string
        ts_ms:
          description: the YES book's last change, unix ms
          title: Ts Ms
          type: integer
        universal_id:
          description: the market universal id
          title: Universal Id
          type: string
        venue:
          description: the venue this book is from
          enum:
            - kalshi
            - polymarket
            - limitless
            - predictfun
          title: Venue
          type: string
        venue_market_id:
          description: the market's id on this venue
          title: Venue Market Id
          type: string
        'yes':
          $ref: '#/components/schemas/PublicBookSide'
          description: the YES book
      required:
        - universal_id
        - venue
        - venue_market_id
        - 'yes'
        - 'no'
        - no_source
        - ts_ms
        - age_ms
        - max_age_s
        - as_of_ms
      title: PublicOrderBook
      type: object
    PublicError:
      properties:
        error:
          $ref: '#/components/schemas/PublicErrorBody'
          description: the refusal
      required:
        - error
      title: PublicError
      type: object
    PublicBookSide:
      properties:
        asks:
          description: best first, price ascending
          items:
            $ref: '#/components/schemas/PublicBookLevel'
          title: Asks
          type: array
        bids:
          description: best first, price descending
          items:
            $ref: '#/components/schemas/PublicBookLevel'
          title: Bids
          type: array
      required:
        - bids
        - asks
      title: PublicBookSide
      type: object
    PublicErrorBody:
      properties:
        code:
          description: >-
            a machine-readable code from x-known-codes; a new code may be added,
            so handle an unknown one by its status
          title: Code
          type: string
          x-known-codes:
            - access_not_granted
            - dependency_unavailable
            - insufficient_scope
            - internal_error
            - invalid_request
            - ip_not_allowed
            - market_closed
            - not_found
            - rate_limited
            - tier_required
            - unauthorized
            - upstream_unavailable
            - venue_not_listed
            - venue_unsupported
        message:
          description: a human-readable explanation; never parse it
          title: Message
          type: string
        request_id:
          description: >-
            this request's id, also sent as the X-Request-Id header; quote it
            when asking for help
          title: Request Id
          type: string
      required:
        - code
        - message
        - request_id
      title: PublicErrorBody
      type: object
    PublicBookLevel:
      properties:
        price:
          description: 0..1 per YES or NO contract
          title: Price
          type: number
        size:
          description: contracts
          title: Size
          type: number
      required:
        - price
        - size
      title: PublicBookLevel
      type: object
  securitySchemes:
    HTTPBearer:
      description: 'Authorization: Bearer tl_live_…'
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.