Skip to main content

What you'll build

A Python script that pulls historical Polymarket probability data from Kwery, computes simple entry/exit signals based on probability thresholds, and evaluates strategy performance over a historical window.

Prerequisites

  • A Kwery API key (get one here)
  • Python 3.10+
  • requests, pandas, and matplotlib installed

Outline

  1. Fetch market snapshots over time
  2. Build a probability time-series
  3. Define a threshold-based signal
  4. Simulate trades and compute PnL
  5. Visualize results

Step 1 — Fetch historical snapshots

Use GET /v1/snapshots with source=polymarket, symbol=BTC (or your asset), and market_id= set to the market slug or condition id from GET /v1/markets. See Snapshots and OpenAPI.

curl "https://kwery-api.com/v1/snapshots?source=polymarket&symbol=BTC&market_id=YOUR_SLUG_OR_0xCONDITION&limit=100" \
  -H "X-API-Key: YOUR_KEY"

Section coming soon — will include full Python code to paginate and normalize snapshot data.

Step 2 — Build a probability time-series

Parse the snapshot response into a pandas.DataFrame indexed by timestamp, with columns for each outcome's probability.

Section coming soon.

Step 3 — Define entry and exit signals

Apply a simple threshold strategy: buy when probability drops below a configurable floor, sell when it rises above a ceiling.

Section coming soon.

Step 4 — Simulate trades

Walk forward through the time-series, tracking position, entry price, and realized PnL per trade.

Section coming soon.

Step 5 — Visualize results

Plot probability over time with entry/exit markers and a cumulative PnL curve.

Section coming soon.


Next steps

  • Extend the strategy with Kelly criterion position sizing
  • Compare across multiple markets using /v1/markets
  • Add Kalshi data via /v1/kalshi for cross-venue analysis