> For the complete documentation index, see [llms.txt](https://www.aevo.xyz/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.aevo.xyz/docs/api-reference/orderbook-checksum.md).

# Orderbook Checksum

Every orderbook message contains a 32-bit integer checksum (represented as a base-10 string). This checksum is used to compare a client's orderbook state versus the matching engine's orderbook state.

Should these checksums differ between client and server, the Websocket client is encouraged to re-subscribe to the channel to fetch the new orderbook snapshot in order to re-build the orderbook state.

* The preimage of the checksum is generated by concatenating each order's price and size, sorted by their price levels
* Only the **best 100 price levels** are included for purposes of checksumming.
* Format: `<best_bid_price>:<best_bid_size>:<best_ask_price>:<best_ask_size>:<second_best_bid_price>:<second_best_bid_size>:...`

**Example**:

* orderbook: `{ "bids": ["9", "2"]], "asks": [["10", "1"] }`
* resulting concatenation: `9:2:10:1`

```python
// Code Example

import zlib

def checksum(bids, asks):
    preimage = ""
    iterations = max(len(bids), len(asks))

    for index in range(min(iterations, 100)):
        if len(bids) > index:
            price, size = bids[index]
            preimage += price + ":" + size + ":"

        if len(asks) > index:
            price, size = asks[index]
            preimage += price + ":" + size + ":"
    
    preimage = preimage[:-1] # strip last colon
    crc = zlib.crc32(preimage.encode("utf8")) & 0xFFFFFFFF
    return crc

print(checksum([["9", "2"]], [["10", "1"]])) # 1226559413
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.aevo.xyz/docs/api-reference/orderbook-checksum.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
