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

# Orderbook

> How the SX Bet orderbook is structured and how to read it.

## What is the orderbook?

The orderbook is the collection of all active, unfilled orders for a given market. Every order in the book is a maker's open ask to bet on a specific outcome at specific odds.

When you fetch orders from the API, you're reading the live orderbook from the maker's perspective.

```bash theme={null}
curl "https://api.sx.bet/orders?marketHashes={marketHash}"
```

<Note>
  Orders on the SX Bet API are always from the maker's perspective.
</Note>

***

## Reading an order

Each order in the API response contains:

```json theme={null}
{
  "orderHash": "0xc19c8838b4ec0f5b6f51e8a18d6ca9c46c9b7a2e1234567890abcdef12345678",
  "marketHash": "0x6750c579d780a9b04fcda4f3e0428d9e5e0a6b1c2d3e4f5a6b7c8d9e0f1a2b3",
  "maker": "0xE52ed002A3d13e3DB3F5A29F7c98A49B4e5C6D7E",
  "totalBetSize": "50000000",
  "percentageOdds": "51000000000000000000",
  "fillAmount": "0",
  "expiry": 2209006800,
  "apiExpiry": 1772737200,
  "baseToken": "0xe2aa35C25aE3d9f4386d4Df7fE1177A3d044f2e7",
  "executor": "0x8f3Bc9b2E3e98765FAC412e1d0A3B5c6d7e8F9A0",
  "salt": "69837538621348917669822801580188867159099562954597560424559338173619670254332",
  "isMakerBettingOutcomeOne": false,
  "signature": "0x4e8b3f2a1c9d7e6b5a4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b",
  "sportXeventId": "L18148217"
}
```

The critical fields for understanding an order:

<table>
  <thead>
    <tr>
      <th style={{ minWidth: '220px' }}>Field</th>
      <th>What it tells you</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`marketHash`</td>
      <td>The market this order belongs to</td>
    </tr>

    <tr>
      <td>`isMakerBettingOutcomeOne`</td>
      <td>Which side the maker is on (`true` = backing outcome 1, `false` = outcome 2)</td>
    </tr>

    <tr>
      <td>`percentageOdds`</td>
      <td>The maker's implied odds — divide by 10^20 to get a decimal (e.g. 0.51 = 51%)</td>
    </tr>

    <tr>
      <td>`totalBetSize`</td>
      <td>The maker's total stake (USDC, 6 decimals)</td>
    </tr>

    <tr>
      <td>`fillAmount`</td>
      <td>Already filled portion — available = `totalBetSize - fillAmount`</td>
    </tr>
  </tbody>
</table>

***

## Converting Odds to Taker's Perspective

To bet on outcome 1 as a taker, you need to find orders where the maker is betting on outcome 2 — because you're taking the other side.

The `isMakerBettingOutcomeOne` field tells you which side a maker has taken:

| `isMakerBettingOutcomeOne` | Maker is betting on | You can use this order to bet on |
| -------------------------- | ------------------- | -------------------------------- |
| `true`                     | Outcome 1           | **Outcome 2**                    |
| `false`                    | Outcome 2           | **Outcome 1**                    |

Let's take a real market — **Cleveland Cavaliers vs Boston Celtics** (moneyline) — and trace how raw maker orders from the API become the taker orderbook you see on sx.bet.

* Outcome 1 = Cleveland Cavaliers
* Outcome 2 = Boston Celtics

### Step 1: Raw maker orders from `GET /orders`

```bash theme={null}
curl "https://api.sx.bet/orders?marketHashes=0x1a46..."
```

Each row is labeled so you can trace it into the taker orderbook below.

