divergence

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Divergence Trading - Spot vs Poly Price Lag

价差交易 - 现货与Polymarket价格滞后策略

Detects when Binance spot prices move but Polymarket 15-minute binary markets haven't caught up yet. Buys the lagging side and sells when it corrects.
Strategy tags match the CLAUDE.md encoding:
BTC_DOWN_s12-14_w15
(0.12-0.14% move in 15s window).
Starts in dry-run mode by default (no real orders).
当Binance现货价格变动,但Polymarket的15分钟二元市场尚未跟上时进行检测。买入滞后的一方,并在价格修正时卖出。
策略标签与CLAUDE.md的编码规则一致:
BTC_DOWN_s12-14_w15
(15秒窗口期内变动0.12-0.14%)。
默认以dry-run模式启动(不会下达真实订单)。

Quick Start

快速开始

/div start                     # Dry-run on BTC,ETH,SOL,XRP
/div start BTC,ETH --size 30   # Specific assets + size
/div status                    # Stats, open positions
/div stop                      # Stop and show summary
/div start                     # 对BTC、ETH、SOL、XRP进行模拟运行
/div start BTC,ETH --size 30   # 指定资产及交易规模
/div status                    # 查看统计数据、未平仓头寸
/div stop                      # 停止运行并显示汇总信息

Commands

命令说明

Start / Stop

启动/停止

/div start [ASSETS] [--size N] [--dry-run]
/div stop
/div start [ASSETS] [--size N] [--dry-run]
/div stop

Monitor

监控

/div status       Stats + open positions + round info
/div positions    Last 20 closed trades with strategy tags
/div markets      Active 15-min markets from Gamma API
/div status       统计数据 + 未平仓头寸 + 周期信息
/div positions    最近20笔平仓交易及策略标签
/div markets      从Gamma API获取的活跃15分钟市场数据

Configure

配置

/div config                           Show current config
/div config --tp 20 --sl 30          Set TP/SL %
/div config --size 50                 Set trade size
/div config --windows 5,10,30         Set detection windows
/div config                           查看当前配置
/div config --tp 20 --sl 30          设置止盈/止损比例
/div config --size 50                 设置交易规模
/div config --windows 5,10,30         设置检测窗口期

Detection Algorithm

检测算法

For each spot tick, across all configured windows (5s, 10s, 15s, 30s, 60s, 90s, 120s):
  1. Look up spot price N seconds ago via binary search
  2. Calculate
    spotMovePct = (now - then) / then * 100
  3. If move >= threshold AND poly is fresh (< 5s stale):
    • Generate signal with strategy tag:
      {ASSET}_{DIR}_s{bucket}_w{window}
    • e.g.,
      BTC_DOWN_s12-14_w15
      = 0.12-0.14% spot drop over 15s
针对每一个现货报价,在所有配置的窗口期(5秒、10秒、15秒、30秒、60秒、90秒、120秒)内执行以下操作:
  1. 通过二分查找获取N秒前的现货价格
  2. 计算
    spotMovePct = (当前价格 - 历史价格) / 历史价格 * 100
  3. 如果价格变动幅度≥阈值且Polymarket数据最新(过期时间<5秒):
    • 生成带有策略标签的信号:
      {ASSET}_{DIR}_s{bucket}_w{window}
    • 示例:
      BTC_DOWN_s12-14_w15
      = 15秒内现货价格下跌0.12-0.14%

Threshold Buckets

阈值区间

BucketSpot Move Range
s08-100.08% - 0.10%
s10-120.10% - 0.12%
s12-140.12% - 0.14%
s14-160.14% - 0.16%
s16-200.16% - 0.20%
s20+0.20%+
区间现货价格变动范围
s08-100.08% - 0.10%
s10-120.10% - 0.12%
s12-140.12% - 0.14%
s14-160.14% - 0.16%
s16-200.16% - 0.20%
s20+0.20%+

Exit Logic

离场逻辑

  1. Force exit — < 30s before market expiry
  2. Take profit — PnL >= 15% (configurable)
  3. Stop loss — PnL <= -25% (configurable)
  4. Trailing stop — Activated at +10%, exits if drops 8% from HWM
  5. Time exit — < 2min before expiry
  1. 强制离场 — 市场到期前30秒内
  2. 止盈离场 — 盈亏比≥15%(可配置)
  3. 止损离场 — 盈亏比≤-25%(可配置)
  4. 追踪止损 — 盈利达到10%时激活,若从最高盈利点回落8%则离场
  5. 时间离场 — 市场到期前2分钟内