> 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/websocket-api/market-data/order-book.md).

# Order Book

Real-time streaming order book data

Real-time order books for a specified currency pair and order book variation.

### **Subscribing**

<table data-header-hidden><thead><tr><th width="100">Feed</th><th>Example</th></tr></thead><tbody><tr><td>Feed</td><td><strong><code>orderbook.&#x3C;order_book_type>.&#x3C;basequote></code></strong></td></tr><tr><td>Example</td><td><strong><code>orderbook.net.btcusd</code></strong></td></tr></tbody></table>

```json
// Request -> order book feed
{
    "type": "subscribe", 
    "feeds": ["orderbook.net.btcusd"]
}
```

### Order Book Types

sFOX provides the following order book variations:

<table><thead><tr><th width="100">Order Book</th><th width="430">Description</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>net</code></strong></td><td>Fee-adjusted order book prioritizing the best net prices.</td><td><strong><code>orderbook.net.ethbtc</code></strong></td></tr><tr><td><strong><code>sfox</code></strong></td><td>Unadjusted order book prioritizing the best raw prices. <strong>Please note:</strong> trades on the <code>sfox</code> order book are assessed an additional 10bps fee.</td><td><strong><code>orderbook.sfox.btcusd</code></strong></td></tr></tbody></table>

### **Order Book Message**

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

#### Order Book Object

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

<details>

<summary>Order Book Message</summary>

