OpportunityFinder opportunity

跨预测市场寻找并执行套利机会的工具,关键词:套利、跨平台、预测市场、量化交易。

算法交易 0 次安装 0 次浏览 更新于 3/5/2026

name: opportunity description: “Find and execute cross-platform arbitrage opportunities across prediction markets” emoji: “🎯” gates: envs: anyOf: - POLY_API_KEY - KALSHI_API_KEY

Opportunity Finder - 完整API参考

发现并执行跨预测市场的跨平台套利机会

基于 arXiv:2508.03474 该研究在Polymarket上发现了 $40M+的实现套利

机会类型

类型 描述 示例
内部 是 + 否 < $1 在同一平台上 两个都买保证利润
跨平台 同一市场不同价格 在A上低价买,在B上高价卖
组合 逻辑违规 (P(A) > P(B) 当 A 意味着 B) 特朗普 > 共和党
边缘 市场与外部模型 (538, 民意调查) 市场45%,模型52%

聊天命令

扫描

/opportunities scan                         # 扫描所有平台寻找机会
/opportunities scan "trump"                 # 用关键词过滤扫描
/opportunities scan --min-edge 2            # 最小2%边缘
/opportunities scan --min-liquidity 1000    # 最小$1000流动性

/opportunities active                       # 查看活跃机会
/opportunities active --sort edge           # 按边缘大小排序
/opportunities active --sort liquidity      # 按流动性排序

实时监控

/opportunities realtime start               # 开始连续扫描
/opportunities realtime stop                # 停止扫描
/opportunities realtime status              # 检查监控状态
/opportunities realtime config --interval 30 # 设置扫描间隔(秒)

市场链接

/opportunities link <market-a> <market-b>   # 手动链接等价市场
/opportunities unlink <market-a> <market-b> # 移除链接
/opportunities links                        # 查看所有链接市场
/opportunities auto-match                   # 运行自动匹配算法

执行

/opportunities execute <id>                 # 执行一个机会
/opportunities execute <id> --size 100      # 执行大小为$100
/opportunities mark-taken <id>              # 标记为已取(手动)
/opportunities record-outcome <id> <pnl>    # 记录盈亏结果

分析

/opportunities stats                        # 性能统计
/opportunities stats --period 7d            # 最近7天
/opportunities history                      # 过去的机会
/opportunities by-platform                  # 按平台对统计
/opportunities by-type                      # 按机会类型统计

风险建模

/opportunities risk <id>                    # 建模执行风险
/opportunities estimate <id>                # 估计执行成本
/opportunities kelly <id>                   # 计算凯利分数

TypeScript API参考

创建机会查找器

import { createOpportunityFinder } from 'clodds/opportunity';

const finder = createOpportunityFinder({
  platforms: ['polymarket', 'kalshi', 'betfair', 'manifold'],

  // 过滤
  minEdge: 0.5,           // 最小0.5%边缘
  minLiquidity: 500,      // 最小$500流动性
  minConfidence: 0.7,     // 70%匹配信心

  // 实时
  enableRealtime: true,
  scanIntervalMs: 30000,  // 30秒间隔

  // 凭证
  polymarket: { apiKey, apiSecret, passphrase, privateKey },
  kalshi: { apiKey, privateKey },
});

扫描寻找机会

// 一次性扫描
const opportunities = await finder.scan({
  query: 'election',      // 可选关键词
  minEdge: 1,             // 最小1%边缘
  minLiquidity: 1000,     // 最小$1000流动性
  platforms: ['polymarket', 'kalshi'],
});

for (const opp of opportunities) {
  console.log(`${opp.type}: ${opp.description}`);
  console.log(`  Edge: ${opp.edge.toFixed(2)}%`);
  console.log(`  Liquidity: $${opp.liquidity.toLocaleString()}`);
  console.log(`  Confidence: ${(opp.confidence * 100).toFixed(0)}%`);
  console.log(`  Score: ${opp.score}/100`);
  console.log(`  Platforms: ${opp.platforms.join(' ↔ ')}`);
}

实时监控

// 开始实时扫描
await finder.startRealtime();

// 事件处理程序
finder.on('opportunity', (opp) => {
  console.log(`🎯 新机会: ${opp.description}`);
  console.log(`   Edge: ${opp.edge.toFixed(2)}%`);
});

