5 分钟完成设置

快速入门

5 分钟内上手 PolyTest API。完成认证、获取市场、拉取快照,并可以直接在这里试用实时示例。

1
2
3
第 1 步

认证

开始 3 天免费试用,并在控制台中生成 API 密钥。所有请求都通过 X-API-Key 请求头进行认证。

你的 API 密钥
获取密钥
你的密钥只用于从此浏览器发出的实时请求,永远不会被存储或发送到我们的服务器。
密钥轮换:我们建议每 90 天轮换一次 API 密钥。
// npm install @polytest/sdk
// export POLYTEST_KEY="pt_live_your_key_here"
import { polytest } from "@polytest/sdk"

const api = polytest() // reads POLYTEST_KEY
const limits = await api.limits()
console.log(limits.tier) // "builder"
第 2 步

获取市场

查询所有可用的预测市场。可按币种(BTC、ETH、SOL,XRP、DOGE 和 BNB 即将推出)和市场时间周期过滤。返回分页结果,最新的在前。

import { polytest } from "@polytest/sdk"

const api = polytest()
const page = await api.markets({ market_type: "5m", coin: "btc", limit: 3 })
console.log(page.total)
for (const market of page.items) console.log(market.slug, market.winner)
第 3 步

获取快照

获取任意市场的历史价格快照。每条快照包括资产价格、Up/Down 结果概率和可选的订单簿深度。快照每秒采集 8 次。

import { polytest } from "@polytest/sdk"

const api = polytest()
const markets = await api.markets({ market_type: "5m", coin: "btc", limit: 10 })
// The newest market may still be running, so take the first resolved one
const market = markets.items.find((m) => m.winner !== null)
if (!market) throw new Error("No resolved market on this page")
const page = await api.snapshots(market.market_id, { limit: 5 })
for (const shot of page.items) {
  console.log(shot.time, shot.price_up, shot.price_down)
}