<Tabs>
  <Tab title="Raw API format">
    <div style={{ overflowX: 'auto' }}>
      <table>
        <thead>
          <tr>
            <th />

            <th>maker</th>
            <th>totalBetSize</th>
            <th>percentageOdds</th>
            <th>isMakerBettingOutcomeOne</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td style={{ borderLeft: '3px solid #e74c3c', paddingLeft: '10px', fontWeight: 'bold', color: '#e74c3c' }}>A</td>
            <td><code>0x5B34...eb42</code></td>
            <td>758990000</td>
            <td>42000000000000000000</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #e67e22', paddingLeft: '10px', fontWeight: 'bold', color: '#e67e22' }}>B</td>
            <td><code>0xcFF3...32b</code></td>
            <td>530000000</td>
            <td>46000000000000000000</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #d4a017', paddingLeft: '10px', fontWeight: 'bold', color: '#d4a017' }}>C</td>
            <td><code>0xDFd1...530</code></td>
            <td>4836776618</td>
            <td>46000000000000000000</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #2ecc71', paddingLeft: '10px', fontWeight: 'bold', color: '#2ecc71' }}>D</td>
            <td><code>0x740d...1D84</code></td>
            <td>292187500</td>
            <td>46750000000000000000</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #3498db', paddingLeft: '10px', fontWeight: 'bold', color: '#3498db' }}>E</td>
            <td><code>0xDFd1...530</code></td>
            <td>4616060608</td>
            <td>50000000000000000000</td>
            <td>true</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #9b59b6', paddingLeft: '10px', fontWeight: 'bold', color: '#9b59b6' }}>F</td>
            <td><code>0xcFF3...32b</code></td>
            <td>799000000</td>
            <td>51500000000000000000</td>
            <td>true</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #e91e8a', paddingLeft: '10px', fontWeight: 'bold', color: '#e91e8a' }}>G</td>
            <td><code>0x5B34...eb42</code></td>
            <td>999650000</td>
            <td>52000000000000000000</td>
            <td>true</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #1abc9c', paddingLeft: '10px', fontWeight: 'bold', color: '#1abc9c' }}>H</td>
            <td><code>0xcFF3...32b</code></td>
            <td>752000000</td>
            <td>52000000000000000000</td>
            <td>true</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Tab>

  <Tab title="Readable format">
    <div style={{ overflowX: 'auto' }}>
      <table>
        <thead>
          <tr>
            <th />

            <th>Maker</th>
            <th>Bet Size (USDC)</th>
            <th>Maker Odds</th>
            <th>isMakerBettingOutcomeOne</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td style={{ borderLeft: '3px solid #e74c3c', paddingLeft: '10px', fontWeight: 'bold', color: '#e74c3c' }}>A</td>
            <td><code>0x5B34...eb42</code></td>
            <td>\$758.99</td>
            <td>42.00%</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #e67e22', paddingLeft: '10px', fontWeight: 'bold', color: '#e67e22' }}>B</td>
            <td><code>0xcFF3...32b</code></td>
            <td>\$530.00</td>
            <td>46.00%</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #d4a017', paddingLeft: '10px', fontWeight: 'bold', color: '#d4a017' }}>C</td>
            <td><code>0xDFd1...530</code></td>
            <td>\$4,836.78</td>
            <td>46.00%</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #2ecc71', paddingLeft: '10px', fontWeight: 'bold', color: '#2ecc71' }}>D</td>
            <td><code>0x740d...1D84</code></td>
            <td>\$292.19</td>
            <td>46.75%</td>
            <td>false</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #3498db', paddingLeft: '10px', fontWeight: 'bold', color: '#3498db' }}>E</td>
            <td><code>0xDFd1...530</code></td>
            <td>\$4,616.06</td>
            <td>50.00%</td>
            <td>true</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #9b59b6', paddingLeft: '10px', fontWeight: 'bold', color: '#9b59b6' }}>F</td>
            <td><code>0xcFF3...32b</code></td>
            <td>\$799.00</td>
            <td>51.50%</td>
            <td>true</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #e91e8a', paddingLeft: '10px', fontWeight: 'bold', color: '#e91e8a' }}>G</td>
            <td><code>0x5B34...eb42</code></td>
            <td>\$999.65</td>
            <td>52.00%</td>
            <td>true</td>
          </tr>

          <tr>
            <td style={{ borderLeft: '3px solid #1abc9c', paddingLeft: '10px', fontWeight: 'bold', color: '#1abc9c' }}>H</td>
            <td><code>0xcFF3...32b</code></td>
            <td>\$752.00</td>
            <td>52.00%</td>
            <td>true</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Tab>
</Tabs>

### Step 2: What the taker sees on sx.bet

Those maker orders create the following orderbook for takers.

The taker's price = `1 - (percentageOdds / 10^20)`. Best taker odds are at the top.

