套利 arbitrage

自动化跨平台套利检测和监控服务,支持多个预测市场平台,提供实时监控、市场比较、机会查看、市场链接和统计分析等功能。

量化策略 0 次安装 0 次浏览 更新于 3/5/2026

name: 套利 description: “跨平台自动套利检测和监控” emoji: “⚖️” gates: envs: anyOf: - POLY_API_KEY - KALSHI_API_KEY

套利服务 - 完整API参考

自动检测和监控预测市场平台间的套利机会。

支持平台

  • Polymarket
  • Kalshi
  • Manifold
  • Metaculus
  • PredictIt
  • Drift
  • Betfair
  • Smarkets

聊天命令

监控控制

/arb start                                  # 开始套利监控
/arb stop                                   # 停止监控
/arb status                                 # 检查监控状态
/arb config --interval 60                   # 设置检查间隔(秒)

手动扫描

/arb check                                  # 运行一次性扫描
/arb check "election"                       # 带关键词扫描
/arb check --platforms poly,kalshi          # 特定平台

市场比较

/arb compare <market-a> <market-b>          # 比较两个特定市场
/arb compare poly:12345 kalshi:TRUMP        # 通过平台:id

查看机会

/arb opportunities                          # 列出当前机会
/arb opportunities --min-spread 2           # 最小2%的价差
/arb opportunities --format table           # 表格格式
/arb opportunities --format detailed        # 详细视图

市场链接

/arb link <market-a> <market-b>             # 手动链接市场
/arb unlink <market-a> <market-b>           # 移除链接
/arb links                                  # 查看所有链接
/arb auto-match                             # 自动检测匹配

统计

/arb stats                                  # 套利统计
/arb stats --period 7d                      # 最近7天
/arb history                                # 历史机会

TypeScript API参考

创建套利服务

import { createArbitrageService } from 'clodds/arbitrage';

const arbService = createArbitrageService({
  platforms: ['polymarket', 'kalshi', 'manifold', 'betfair'],

  checkIntervalMs: 30000,    // 每30秒检查一次
  minSpread: 0.5,            // 最小0.5%的价差
  minLiquidity: 100,         // 最少$100

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

开始/停止监控

// 开始持续监控
await arbService.start();

// 事件处理器
arbService.on('arbitrage', (opp) => {
  console.log(`⚖️ 套利发现!`);
  console.log(`  ${opp.marketA.platform}: ${opp.marketA.price}`);
  console.log(`  ${opp.marketB.platform}: ${opp.marketB.price}`);
  console.log(`  价差: ${opp.spread.toFixed(2)}%`);
});

arbService.on('arbitrageExpired', (opp) => {
  console.log(`套利过期: ${opp.id}`);
});

// 检查状态
const isRunning = arbService.isRunning();

// 停止监控
await arbService.stop();

一次性检查

// 运行单次扫描
const opportunities = await arbService.checkArbitrage({
  query: 'trump',
  platforms: ['polymarket', 'kalshi'],
  minSpread: 1,
});

for (const opp of opportunities) {
  console.log(`${opp.question}`);
  console.log(`  在 ${opp.buyPlatform} 买入 @ ${opp.buyPrice}`);
  console.log(`  在 ${opp.sellPlatform} 卖出 @ ${opp.sellPrice}`);
  console.log(`  价差: ${opp.spread.toFixed(2)}%`);
}

比较特定市场

// 比较两个特定市场
const comparison = await arbService.compareMarkets(
  { platform: 'polymarket', id: 'market-123' },
  { platform: 'kalshi', id: 'TRUMP-WIN' }
);

if (comparison.hasArbitrage) {
  console.log(`套利存在!`);
  console.log(`  在 ${comparison.buyPlatform} 买入 ${comparison.buySide}`);
  console.log(`  在 ${comparison.sellPlatform} 卖出 ${comparison.sellSide}`);
  console.log(`  价差: ${comparison.spread.toFixed(2)}%`);
} else {
  console.log(`无套利。价格差异: ${comparison.priceDiff.toFixed(2)}%`);
}

市场链接

// 添加手动匹配
await arbService.addMatch(
  { platform: 'polymarket', id: 'market-123', question: 'Will Trump win?' },
  { platform: 'kalshi', id: 'TRUMP-WIN', question: 'Trump wins 2024' }
);

// 移除匹配
await arbService.removeMatch('polymarket:market-123', 'kalshi:TRUMP-WIN');

// 使用问题相似度自动检测匹配
const autoMatches = await arbService.autoMatchMarkets({
  minSimilarity: 0.85,
});

console.log(`发现 ${autoMatches.length} 自动匹配`);

获取机会

// 获取当前机会
const opportunities = await arbService.getOpportunities({
  minSpread: 1,
  sortBy: 'spread',  // 'spread' | 'liquidity' | 'confidence'
});

// 格式化显示
const formatted = await arbService.formatOpportunities(opportunities);
console.log(formatted);

统计

// 获取套利统计
const stats = await arbService.getStats({
  period: '30d',
});

console.log(`总机会数: ${stats.totalOpportunities}`);
console.log(`平均价差: ${stats.avgSpread.toFixed(2)}%`);
console.log(`最大价差: ${stats.maxSpread.toFixed(2)}%`);
console.log(`按平台对:`);
for (const [pair, count] of Object.entries(stats.byPlatformPair)) {
  console.log(`  ${pair}: ${count}`);
}

检测到的套利类型

1. 跨平台价格差异

市场: "Trump wins 2024"
Polymarket YES: 52¢
Kalshi YES: 55¢

策略: 买入Polymarket YES, 卖出Kalshi YES
价差: 3¢ (5.8%)

2. 内部套利(再平衡)

市场: "Will X happen?"
YES: 45¢
NO: 52¢
总计: 97¢

策略: 买入YES和NO
保证利润: 每$1赚3¢

3. 反向市场

市场A: "Trump wins" = 55¢
市场B: "Trump loses" = 48¢
总计: 103¢ (应为100¢)

策略: 卖出两者,赚取3¢

配置

arbService.configure({
  // 扫描
  checkIntervalMs: 30000,
  batchSize: 50,

  // 过滤
  minSpread: 0.5,
  minLiquidity: 100,
  minConfidence: 0.7,

  // 匹配
  autoMatchEnabled: true,
  minMatchSimilarity: 0.85,

  // 警告
  alertOnNewArb: true,
  alertThreshold: 2,  // 2%+价差警告
});

最佳实践

  1. 手动验证匹配 - 自动匹配可能有误报
  2. 检查流动性 - 确保能够实际执行
  3. 考虑费用 - 平台费用减少价差
  4. 快速行动 - 套利很快消失
  5. 使用限价单 - 避免滑点
  6. 跟踪所有结果 - 构建性能数据