> For the complete documentation index, see [llms.txt](https://docs.sfox.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sfox.com/connect/websocket-api/market-data/users.md).

# Order Book

Real-time order books for a specified currency pair.

### Subscription Instructions

<table><thead><tr><th width="443.5577654976056">Subscription Format</th><th>Example</th></tr></thead><tbody><tr><td><code>orderbook.net.&#x3C;basequote></code></td><td><code>orderbook.net.btcusd</code></td></tr></tbody></table>

### Payload Details

{% hint style="info" %}
Order book subscriptions receive full order book snapshots for the pair. sFOX does not support sending changes at this time.
{% endhint %}

<table><thead><tr><th width="206">Key</th><th>Description</th></tr></thead><tbody><tr><td><code>bids</code></td><td>An array of the bids available in this order book. Each bid is a price, quantity, and liquidity source</td></tr><tr><td><code>asks</code></td><td>An array of the asks available in this order book. Each ask is a price, quantity, and liquidity source</td></tr><tr><td><code>market making</code></td><td>The best bids and offers of the available destinations for maker orders placed on this pair</td></tr><tr><td><code>pair</code></td><td>The currency pair of this order book</td></tr><tr><td><code>lastupdated</code></td><td>The UNIX timestamp this order book was last updated</td></tr><tr><td><code>lastpublished</code></td><td>The UNIX timestamp this order book was last published</td></tr></tbody></table>

### Example Code & Order Book Message

{% tabs %}
{% tab title="NodeJS" %}

```javascript
const WebSocket = require('ws')

const ws = new WebSocket('wss://ws.sfox.com/ws')

ws.on('open', function() {
  const authMessage = {
   type: 'authenticate',
   apiKey: '<ENTERPRISE_API_KEY>',
   enterprise: 'true'
  }
  
  ws.send(JSON.stringify(authMessage))
})

// After successful authentication, subscribe to order book feed
const subscribeMsg = {
  type: 'subscribe',
  feeds: ['orderbook.net.btcusd', 'orderbook.net.ethusd']
}

ws.send(JSON.stringify(subscribeMsg))
```

{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import asyncio
import json
import websockets

async def main(uri):
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "type": "authenticate",
            "apiKey": "<ENTERPRISE_API_KEY>",
            "enterprise": "true"
        }))

        # After successful authentication message, subscribe to the order book feed
        await ws.send(json.dumps({
            "type": "subscribe",
            "feeds": ["orderbook.net.btcusd"]
        }))
        async for msg in ws:
            print(msg)


asyncio.run(main("wss://ws.sfox.com/ws"))
```

{% endcode %}
{% endtab %}

{% tab title="Example Message" %}

<pre class="language-json"><code class="lang-json"><strong>{
</strong>  "sequence": 18,
  "recipient": "orderbook.net.btcusd",
  "timestamp": 1649900198079450163,
  "payload": {
    "bids": [
      [41368.2, 0.3, "market1"],
      [41367.742812, 0.001963, "otc1"],
      [41367.292857, 0.006878, "market2"],
      [41365.91428571, 0.7, "otc2"],
      [41362.1, 2, "market3"],
      [41361.453441, 0.014505, "otc3"]
    ],
    "asks": [
      [41364.5, 0.5, "otc1"],
      [41367.9, 0.5, "market1"],
      [41371.325, 4, "otc2"],
      [41373.322712, 0.03838193, "market2"],
      [41373.332716, 0.01, "otc3"]
    ],
    "market_making": {
      "bids": [
        [41345.224109, 1.27, "market1"],
        [41361.46, 0.39449605, "otc3"],
        [41366.05, 0.0023, "market2"],
        [41371.88, 0.001963, "otc2"],
        [41374, 0.69001372, "market4"],
        [41374.4, 0.00331432, "otc4"]
      ],
      "asks": [
        [41381.49, 0.12087124, "market5"],
        [41375.29, 0.01103, "market7"],
        [41374.5, 2.0260228, "otc3"],
        [41368.5, 0.01005354, "market1"],
        [41352.644322, 0.03838193, "market2"]
      ]
    },
    "pair": "btcusd",
    "lastupdated": 1649900198016,
    "lastpublished": 1649900198017
  }
}
</code></pre>

{% endtab %}
{% endtabs %}


---

# 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://docs.sfox.com/connect/websocket-api/market-data/users.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.