finder.on('opportunityExpired', (opp) => {
  console.log(`❌ 机会过期: ${opp.id}`);
});

finder.on('opportunityUpdated', (opp) => {
  console.log(`📊 更新: ${opp.id} - 边缘现在是${opp.edge.toFixed(2)}%`);
});

// 获取活跃机会
const active = await finder.getActive();

// 停止监控
await finder.stopRealtime();

市场链接

// 手动链接等价市场
await finder.linkMarkets(
  { platform: 'polymarket', id: 'market-123' },
  { platform: 'kalshi', id: 'TRUMP-WIN' }
);

// 使用语义相似度自动匹配
const matches = await finder.autoMatchMarkets({
  minSimilarity: 0.85,
  platforms: ['polymarket', 'kalshi'],
});

console.log(`找到${matches.length}潜在匹配`);
for (const match of matches) {
  console.log(`${match.marketA.question}`);
  console.log(`  ↔ ${match.marketB.question}`);
  console.log(`  相似度: ${(match.similarity * 100).toFixed(0)}%`);
}

// 获取所有链接
const links = await finder.getLinks();

执行机会

// 执行一个机会
const result = await finder.execute(opportunityId, {
  size: 100,              // $100位置
  maxSlippage: 0.5,       // 最大0.5%滑点
  useProtectedOrders: true,
});

console.log(`执行: ${result.status}`);
console.log(`  成交: $${result.filledSize}`);
console.log(`  平均价格: ${result.avgPrice}`);
console.log(`  费用: $${result.fees}`);

// 手动标记为已取
await finder.markTaken(opportunityId);

// 记录结果
await finder.recordOutcome(opportunityId, {
  pnl: 25.50,
  exitPrice: 0.55,
  exitTimestamp: Date.now(),
});

分析

// 获取统计数据
const stats = await finder.getAnalytics({
  period: '30d',
});

console.log(`总机会: ${stats.total}`);
console.log(`已取: ${stats.taken}`);
console.log(`胜率: ${(stats.winRate * 100).toFixed(1)}%`);
console.log(`总盈亏: $${stats.totalPnl.toLocaleString()}`);
console.log(`平均边缘: ${stats.avgEdge.toFixed(2)}%`);
console.log(`按平台对:`);
for (const [pair, data] of Object.entries(stats.byPlatformPair)) {
  console.log(`  ${pair}: ${data.count} 机会, $${data.pnl} 盈亏`);
}

风险建模

// 建模执行风险
const risk = await finder.modelRisk(opportunityId);

console.log(`执行风险:`);
console.log(`  成交概率: ${(risk.fillProbability * 100).toFixed(0)}%`);
console.log(`  预期滑点: ${risk.expectedSlippage.toFixed(2)}%`);
console.log(`  成交时间: ${risk.estimatedTimeToFill}s`);
console.log(`  对手方风险: ${risk.counterpartyRisk}`);

// 估计执行
const estimate = await finder.estimateExecution(opportunityId, {
  size: 500,
});

console.log(`$500的执行估计:`);
console.log(`  预期成交: $${estimate.expectedFill}`);
console.log(`  预期成本: $${estimate.expectedCost}`);
console.log(`  成本后净边缘: ${estimate.netEdge.toFixed(2)}%`);

机会评分

机会根据以下因素评分0-100:

因素 权重 描述
边缘 % 35% 原始套利价差
流动性 25% 可用交易量
信心 25% 匹配质量
执行 15% 平台可靠性

惩罚

  • 低流动性 (<$1000): -5分
  • 跨平台复杂性: -3分每个平台
  • 高滑点 (>2%): -5分
  • 低信心 (<70%): -5分
  • 接近到期 (<24h): -3分

语义匹配

市场匹配使用:

  1. Exact slug match - 平台特定ID
  2. Text similarity - 杰卡德系数
  3. Vector embeddings - 语义相似度
  4. Manual links - 用户定义
// 配置匹配
finder.setMatchingConfig({
  minTextSimilarity: 0.8,
  minEmbeddingSimilarity: 0.85,
  useManualLinksFirst: true,
});

最佳实践

  1. 从高信心匹配开始 - 85%+相似度
  2. 检查流动性 - 确保足够的交易量执行
  3. 考虑费用 - 包含平台费用
  4. 使用受保护的订单 - 避免滑点
  5. 实时监控 - 机会消失得快
  6. 跟踪结果 - 建立性能历史