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

# Get Order Book Events

> Get the L2 snapshots and price changes needed to reconstruct an outcome token's order book over time.

Use this endpoint to pull the L2 events for one or more outcome tokens. Each event is either a `book` snapshot (full `bids` and `asks`) or a `price_change` delta (a single `side`, `price`, and `sizeAfter`).

Provide at least one of `marketId`, `conditionId`, or `tokenId`. The API combines values in the same parameter with OR. It combines different parameters with AND.

## Reconstructing a book

To rebuild a token's book at a target time:

1. For one `tokenId`, fetch the latest `book` at or before the target time with `eventType=book`, `to=<target_time>`, `order=desc`, and `limit=1`.
2. Start a new query from that event's `cursor`. Set `eventType=price_change`, keep `to=<target_time>`, and use `order=asc`.
3. Page through the results with the same filters and `order`, passing each `nextCursor` into the next request.
4. Apply `BUY` deltas to bids and `SELL` deltas to asks. A `sizeAfter` value of `0` removes the price level. Any other value replaces its size.

You need a `book` snapshot to start reconstruction. If none exists at or before the target time, the later price changes are not enough to rebuild the book.

<Note>
  Events use **Unix milliseconds**. Other API endpoints use seconds. Subtract `timestamp` from `indexedTimestamp` to estimate total indexing latency, including WebSocket delivery, queueing, batching, and insertion. Historical rows created before `timestamp_ingested` do not have a reliable original ingestion timestamp.
</Note>

<Warning>
  Cursors are opaque. Keep the filters and `order` unchanged while paging through one result set. When reconstructing a book, you can use the snapshot cursor to start the new ascending `price_change` query described above.
</Warning>


## OpenAPI

````yaml openapi.json GET /v1/orderbook/events
openapi: 3.1.0
info:
  title: Orbscan Open API
  description: >-
    REST endpoints for Polymarket wallet activity, positions, transfers,
    transaction details, and L2 order book data.
  version: 1.0.0
servers:
  - url: https://api.orbscan.com
    description: Production
security:
  - bearerAuth: []
