跳到正文
DEV Community· Khan·· 2 天前AI 評分46

如何用 Python 擷取 Polymarket 與 Kalshi 預測市場即時賠率(無需 API 金鑰)

How to Fetch Live Polymarket & Kalshi Prediction Market Odds in Python (Zero API Keys)

AI 導讀

文章示範透過 Apify 的統一爬蟲,以一次 Python 呼叫取得 Polymarket 和 Kalshi 的即時市場數據,並設定 APIFY_TOKEN。回傳資料包括標準化價格、隱含概率、24 小時成交量、流動性及跨平台市場匹配提示,另提供 REST/cURL 呼叫方式。

正文

Cover image for How to Fetch Live Polymarket & Kalshi Prediction Market Odds in Python (Zero API Keys)

Khan

Tracking prediction markets across Polymarket and Kalshi usually means maintaining two different APIs, normalizing probability formats (0–1 vs cents/bid-ask strings), and manually matching identical questions across venues to spot price spreads.

Here is a clean, proxy-free way to pull normalized live odds, 24h volume, liquidity, and cross-venue spread hints from both exchanges in a single Python call.

1. Install the Client

pip install apify-client
export APIFY_TOKEN="your_apify_token"

2. Fetch Normalized Polymarket & Kalshi Markets

This calls the Polymarket & Kalshi Prediction Markets Unified Scraper directly over HTTP APIs (no headless browser or proxies needed):

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

run = client.actor("api-market/prediction-markets-unified").call(
    run_input={
        "platforms": ["polymarket", "kalshi"],
        "minVolume24h": 1000,
        "maxMarketsPerPlatform": 50,
        "includeCrossMarketMatches": True,
    }
)

items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
print(f"Fetched {len(items)} normalized markets")

for m in items[:5]:
    print(m["platform"], "|", m["question"], "| YES:", m["impliedProbPct"], "%")

3. Or Call It Synchronously via REST / cURL

If you don't want an SDK dependency (or want to plug it into n8n, Make, or an AI agent):

curl -sS -X POST \
  "https://api.apify.com/v2/acts/api-market~prediction-markets-unified/run-sync-get-dataset-items" \
  -H "Authorization: Bearer ${APIFY_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"platforms":["polymarket","kalshi"],"maxMarketsPerPlatform":20,"includeCrossMarketMatches":true}'

Each returned item follows one flat schema (platform, question, yesPrice, noPrice, impliedProbPct, spreadBps, volume24h, liquidity, closeTime, and crossMarketMatch when a similar market exists on the other venue).


More Proxy-Free Data APIs & Examples

I've been building a collection of lightweight, API-first scrapers with Pay-Per-Event pricing and ready-to-run Python/Node/cURL examples in github.com/wOkk93/apify-data-actors:

Full catalog: apify.com/api-market — feedback and schema suggestions welcome!

來源:DEV Community · dev.to