> ## 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.

# Fetching Odds

> How to fetch current odds and orderbook data for a market.

There are two ways to fetch odds depending on what you need:

| Endpoint                | Use when                                                                             |
| ----------------------- | ------------------------------------------------------------------------------------ |
| `GET /orders`           | You need the full orderbook — all active orders, sizes, and individual order details |
| `GET /orders/odds/best` | You only need the current best price for each outcome                                |

<Note>
  All odds returned by the API are from the **maker's perspective**. To get the taker odds on the opposite outcome, use: `takerOdds = 1 - percentageOdds / 10^20`. For example, if a maker is asking for 51% on outcome 1, a taker gets outcome 2 at 49%.
</Note>

For live updates without polling, both endpoints have a corresponding WebSocket channel — covered in the [Real-time best odds](#real-time-best-odds) and [Real-time orderbook](#real-time-orderbook) sections below. Both assume a connected Centrifugo client; see [Real-time Data → Getting started](/developers/real-time#getting-started) for auth and connection setup.

***

## GET /orders

Use this when you need to inspect full order details — available sizes, fill status, or depth across both sides of a market. You can fetch orders for multiple markets at once, all orders for a specific event, or all orders posted by a specific maker address. See the [full parameter reference →](/api-reference/get-orders).

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

<Note>
  Like the `percentageOdds` value, `totalBetSize` and `fillAmount` are from the maker's perspective. To calculate available taker liquidity, use: `remainingTakerSpace = (totalBetSize - fillAmount) * 10^20 / percentageOdds - (totalBetSize - fillAmount)`
</Note>

***

## GET /orders/odds/best

Use this when you only need the best available price on each side — for example, to check odds before placing a fill (see [Filling Orders](/developers/filling-orders#step-1-find-orders-to-fill)) or to scan for value across a league. Note that this endpoint only returns the best price, not available liquidity at that price. If you need to know how much you can fill at those odds, use `GET /orders` to fetch the full orderbook. See the [full parameter reference →](/api-reference/get-best-odds).

```bash theme={null}
curl "https://api.sx.bet/orders/odds/best?marketHashes=0xbe62...&baseToken=0x6629..."
```

***

## Real-time best odds

Subscribe to [`best_odds:global`](/developers/real-time#channels) for live best-odds updates. Two things are specific to this channel:

* **No server-side history** — recovery is unavailable, so re-seed from REST on every connect (not just failed recovery).
* **Field name differs between REST and WS** — REST returns `outcomeOne`/`outcomeTwo`; WS publications use `isMakerBettingOutcomeOne`. Map between them when seeding state.

Each message is a complete replacement for that market/outcome, not a delta. Because there's no history, messages can also arrive out of order — guard with `updatedAt`.

```javascript theme={null}
const sub = client.newSubscription("best_odds:global");

sub.on("publication", (ctx) => {
  for (const update of ctx.data) {
    const key = `${update.marketHash}:${update.isMakerBettingOutcomeOne}`;
    const existing = state[key];
    if (existing && update.updatedAt <= existing.updatedAt) continue;
    state[key] = update;
  }
});

sub.on("subscribed", async () => {
  const res = await fetch(`https://api.sx.bet/orders/odds/best?marketHashes=${marketHashes.join(",")}&baseToken=${baseToken}`);
  const { data } = await res.json();
  for (const market of data.bestOdds) {
    state[`${market.marketHash}:true`]  = { marketHash: market.marketHash, isMakerBettingOutcomeOne: true,  percentageOdds: market.outcomeOne.percentageOdds, updatedAt: market.outcomeOne.updatedAt };
    state[`${market.marketHash}:false`] = { marketHash: market.marketHash, isMakerBettingOutcomeOne: false, percentageOdds: market.outcomeTwo.percentageOdds, updatedAt: market.outcomeTwo.updatedAt };
  }
});

sub.subscribe();
```

For client setup, see [Real-time Data → Getting started](/developers/real-time#getting-started). Payload reference: [Best Odds →](/api-reference/centrifugo-best-odds).

***

## Real-time orderbook

Subscribe to [`order_book:market_{marketHash}`](/developers/real-time#channels) with `positioned: true, recoverable: true`. Two things are specific to this channel:

* **History is enabled** — Centrifugo replays missed publications on reconnect, so the subscribe-to-fetch race is handled automatically. No manual buffering needed unless you want belt-and-braces.
* **REST seed uses `/orders?marketHashes={hash}`** — fetch only when `wasRecovering && recovered` is false.

```javascript theme={null}
const sub = client.newSubscription(`order_book:market_${marketHash}`, {
  positioned: true,
  recoverable: true,
});

sub.on("publication", (ctx) => applyUpdate(ctx.data));

sub.on("subscribed", async (ctx) => {
  if (ctx.wasRecovering && ctx.recovered) return; // history filled the gap
  const res = await fetch(`https://api.sx.bet/orders?marketHashes=${marketHash}`);
  applySnapshot(await res.json());
});

sub.subscribe();
```

For recovery state interpretation, dedup, and the buffered variant of this pattern, see [Real-time Data → Snapshot + subscribe pattern](/developers/real-time#snapshot--subscribe-pattern). Payload reference: [Order Book Updates →](/api-reference/centrifugo-order-book-updates).

***

## Related

<CardGroup cols={2}>
  <Card title="Real-time Data →" icon="bolt" href="/developers/real-time">
    Full WebSocket guide: auth, connection, recovery, and channel reference.
  </Card>

  <Card title="Filling Orders →" icon="circle-check" href="/developers/filling-orders">
    Use best odds to find orders, then submit a fill.
  </Card>

  <Card title="Best Odds Payload →" icon="code" href="/api-reference/centrifugo-best-odds">
    Field-by-field reference for `best_odds:global` messages.
  </Card>

  <Card title="Order Book Payload →" icon="code" href="/api-reference/centrifugo-order-book-updates">
    Field-by-field reference for `order_book:*` messages.
  </Card>
</CardGroup>