<pre class="language-json"><code class="lang-json"><strong>// Order book message
</strong><strong>{
</strong>  "sequence": 18,
  "recipient": "orderbook.net.btcusd",
  "timestamp": 1649900198079450163,
  "payload": {
    "bids": [
      [41368.2, 0.3, "b2c2"],
      [41367.742812, 0.001963, "binance"],
      [41367.292857, 0.006878, "binance"],
      [41365.91428571, 0.7, "b2c2"],
      [41362.1, 2, "b2c2"],
      [41361.453441, 0.014505, "binance"],
      [41360.143572, 0.00869, "binance"],
      [41359.8561017, 0.2, "otc17"],
      [41358.613725, 1.20871, "otc19"],
      [41358.103776, 0.04, "binance"],
      [41358.073779, 0.028977, "binance"],
      [41357.873799, 0.012086, "binance"],
      [41357.113875, 1.20871, "otc19"],
      [41356.573929, 0.024173, "binance"],
      [41355.903996, 1.81307, "otc19"],
      [41355.8, 0.5, "otc23"],
      [41355.194067, 2.41733, "otc19"],
      [41353.994187, 0.017737, "binance"],
      [41353.974189, 0.19, "binance"],
      [41352.884298, 6.04332, "otc19"],
      [41352.4, 0.5, "otc23"],
      [41350.024584, 0.145041, "binance"],
      [41348.975, 4, "otc23"],
      [41348.96469, 0.003885, "binance"],
      [41348.17142857, 7, "b2c2"],
      [41346.76491, 0.05, "binance"],
      [41345.5071109, 1, "otc17"],
      [41344.76511, 8.46104, "otc19"],
      [41344.56513, 0.003885, "binance"],
      [41343.915195, 0.146232, "binance"],
      [41341.675419, 0.475, "binance"],
      [41340.77927, 0.39449605, "bitstamp"],
      [41340.615525, 0.035367, "binance"],
      [41339.06013, 0.00723432, "bitstamp"],
      [41338.770275, 0.15077458, "bitstamp"],
      [41338.525734, 12.08665, "otc19"],
      [41338.26053, 1.03596356, "bitstamp"],
      [41335.4205242, 5, "otc17"],
      [41335.272025, 0.12036964, "bitstamp"],
      [41335.06213, 0.13449116, "bitstamp"],
      [41333.60286, 0.12056821, "bitstamp"],
      [41333.516235, 0.241751, "binance"],
      [41333.4, 5, "otc23"],
      [41333.0256, 0.00331432, "kraken"],
      [41332.60336, 0.12087285, "bitstamp"],
      [41331.82375, 0.42, "bitstamp"],
      [41330.386548, 0.012, "binance"],
      [41330.376549, 0.142368, "binance"],
      [41330.306556, 12.08665, "otc19"],
      [41330.114605, 0.16802493, "bitstamp"],
      [41330.0286, 0.60222489, "kraken"],
      [41330.026584, 0.1, "binance"],
      [41328.776709, 0.036344, "binance"],
      [41328.63, 0.70524095, "kraken"],
      [41327.495915, 0.42, "bitstamp"],
      [41327.3313, 0.42197361, "kraken"],
      [41327.276025, 0.12088751, "bitstamp"],
      [41326.2324, 0.1, "kraken"],
      [41326.1325, 0.54830808, "kraken"],
      [41326.0326, 0.24161579, "kraken"],
      [41325.976989, 0.01, "binance"],
      [41325.96699, 0.1716, "binance"],
      [41325.3333, 0.12087016, "kraken"],
      [41325.257035, 1, "bitstamp"],
      [41324.68395, 0.0023, "gemini"],
      [41324.56713, 0.055, "binance"],
      [41324.553564, 1.27, "market1"],
      [41324.4342, 0.64773203, "kraken"],
      [41324.047182, 0.011, "binance"],
      [41324.037183, 0.1, "binance"],
      [41324.027184, 1, "binance"],
      [41323.84774, 0.1571347, "bitstamp"],
      [41323.5351, 3.62613745, "kraken"],
      [41323.34799, 0.42, "bitstamp"],
      [41322.497337, 0.09679, "binance"],
      [41322.484392, 0.01, "market1"],
      [41322.34849, 0.05, "bitstamp"],
      [41322.207366, 0.095, "binance"],
      [41322.157371, 1.007778, "binance"],
      [41321.14909, 0.03705224, "bitstamp"],
      [41321.1073014, 25, "otc17"],
      [41320.2384, 0.67345556, "kraken"],
      [41319.927594, 12.0873, "otc19"],
      [41319.8388, 0.0001, "kraken"],
      [41319.745488, 0.04009981, "market1"],
      [41319.735492, 0.0421593, "market1"],
      [41319.41922, 0.04865, "gemini"],
      [41319.1395, 0.003149, "kraken"],
      [41318.9397, 0.25, "kraken"],
      [41318.9397, 0.635, "gemini"],
      [41318.69032, 0.19340004, "bitstamp"],
      [41318.356044, 1.25, "market1"],
      [41318.31033, 0.02417329, "gemini"],
      [41317.5411, 0.6040736, "kraken"],
      [41317.45094, 0.42, "bitstamp"],
      [41316.52212, 0.0686, "market7"],
      [41315.8, 15, "b2c2"],
      [41314.898097, 3.583457, "binance"],
      [41314.888098, 0.095, "binance"],
      [41314.644, 0.12090144, "kraken"],
      [41314.46814, 0.133897, "binance"],
      [41314.2444, 0.01, "gemini"],
      [41314.16448, 0.42, "gemini"],
      [41313.37298, 0.1941, "bitstamp"],
      [41313.328254, 0.280266, "binance"],
      [41312.5461, 6.04332265, "kraken"],
      [41312.003665, 0.42, "bitstamp"],
      [41311.81683, 0.1274, "market7"],
      [41311.688418, 12.0873, "otc19"],
      [41311.65384, 0.0365641, "bitstamp"],
      [41311.4, 25, "b2c2"],
      [41311.324005, 0.61, "bitstamp"],
      [41311.0476, 0.37887065, "kraken"],
      [41310.7479, 0.2995721, "kraken"],
      [41310.744295, 0.05, "bitstamp"],
      [41310.648, 1, "gemini"],
      [41309.55909, 0.00121092, "gemini"],
      [41309.348652, 0.095, "binance"],
      [41309.21943, 0.04834911, "gemini"],
      [41309.15949, 0.60812, "gemini"]
    ],
    "asks": [
      [41364.5, 0.5, "otc23"],
      [41367.9, 0.5, "otc23"],
      [41371.325, 4, "otc23"],
      [41373.322712, 0.03838193, "market1"],
      [41373.332716, 0.01, "market1"],
      [41374.163048, 0.03712564, "market1"],
      [41374.173052, 0.1, "market1"],
      [41375.1855912, 0.2, "otc17"],
      [41375.39354, 0.1, "market1"],
      [41376.423952, 0.2, "market1"],
      [41377.417328, 1.2087, "otc19"],
      [41377.464368, 0.01, "market1"],
      [41378.317418, 1.20871, "otc19"],
      [41379.417528, 1.81307, "otc19"],
      [41379.427529, 0.01103, "binance"],
      [41379.43753, 0.006888, "binance"],
      [41379.535196, 0.01, "market1"],
      [41380.367623, 0.02579, "binance"],
      [41380.555604, 0.26, "market1"],
      [41381.03769, 0.024176, "binance"],
      [41381.43773, 0.001568, "binance"],
      [41381.857772, 2.41742, "otc19"],
      [41381.897776, 0.012086, "binance"],
      [41382.886536, 0.02943697, "market1"],
      [41384.2189484, 5, "otc17"],
      [41385.648151, 0.04, "binance"],
      [41385.658152, 0.035678, "binance"],
      [41385.728159, 6.04332, "otc19"],
      [41385.8, 0.3, "b2c2"],
      [41386.358222, 0.00869, "binance"],
      [41386.9, 5, "otc23"],
      [41387.2238233, 1, "otc17"],
      [41387.478372, 0.7, "market1"],
      [41387.858372, 0.145044, "binance"],
      [41388.08571429, 0.7, "b2c2"],
      [41388.872938, 0.2047, "market11"],
      [41388.968483, 0.095, "binance"],
      [41388.99898, 0.99, "market1"],
      [41389.1385, 0.05, "binance"],
      [41390.0494, 1.25, "market1"],
      [41390.308617, 0.095, "binance"],
      [41390.89974, 0.13, "market1"],
      [41390.933556, 0.0072, "market11"],
      [41391.188705, 0.000003, "binance"],
      [41391.198706, 0.00077, "binance"],
      [41391.55, 0.07250918, "bitfinex"],
      [41391.673778, 0.039, "market11"],
      [41391.898776, 8.46065, "otc19"],
      [41392.158802, 0.24179, "binance"],
      [41392.2, 2, "b2c2"],
      [41392.708857, 0.018085, "binance"],
      [41394.489035, 0.000545, "binance"],
      [41395.074798, 0.0112, "market11"],
      [41395.129099, 0.0081, "binance"],
      [41395.21484, 0.255, "market11"],
      [41395.63915, 0.001944, "binance"],
      [41395.799166, 0.001572, "binance"],
      [41396.25188, 1.25, "market1"],
      [41396.552, 0.5, "bitfinex"],
      [41397.749361, 0.036018, "binance"],
      [41398.5528, 0.19739821, "bitfinex"],
      [41398.93948, 0.1716, "binance"],
      [41399.5532, 0.00034227, "bitfinex"],
      [41400.089595, 12.08665, "otc19"],
      [41400.5536, 0.55271771, "bitfinex"],
      [41401.233872, 1, "market1"],
      [41401.31667, 0.2421, "market11"],
      [41401.99063, 0.0574, "market7"],
      [41402.180745, 0.12087124, "bitstamp"],
      [41402.5544, 0.61221032, "bitfinex"],
      [41402.919878, 0.000635, "binance"],
      [41403.347279, 0.5076, "market11"],
      [41403.5548, 0.07973682, "bitfinex"],
      [41403.81742, 0.51, "market11"],
      [41404.5552, 0.1662, "bitfinex"],
      [41404.962135, 0.23964408, "bitstamp"],
      [41404.97214, 0.12087406, "bitstamp"],
      [41405.100096, 0.000502, "binance"],
      [41405.5556, 0.38084686, "bitfinex"],
      [41406.02857143, 7, "b2c2"],
      [41406.28492, 0.0131, "market7"],
      [41406.482895, 0.15073263, "bitstamp"],
      [41406.556, 0.03624, "bitfinex"],
      [41406.89553, 0.1386, "market7"],
      [41407.488521, 0.4988, "market11"],
      [41407.74036, 0.1, "binance"],
      [41407.770363, 0.099338, "binance"],
      [41408.310417, 12.08665, "otc19"],
      [41408.5568, 0.060436, "bitfinex"],
      [41409.5572, 0.009672, "bitfinex"],
      [41409.8685, 0.01005354, "gemini"],
      [41410.330619, 0.012075, "binance"],
      [41410.464885, 0.42, "bitstamp"],
      [41410.5576, 0.0011, "bitfinex"],
      [41411.11521, 0.00122, "bitstamp"],
      [41411.125215, 0.0144676, "bitstamp"],
      [41411.1366896, 25, "otc17"],
      [41411.145225, 0.05, "bitstamp"],
      [41411.37, 0.0481, "market7"],
      [41411.445375, 0.1571276, "bitstamp"],
      [41411.558, 1.047576, "bitfinex"],
      [41411.629763, 0.4912, "market11"],
      [41412.5584, 0.39479641, "bitfinex"],
      [41413.15178, 0.0128, "market7"],
      [41413.206255, 0.25653181, "bitstamp"],
      [41413.5588, 0.8926, "bitfinex"],
      [41414.1728, 0.2814, "market7"],
      [41414.346825, 0.03670669, "bitstamp"],
      [41414.391025, 0.001, "binance"],
      [41414.5592, 0.20304, "bitfinex"],
      [41414.606955, 0.42, "bitstamp"],
      [41414.83707, 0.19339577, "bitstamp"],
      [41415.5596, 0.0121, "bitfinex"],
      [41415.771005, 0.4851, "market11"],
      [41415.8745, 2.0260228, "kraken"],
      [41416.25488, 0.2394, "market7"],
      [41416.2749, 3.62582685, "kraken"],
      [41416.311167, 0.0605, "market11"],
      [41416.53516, 0.291, "gemini"],
      [41416.54124, 12.08665, "otc19"]
    ],
    "market_making": {
      "bids": [
        [41345.224109, 1.27, "market1"],
        [41361.46, 0.39449605, "bitstamp"],
        [41366.05, 0.0023, "gemini"],
        [41371.88, 0.001963, "binance"],
        [41374, 0.69001372, "bitfinex"],
        [41374.4, 0.00331432, "kraken"]
      ],
      "asks": [
        [41381.49, 0.12087124, "bitstamp"],
        [41375.29, 0.01103, "binance"],
        [41374.5, 2.0260228, "kraken"],
        [41368.5, 0.01005354, "gemini"],
        [41352.644322, 0.03838193, "market1"]
      ]
    },
    "pair": "btcusd",
    "lastupdated": 1649900198016,
    "lastpublished": 1649900198017
  }
}
</code></pre>

</details>

### Example Code

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

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

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

ws.on('message', function(data) {
    console.log(data);
});

ws.on('open', function() {
  const subscribeMsg = {
    type: 'subscribe',
    feeds: ['orderbook.sfox.ethbtc']
  }
  ws.send(JSON.stringify(subscribeMsg));
});
```

{% endtab %}

{% tab title="Python" %}

```python
import asyncio
import json

import websockets


async def main(uri):
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "type": "subscribe",
            "feeds": [
                "orderbook.sfox.ethbtc",
            ],
        }))
        async for msg in ws:
            print(msg)


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

{% 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/websocket-api/market-data/order-book.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.