paths:
  /v1/orderbook/events:
    get:
      summary: Get order book events
      description: >-
        Returns the stored L2 events needed to reconstruct an outcome token's
        order book. Provide at least one of `marketId`, `conditionId`, or
        `tokenId`. The API combines values in the same parameter with OR and
        different parameters with AND.
      operationId: getOrderBookEvents
      parameters:
        - name: marketId
          in: query
          required: false
          description: >-
            Market IDs to include. You can provide up to 20 as comma-separated
            values, repeated parameters, or both.
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
            maxItems: 20
            example:
              - '12345'
        - name: conditionId
          in: query
          required: false
          description: >-
            Condition IDs to include. You can provide up to 20 as
            comma-separated values, repeated parameters, or both. Input is
            case-insensitive.
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
            maxItems: 20
            example:
              - >-
                0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
        - name: tokenId
          in: query
          required: false
          description: >-
            Outcome token IDs to include. You can provide up to 50 as
            comma-separated values, repeated parameters, or both.
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
            maxItems: 50
            example:
              - '123456789'
        - name: eventType
          in: query
          required: false
          description: >-
            Event types to include: `book`, `price_change`, or both. The
            endpoint returns both when you omit this parameter.
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
              enum:
                - book
                - price_change
            maxItems: 2
        - name: from
          in: query
          required: false
          description: Inclusive lower bound on source time, Unix milliseconds.
          schema:
            type: integer
            format: int64
            example: 1788852000000
        - name: to
          in: query
          required: false
          description: >-
            Inclusive upper bound on source time, Unix milliseconds. Must be
            greater than or equal to `from`.
          schema:
            type: integer
            format: int64
        - name: order
          in: query
          required: false
          description: Sort by source time. Defaults to `asc`. Case-insensitive.
          schema:
            type: string
            enum:
              - asc
              - desc
            default: asc
        - name: limit
          in: query
          required: false
          description: >-
            Page size. Defaults to 1,000. Values outside 1 to 10,000 return
            `400`.
          schema:
            type: integer
            default: 1000
            minimum: 1
            maximum: 10000
        - name: cursor
          in: query
          required: false
          description: >-
            Opaque cursor from the last item's `cursor` or the response's
            `nextCursor`. Keep the filters and `order` unchanged while paging
            one result set. To reconstruct a book, you can use a snapshot cursor
            to start a new ascending `price_change` query.
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: OK
                  status_code:
                    type: string
                    example: '1'
                  data:
                    type: object
                    properties:
                      items:
                        type: array
                        items:
                          $ref: '#/components/schemas/OrderBookEvent'
                      nextCursor:
                        type: string
                        nullable: true
              example:
                message: OK
                status_code: '1'
                data:
                  items:
                    - cursor: AAABoMfIdTSZ95XfHI2JY3xDPBEiM-NgpOm-DblE2HiRi5Ny98xn0g
                      marketId: '573656'
                      conditionId: >-
                        0x02deb9538f5c123373adaa4ee6217b01745f1662bc902e46ac92f3fe6f8741e8
                      tokenId: >-
                        93694900555669388759405753550770573998169287228984912881955464376232163096213
                      outcome: 'Yes'
                      eventType: book
                      timestamp: 1790058198324
                      indexedTimestamp: 1790058204527
                      side: null
                      price: null
                      sizeAfter: null
                      bids:
                        - - '0.48'
                          - '12500'
                        - - '0.47'
                          - '20000'
                      asks:
                        - - '0.49'
                          - '8000'
                        - - '0.5'
                          - '15000'
                      sourceHash: db60d216be1f61bfe63c4c9a92a2d42fd30e319c
                    - cursor: AAABoIUSUAm3qt444MRDsUeszsPPlC2V4ijGB4PrCvlQPcNHl9XYGg
                      marketId: '573656'
                      conditionId: >-
                        0x02deb9538f5c123373adaa4ee6217b01745f1662bc902e46ac92f3fe6f8741e8
                      tokenId: >-
                        93694900555669388759405753550770573998169287228984912881955464376232163096213
                      outcome: 'Yes'
                      eventType: price_change
                      timestamp: 1788938965001
                      indexedTimestamp: 1788938967881
                      side: SELL
                      price: '0.79'
                      sizeAfter: '6'
                      bids: null
                      asks: null
                      sourceHash: 7bbd3aff3cc9a5b22c69a6a4f3c2ce8c2fb4b6ab
                  nextCursor: null
        '400':
          description: >-
            A filter, `eventType`, `order`, `limit`, timestamp, or time range is
            invalid; or no `marketId`, `conditionId`, or `tokenId` was supplied.
          content:
            application/json:
              example:
                message: tokenId, marketId, or conditionId is required
                status_code: '0'
                data: null
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/ServerError'
components:
  schemas:
    OrderBookEvent:
      type: object
      properties:
        cursor:
          type: string
          description: >-
            Stable opaque boundary for this logical event; pass it back as the
            `cursor` query parameter.
        marketId:
          type: string
          description: Gamma market ID.
        conditionId:
          type: string
          description: Condition ID.
        tokenId:
          type: string
          description: Outcome token whose independent book changed.
        outcome:
          type: string
          nullable: true
          description: Outcome label resolved from metadata.
        eventType:
          type: string
          enum:
            - book
            - price_change
          description: Event type.
        timestamp:
          type: integer
          format: int64
          description: Polymarket source time, Unix milliseconds.
        indexedTimestamp:
          type: integer
          format: int64
          description: >-
            Earliest ingestion time for the logical event, in Unix milliseconds.
            Subtract `timestamp` from this value to estimate total indexing
            latency.
        side:
          type: string
          nullable: true
          description: Source side, normally `BUY` or `SELL`. Set only for `price_change`.
        price:
          type: string
          nullable: true
          description: Price on a 0 to 1 scale. Set only for `price_change`.
        sizeAfter:
          type: string
          nullable: true
          description: >-
            Remaining size after the update; `0` removes the level, any other
            value replaces the level size. Set only for `price_change`.
        bids:
          type: array
          nullable: true
          description: >-
            Bid levels as `[price, size]` decimal-string pairs. Set only for
            `book`.
          items:
            type: array
            minItems: 2
            maxItems: 2
            items:
              type: string
        asks:
          type: array
          nullable: true
          description: >-
            Ask levels as `[price, size]` decimal-string pairs. Set only for
            `book`.
          items:
            type: array
            minItems: 2
            maxItems: 2
            items:
              type: string
        sourceHash:
          type: string
          nullable: true
          description: Hash supplied by Polymarket for integrity checks.
  responses:
    Unauthorized:
      description: The API key is missing or invalid.
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                example: Missing or invalid API key
              status_code:
                type: string
                example: '0'
              data:
                type: 'null'
          example:
            message: Missing or invalid API key
            status_code: '0'
            data: null
    Forbidden:
      description: The API key is valid but not allowed to use this resource.
    TooManyRequests:
      description: The rate limit for your credential was exceeded.
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                example: Rate limit exceeded
              status_code:
                type: string
                example: '0'
              data:
                type: 'null'
          example:
            message: Rate limit exceeded
            status_code: '0'
            data: null
    ServerError:
      description: Unexpected server failure.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Paste your Orbscan API key here. The `Bearer` prefix is added
        automatically.

````