<div style={{ display: 'flex', gap: '24px', flexWrap: 'wrap' }}>
  <div style={{ flex: 1, minWidth: '220px' }}>
    <table>
      <thead>
        <tr><th colSpan="3" style={{ textAlign: 'center', fontWeight: 'normal', fontSize: '0.7rem', textTransform: 'uppercase', letterSpacing: '0.05em', color: '#6b7280', paddingBottom: '2px' }}>Outcome 1</th></tr>
        <tr><th colSpan="3" style={{ textAlign: 'center' }}>Cleveland Cavaliers</th></tr>
        <tr><th /><th>Size</th><th>Taker Price</th></tr>
      </thead>

      <tbody>
        <tr>
          <td style={{ borderLeft: '3px solid #2ecc71', paddingLeft: '10px', fontWeight: 'bold', color: '#2ecc71' }}>D</td>
          <td>\$292.19</td>
          <td><strong>53.25¢</strong></td>
        </tr>

        <tr>
          <td style={{ borderLeft: '3px solid #e67e22', paddingLeft: '10px', fontWeight: 'bold', color: '#e67e22' }}>B</td>
          <td>\$530.00</td>
          <td><strong>54.0¢</strong></td>
        </tr>

        <tr>
          <td style={{ borderLeft: '3px solid #d4a017', paddingLeft: '10px', fontWeight: 'bold', color: '#d4a017' }}>C</td>
          <td>\$4,836.78</td>
          <td><strong>54.0¢</strong></td>
        </tr>

        <tr>
          <td style={{ borderLeft: '3px solid #e74c3c', paddingLeft: '10px', fontWeight: 'bold', color: '#e74c3c' }}>A</td>
          <td>\$758.99</td>
          <td><strong>58.0¢</strong></td>
        </tr>
      </tbody>
    </table>
  </div>

  <div style={{ flex: 1, minWidth: '220px' }}>
    <table>
      <thead>
        <tr><th colSpan="3" style={{ textAlign: 'center', fontWeight: 'normal', fontSize: '0.7rem', textTransform: 'uppercase', letterSpacing: '0.05em', color: '#6b7280', paddingBottom: '2px' }}>Outcome 2</th></tr>
        <tr><th colSpan="3" style={{ textAlign: 'center' }}>Boston Celtics</th></tr>
        <tr><th /><th>Size</th><th>Taker Price</th></tr>
      </thead>

      <tbody>
        <tr>
          <td style={{ borderLeft: '3px solid #e91e8a', paddingLeft: '10px', fontWeight: 'bold', color: '#e91e8a' }}>G</td>
          <td>\$999.65</td>
          <td><strong>48.0¢</strong></td>
        </tr>

        <tr>
          <td style={{ borderLeft: '3px solid #1abc9c', paddingLeft: '10px', fontWeight: 'bold', color: '#1abc9c' }}>H</td>
          <td>\$752.00</td>
          <td><strong>48.0¢</strong></td>
        </tr>

        <tr>
          <td style={{ borderLeft: '3px solid #9b59b6', paddingLeft: '10px', fontWeight: 'bold', color: '#9b59b6' }}>F</td>
          <td>\$799.00</td>
          <td><strong>48.5¢</strong></td>
        </tr>

        <tr>
          <td style={{ borderLeft: '3px solid #3498db', paddingLeft: '10px', fontWeight: 'bold', color: '#3498db' }}>E</td>
          <td>\$4,616.06</td>
          <td><strong>50.0¢</strong></td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

***

## Converting Maker Bet Sizes to Available Liquidity

Like `percentageOdds`, `totalBetSize` and `fillAmount` for a given order are from the maker's perspective. To find how much liquidity is available for a taker to fill, you will need to convert the remaining maker space (`totalBetSize - fillAmount`) into taker space.

### The formula

```
remainingTakerSpace = (totalBetSize - fillAmount) * 10^20 / percentageOdds - (totalBetSize - fillAmount)
```

On any given bet, the maker's stake and the taker's stake together form the total payout pool. The maker posts an order at their implied odds (`percentageOdds / 10^20`), so the total pot for any filled amount is `makerStake / makerOdds`. The taker's maximum stake is that total pot minus the maker's stake.

### Example

```json theme={null}
{
  "totalBetSize": "10000000",
  "fillAmount": "4000000",
  "percentageOdds": "52500000000000000000"
}
```

```
remainingTakerSpace = (10000000 - 4000000) * 10^20 / 52500000000000000000 - (10000000 - 4000000)
                    ≈ 5428571  (~5.43 USDC)
```

So while 6.00 USDC of maker stake remains, a taker can fill up to \~5.43 USDC on the other side.

### In code

<CodeGroup>
  ```python Python theme={null}
  ODDS_PRECISION = 10 ** 20
  USDC_DECIMALS = 10 ** 6

  def taker_liquidity(order: dict) -> float:
      remaining_maker = int(order["totalBetSize"]) - int(order["fillAmount"])
      remaining_taker = remaining_maker * ODDS_PRECISION // int(order["percentageOdds"]) - remaining_maker
      return remaining_taker / USDC_DECIMALS

  # Example
  order = {
      "totalBetSize": "10000000",
      "fillAmount": "4000000",
      "percentageOdds": "52500000000000000000",
  }
  print(f"${taker_liquidity(order):.2f} available to fill")  # ~$5.43
  ```

  ```javascript JavaScript theme={null}
  const ODDS_PRECISION = BigInt(10 ** 20);
  const USDC_DECIMALS = 1e6;

  function takerLiquidity(order) {
    const remainingMaker = BigInt(order.totalBetSize) - BigInt(order.fillAmount);
    const remainingTaker = remainingMaker * ODDS_PRECISION / BigInt(order.percentageOdds) - remainingMaker;
    return Number(remainingTaker) / USDC_DECIMALS;
  }

  // Example
  const order = {
    totalBetSize: "10000000",
    fillAmount: "4000000",
    percentageOdds: "52500000000000000000",
  };
  console.log(`$${takerLiquidity(order).toFixed(2)} available to fill`);  // ~$5.43
  ```
</CodeGroup>
