实时市场数据源来自8个预测市场平台
市场数据 - 完整API参考
实时和历史市场数据来自Polymarket, Kalshi, Manifold, Metaculus, PredictIt, Drift, Betfair和Smarkets。
支持平台
| 平台 | 数据源类型 | 交易 | 数据 |
|---|---|---|---|
| Polymarket | WebSocket + RTDS | 是 | 价格,订单簿,交易 |
| Kalshi | WebSocket | 是 | 价格,订单簿 |
| Betfair | WebSocket | 是 | 赔率,成交量 |
| Smarkets | WebSocket | 是 | 赔率,成交量 |
| Drift | REST | 是 | 价格,资金 |
| Manifold | WebSocket | 只读 | 价格,评论 |
| Metaculus | REST | 只读 | 预测 |
| PredictIt | REST | 只读 | 价格 |
聊天命令
搜索市场
/feed search "trump" # 搜索所有平台
/feed search "election" --platform poly # 搜索特定平台
/feed search "fed rate" --limit 20 # 限制结果
获取价格
/feed price poly <market-id> # 获取当前价格
/feed price kalshi TRUMP-WIN # Kalshi市场
/feed prices "trump" # 所有匹配市场的价格
订单簿
/feed orderbook poly <market-id> # 获取订单簿
/feed orderbook poly <market-id> --depth 10 # 限制深度
订阅(实时)
/feed subscribe poly <market-id> # 订阅价格更新
/feed unsubscribe poly <market-id> # 取消订阅
/feed subscriptions # 列出活跃订阅
新闻
/feed news "trump" # 获取主题新闻
/feed news <market-id> # 特定市场的新闻
/feed news --recent 10 # 最后10条新闻
边缘分析
/feed edge poly <market-id> # 分析模型对比边缘
/feed kelly poly <market-id> --prob 0.55 # 计算凯利分数
TypeScript API参考
创建数据源管理器
import { createFeedManager } from 'clodds/feeds';
const feeds = createFeedManager({
platforms: ['polymarket', 'kalshi', 'manifold', 'betfair'],
// 启用实时
enableRealtime: true,
// 平台凭证(仅限读取时可选)
polymarket: { apiKey },
kalshi: { apiKey },
betfair: { appKey, sessionToken },
});
搜索市场
// 跨所有平台搜索
const results = await feeds.searchMarkets('trump election', {
platforms: ['polymarket', 'kalshi'],
limit: 20,
sortBy: 'volume',
});
for (const market of results) {
console.log(`[${market.platform}] ${market.question}`);
console.log(` 价格:${market.price}`);
console.log(` 成交量:$${market.volume.toLocaleString()}`);
}
获取单个市场
// 获取特定市场
const market = await feeds.getMarket('polymarket', 'market-123');
console.log(`问题:${market.question}`);
console.log(`YES:${market.yesPrice} / NO:${market.noPrice}`);
console.log(`成交量:$${market.volume.toLocaleString()}`);
console.log(`结束日期:${market.endDate}`);
获取价格
// 获取当前价格
const price = await feeds.getPrice('polymarket', 'market-123');
console.log(`YES:${price.yes}`);
console.log(`NO:${price.no}`);
console.log(`价差:${price.spread}`);
console.log(`更新时间:${price.timestamp}`);
获取订单簿
// 获取订单簿
const orderbook = await feeds.getOrderbook('polymarket', 'market-123', {
depth: 10,
});
console.log('买单(YES):');
for (const bid of orderbook.bids) {
console.log(` ${bid.price}: $${bid.size}`);
}
console.log('卖单(YES):');
for (const ask of orderbook.asks) {
console.log(` ${ask.price}: $${ask.size}`);
}
订阅实时更新
// 订阅价格更新
const subscription = await feeds.subscribePrice('polymarket', 'market-123');
subscription.on('price', (update) => {
console.log(`价格更新:YES=${update.yes}, NO=${update.no}`);
});
subscription.on('trade', (trade) => {
console.log(`交易:${trade.side} ${trade.size} @ ${trade.price}`);
});
// 取消订阅
await subscription.unsubscribe();
新闻
// 获取最近新闻
const news = await feeds.getRecentNews('trump', { limit: 10 });
for (const article of news) {
console.log(`[${article.source}] ${article.title}`);
console.log(` ${article.summary}`);
console.log(` ${article.url}`);
}
// 搜索新闻
const searchResults = await feeds.searchNews('federal reserve', {
from: '2024-01-01',
sources: ['reuters', 'bloomberg'],
});
边缘分析
// 分析模型对比边缘
const edge = await feeds.analyzeEdge('polymarket', 'market-123');
console.log(`市场价格:${edge.marketPrice}`);
console.log(`模型估计:`);
for (const model of edge.models) {
console.log(` ${model.name}: ${model.estimate}`);
console.log(` 边缘:${model.edge > 0 ? '+' : ''}${model.edge.toFixed(1)}%`);
}
console.log(`共识边缘:${edge.consensusEdge.toFixed(1)}%`);
凯利准则
// 计算最优仓位大小
const kelly = await feeds.calculateKelly({
platform: 'polymarket',
marketId: 'market-123',
estimatedProbability: 0.55, // 您的估计
bankroll: 10000, // 您的资金
kellyFraction: 0.5, // 安全起见,半凯利
});
console.log(`市场价格:${kelly.marketPrice}`);
console.log(`您的估计:${kelly.estimatedProb}`);
console.log(`边缘:${kelly.edge.toFixed(1)}%`);
console.log(`全凯利:${kelly.fullKelly.toFixed(1)}%`);
console.log(`推荐大小:$${kelly.recommendedSize}`);
平台特定功能
Polymarket RTDS(实时数据服务)
// 连接RTDS以获得超低延迟更新
const rtds = await feeds.connectRTDS('polymarket');
rtds.on('tick', (tick) => {
console.log(`${tick.market}: ${tick.price} (${tick.side})`);
});
rtds.subscribe(['market-123', 'market-456']);
Betfair赔率
// 获取Betfair赔率
const odds = await feeds.getBetfairOdds('event-123');
for (const runner of odds.runners) {
console.log(`${runner.name}: ${runner.backOdds} / ${runner.layOdds}`);
}
Metaculus预测
// 获取Metaculus社区预测
const forecast = await feeds.getMetaculusForecast('question-123');
console.log(`社区中位数:${forecast.median}`);
console.log(`25%分位数:${forecast.q25}`);
console.log(`75%分位数:${forecast.q75}`);
console.log(`预测者数量:${forecast.forecasterCount}`);
数据刷新率
| 平台 | REST | WebSocket |
|---|---|---|
| Polymarket | 5s | 实时 |
| Kalshi | 10s | 实时 |
| Betfair | 1s | 实时 |
| Manifold | 30s | 实时 |
| Metaculus | 60s | N/A |
| PredictIt | 30s | N/A |
最佳实践
- 使用WebSocket 进行实时交易决策
- 缓存响应 用于非时间敏感查询
- 尊重速率限制 - 尽可能批量请求
- 选择性订阅 - 仅订阅您需要的市场
- 处理重新连接 - WebSocket连接可能会断开