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

# Examples

> Copyable SDK, CLI, and HTTP examples for common market data workflows.

## Choose a workflow

<CardGroup cols={2}>
  <Card title="Find a Polymarket condition" icon="search" href="#find-a-polymarket-condition">
    Resolve a Polymarket slug or URL into condition IDs.
  </Card>

  <Card title="Audit a timestamp range" icon="clock" href="#audit-a-timestamp-range">
    Pull raw records across an inclusive timestamp window with cursor pagination.
  </Card>

  <Card title="Find asset IDs" icon="fingerprint" href="#find-polymarket-asset-ids">
    Extract CLOB token IDs for per-outcome Polymarket orderbook summaries.
  </Card>

  <Card title="Build OHLC quotes" icon="chart-candlestick" href="#build-ohlc-quotes">
    Get best bid, best ask, midpoint, spread, and OHLC candles.
  </Card>

  <Card title="Check data quality" icon="triangle-alert" href="#check-data-quality">
    Validate stored dates and April 2026 known windows before a backtest.
  </Card>
</CardGroup>

## Find a Polymarket condition

<CodeGroup>
  ```python Python SDK theme={null}
  from entityml import EntityMLClient

  client = EntityMLClient()
  result = client.lookup.polymarket_slug(slug="will-bitcoin-hit-100k")

  for market in result["markets"]:
      print(market["question"], market["conditionId"])
  ```

  ```bash CLI theme={null}
  entityml lookup-slug --slug will-bitcoin-hit-100k
  ```

  ```bash Raw HTTP theme={null}
  curl "https://api.entityml.com/api/v1/lookup/slug?slug=will-bitcoin-hit-100k"
  ```
</CodeGroup>

## Find Polymarket asset IDs

Polymarket summaries are per outcome token. First use the condition ID to pull a small raw page, then collect the unique `asset_id` values from the returned events.

<CodeGroup>
  ```python Python SDK theme={null}
  from entityml import EntityMLClient

  client = EntityMLClient(api_key="YOUR_API_KEY")

  page = client.polymarket.get_market_data(
      condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
      date="2026-02-13",
      limit=100,
  )

  asset_ids = sorted({row["asset_id"] for row in page["data"] if row.get("asset_id")})
  print(asset_ids)
  ```

  ```bash CLI + jq theme={null}
  entityml polymarket market-data \
    --condition-id 0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4 \
    --date 2026-02-13 \
    --limit 100 \
    | jq -r '.data[].asset_id' | sort -u
  ```

  ```bash Raw HTTP + jq theme={null}
  curl -H "Authorization: Bearer YOUR_API_KEY" \
    "https://api.entityml.com/api/v1/polymarket/market/data?condition_id=0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4&date=2026-02-13&limit=100" \
    | jq -r '.data[].asset_id' | sort -u
  ```
</CodeGroup>

<Note>
  A binary Polymarket usually has two `asset_id` values. The API does not label which token is which outcome in raw orderbook records, so join against Polymarket market metadata when you need outcome names.
</Note>

## Audit a timestamp range

Range endpoints accept Unix seconds or milliseconds. Use `next_cursor` unchanged while `has_more` is `true`.

<CodeGroup>
  ```python Polymarket SDK theme={null}
  from entityml import EntityMLClient

  client = EntityMLClient(api_key="YOUR_API_KEY")

  cursor = None
  while True:
      page = client.polymarket.get_market_data_range(
          condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
          start_timestamp=1770940800000,
          end_timestamp=1770944400000,
          cursor=cursor,
          limit=1000,
      )
      print(page["data_count"])
      cursor = page["pagination"]["next_cursor"]
      if not cursor:
          break
  ```

  ```python Kalshi SDK theme={null}
  from entityml import EntityMLClient

  client = EntityMLClient(api_key="YOUR_API_KEY")

  page = client.kalshi.get_market_data_range(
      ticker="KXBTC-26FEB2606-B60125",
      start_timestamp=1772103600000,
      end_timestamp=1772107200000,
      limit=1000,
  )
  print(page["data_count"])
  ```

  ```bash CLI theme={null}
  entityml polymarket market-data-range \
    --condition-id 0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4 \
    --start-timestamp 1770940800000 \
    --end-timestamp 1770944400000 \
    --limit 1000
  ```
</CodeGroup>

## Build OHLC quotes

Polymarket orderbook summaries require a condition ID and an `asset_id`. Kalshi summaries require a ticker.

<CodeGroup>
  ```python Polymarket SDK theme={null}
  from entityml import EntityMLClient

  client = EntityMLClient(api_key="YOUR_API_KEY")

  summary = client.polymarket.get_orderbook_summary(
      condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
      asset_id="97684905927345553455494278582909124912046930226695064344571162061840768197777",
      start_timestamp=1770940800000,
      end_timestamp=1770944399999,
      resolution=60,
  )

  first = summary["data"][0]
  print(first["mid_price"], first["mid_price_ohlc"])
  ```

  ```bash Polymarket CLI theme={null}
  entityml polymarket orderbook-summary \
    --condition-id 0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4 \
    --asset-id 97684905927345553455494278582909124912046930226695064344571162061840768197777 \
    --start-timestamp 1770940800000 \
    --end-timestamp 1770944399999 \
    --resolution 60
  ```

  ```python Kalshi SDK theme={null}
  from entityml import EntityMLClient

  client = EntityMLClient(api_key="YOUR_API_KEY")

  summary = client.kalshi.get_orderbook_summary(
      ticker="KXBTC-26FEB2606-B60125",
      start_timestamp=1772103600000,
      end_timestamp=1772107199999,
      resolution=60,
  )

  first = summary["data"][0]
  print(first["best_bid"], first["best_ask"], first["spread_ohlc"])
  ```
</CodeGroup>

## Check data quality

<Steps>
  <Step title="Check stored dates">
    Call `get_market_date_range` for the condition ID or ticker.
  </Step>

  <Step title="Sample raw data">
    Pull a small page from the exact UTC date or timestamp range you need.
  </Step>

  <Step title="Inspect summary buckets">
    Confirm `quote_count`, `is_forward_filled`, and the OHLC fields before using the data in a backtest.
  </Step>
</Steps>

<AccordionGroup>
  <Accordion title="Kalshi April parser window">
    Affected Kalshi records from `2026-03-31` through `2026-04-24` can have null price payloads even when quote counts are nonzero.
  </Accordion>

  <Accordion title="Polymarket April collector gaps">
    Some Polymarket markets have gap-marked or missing data during the April 2026 collector instability window. Inspect `gap_start` and `gap_end` records when auditing this period.
  </Accordion>
</AccordionGroup>

See [Data Quality](/data-quality) for the full incident notes.
