# Fetching Orders

> 💡 **Production advice:** run **your own indexer** from chain events. Use our API for development/testing.

### Endpoint

```
GET https://round-snowflake-9c31.devops-118.workers.dev/
```

### Polling & Freshness

* **Refresh every \~30s** (aligns with Odette.fi / Flys.bet cadence).
* Fetch **fresh** orders right before trade execution.
* Orders can expire or be filled between polls.

```ts
const REFRESH_INTERVAL = 30_000;

async function fetchAndUpdateOrders() {
  const res = await fetch('https://round-snowflake-9c31.devops-118.workers.dev/');
  const json = await res.json();
  updateOrdersDisplay(json.data.orders);
  if (json.data.market_data) updateMarketPrices(json.data.market_data);
}

fetchAndUpdateOrders();
setInterval(fetchAndUpdateOrders, REFRESH_INTERVAL);
```

### Response Shape (abridged)

```json
{
  "data": {
    "orders": [
      {
        "order": {
          "maker": "0x...",
          "collateral": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "isCall": true,
          "priceFeed": "0x64c911996D3c6aC71f9b455B1E8E7266BcbD848F",
          "implementation": "0xb727690FDD4Bb0ff74f2f0CC3E68297850A634c5",
          "strikes": [100000000000, 110000000000],
          "expiry": 1734336000,
          "price": "5000000",
          "maxCollateralUsable": "1000000000",
          "isLong": true,
          "orderExpiryTimestamp": 1734336000,
          "numContracts": "0",
          "extraOptionData": "0x"
        },
        "nonce": "12345",
        "signature": "0x...",
        "optionBookAddress": "0x1fcA1052F45A3271F12221D4D990BfED4EE7D0b1"
      }
    ],
    "market_data": { "BTC": 95000.50, "ETH": 3500.25 }
  }
}
```

### Common Filters

```ts
// by strike count
const spreads = orders.filter(o => o.order.strikes.length === 2);
const butterflies = orders.filter(o => o.order.strikes.length === 3);
const condors = orders.filter(o => o.order.strikes.length === 4);

// by asset
const BTC_FEED = '0x64c9...48F';
const btcOrders = orders.filter(o => o.order.priceFeed === BTC_FEED);

// by collateral (USDC)
const USDC = '0x8335...913';
const usdcOrders = orders.filter(o => o.order.collateral.toLowerCase() === USDC.toLowerCase());

// by implementation
const CALL_SPREAD = '0x2Db5...eE3';
const callSpreads = orders.filter(o => o.order.implementation.toLowerCase() === CALL_SPREAD.toLowerCase());
```

### Decimals

| Field                 | Decimals | Example        | Human       |
| --------------------- | -------- | -------------- | ----------- |
| `strikes[]`           | 8        | `100000000000` | `1000`      |
| `price`               | 8        | `5000000`      | `0.05 USDC` |
| `maxCollateralUsable` | 6        | `1000000`      | `1 USDC`    |

```ts
const strike = order.strikes[0] / 1e8;
const price = Number(order.price) / 1e8;
```
