polymarket-trading

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Terminology & Concepts

术语与概念

  • Exit Plan: Automated limit sell at $0.99 placed as soon as position opens.
  • Hedged Reversal: Holding both UP and DOWN positions simultaneously when trend flips.
  • Midpoint Stop Loss: Market sell triggered by midpoint price dropping to/below $0.30.
  • Scale-In: Adding capital to winning positions via Market Orders (FAK).
  • Underdog: Side trading below $0.50. Requires >40% confidence for entry.
  • Tick Size: Minimum price increment allowed for a market (e.g., 0.01 or 0.001).
  • 退出计划(Exit Plan):建仓后立即挂出0.99美元的自动限价卖出订单。
  • 对冲反转(Hedged Reversal):当趋势反转时,同时持有看涨(UP)和看跌(DOWN)头寸。
  • 中点止损(Midpoint Stop Loss):当中点价格跌至0.30美元或以下时触发市价卖出。
  • 逐步加仓(Scale-In):通过FAK市价订单向盈利头寸追加资金。
  • 弱势方(Underdog):交易价格低于0.50美元的一方,入场需具备40%以上的信心。
  • 最小价格变动单位(Tick Size):市场允许的最小价格增量(例如0.01或0.001)。

Strategy Nuances

策略细节

Confidence Calculation Methods (v0.5.0+)

信心度计算方法(v0.5.0及以上版本)

The bot supports two confidence calculation methods for A/B testing:
Additive Method (Default):
  • Directional voting system with weighted signal aggregation
  • Confidence = (winning_total - (losing_total × 0.2)) × lead_lag_bonus
  • Trend agreement bonus (1.1x) when Binance and Polymarket momentum align
Bayesian Method (Alternative):
  • Statistically principled probability theory using log-odds
  • Starts with market prior from Polymarket orderbook
  • Accumulates evidence via log-likelihood ratios:
    python
    evidence = (score - 0.5) × 2  # Scale to -1 to +1
    log_LR = evidence × 3.0 × quality  # Quality factor (0.7-1.5x)
    log_odds += log_LR × weight
    confidence = 1 / (1 + exp(-log_odds))
  • Naturally handles conflicting signals (they cancel out)
  • Market prior anchors calculation to Polymarket reality
A/B Testing:
  • Both methods calculated simultaneously on every trade
  • Results stored in database for comparison
  • Toggle via
    BAYESIAN_CONFIDENCE
    environment variable (default: NO)
  • Compare win rates after 100+ trades:
    sql
    SELECT
        AVG(CASE WHEN bias='UP' THEN edge ELSE -edge END) as avg_edge,
        COUNT(*) as total,
        SUM(CASE WHEN result='WIN' THEN 1 ELSE 0 END) as wins,
        CAST(wins AS REAL) / COUNT(*) as win_rate
    FROM trades
    WHERE settled = 1
    GROUP BY method;
该交易机器人支持两种信心度计算方法用于A/B测试:
累加方法(默认):
  • 带加权信号聚合的方向性投票系统
  • 信心度 = (盈利信号总数 - (亏损信号总数 × 0.2)) × 领先滞后奖励系数
  • 当Binance与Polymarket趋势一致时,获得1.1倍的趋势一致奖励
贝叶斯方法(备选):
  • 基于统计原理的对数概率理论
  • 以Polymarket订单簿的市场先验数据为基础
  • 通过对数似然比累积证据:
    python
    evidence = (score - 0.5) × 2  # Scale to -1 to +1
    log_LR = evidence × 3.0 × quality  # Quality factor (0.7-1.5x)
    log_odds += log_LR × weight
    confidence = 1 / (1 + exp(-log_odds))
  • 可自然处理相互矛盾的信号(信号会相互抵消)
  • 市场先验数据确保计算贴合Polymarket实际情况
A/B测试:
  • 每笔交易同时使用两种方法计算
  • 结果存储在数据库中用于对比
  • 通过
    BAYESIAN_CONFIDENCE
    环境变量切换(默认值:NO)
  • 交易100笔以上后对比胜率:
    sql
    SELECT
        AVG(CASE WHEN bias='UP' THEN edge ELSE -edge END) as avg_edge,
        COUNT(*) as total,
        SUM(CASE WHEN result='WIN' THEN 1 ELSE 0 END) as wins,
        CAST(wins AS REAL) / COUNT(*) as win_rate
    FROM trades
    WHERE settled = 1
    GROUP BY method;

Exit Plan Optimization

退出计划优化

  • Smart Exit Pricing:
    • High confidence trades (≥85%): Use $0.999 exit price for maximum profit
    • Standard trades: Use $0.99 exit price (configurable via EXIT_PRICE_TARGET)
    • Only apply 0.999 for winning positions (UP side with price ≥ entry OR DOWN side with price ≤ entry)
  • Immediate Placement: Exit plans placed immediately after position fill (no age requirement)
  • Real-Time Size Validation: Exit order size validated every 1-second cycle
  • Repair Logic:
    • Automatic repair if exit order size mismatches database size
    • Uses 0.05 share threshold to prevent infinite repair loops from exchange rounding
    • Cancels incorrect order and places new one with correct size
  • Adoption Logic: Discovers and adopts existing SELL orders on exchange to prevent duplicates
  • 智能退出定价
    • 高信心度交易(≥85%):使用0.999美元的退出价格以获取最大利润
    • 标准交易:使用0.99美元的退出价格(可通过EXIT_PRICE_TARGET配置)
    • 仅对盈利头寸使用0.999美元的价格(看涨头寸价格≥入场价,或看跌头寸价格≤入场价)
  • 立即挂单:建仓完成后立即挂出退出计划(无时间要求)
  • 实时规模验证:每1秒验证一次退出订单的规模
  • 修复逻辑
    • 若退出订单规模与数据库记录不符,自动修复
    • 使用0.05份额的阈值,避免因交易所四舍五入导致无限修复循环
    • 取消错误订单并挂出规模正确的新订单
  • 适配逻辑:识别并复用交易所已有的卖出订单,避免重复挂单

Scale-In Strategy (Dynamic)

动态逐步加仓策略

  • Default
    SCALE_IN_TIME_LEFT
    : 450s (7.5 minutes)
  • Dynamic early entry timing based on confidence (
    edge
    ) and midpoint price:
    • 12m left:
      edge
      >= 90% and price >= $0.80
    • 9m left:
      edge
      >= 80% and price >= $0.70
    • 7m left:
      edge
      >= 70% and price >= $0.65
  • Uses Market Orders (FAK) to ensure immediate fills
  • Multiplier: 1.5x (adds 150% more capital, creating 2.5x total position)
  • 默认
    SCALE_IN_TIME_LEFT
    :450秒(7.5分钟)
  • 根据信心度(
    edge
    )和中点价格动态调整提前入场时机:
    • 剩余12分钟:
      edge
      ≥90%且价格≥0.80美元
    • 剩余9分钟:
      edge
      ≥80%且价格≥0.70美元
    • 剩余7分钟:
      edge
      ≥70%且价格≥0.65美元
  • 使用FAK市价订单确保立即成交
  • 乘数:1.5倍(追加150%的资金,总头寸达到2.5倍)

Signal Bonuses

信号奖励

  • Trend Agreement Bonus: 1.1x multiplier if Binance and Polymarket trends align
  • Lead/Lag Bonus: 1.2x bonus or 0.8x penalty based on cross-exchange consistency
  • 趋势一致奖励:若Binance与Polymarket趋势一致,奖励乘数为1.1倍
  • 领先/滞后奖励:根据跨交易所一致性,给予1.2倍奖励或0.8倍惩罚

Technical Requirements

技术要求

  • Precision: Use strict 0.0001 threshold for balance syncing
  • Minimum Size: Polymarket enforces a 5.0 share minimum for limit orders
  • Rounding: Use
    truncate_float(value, 2)
    for all order sizes to match exchange precision
  • 精度:余额同步使用严格的0.0001阈值
  • 最小规模:Polymarket对限价订单强制要求5.0份额的最低规模
  • 四舍五入:所有订单规模使用
    truncate_float(value, 2)
    函数,以匹配交易所精度

Fees & Rebates (15-Minute Crypto Markets)

手续费与返利(15分钟加密货币市场)

  • Taker Fees: Applied ONLY to 15-minute crypto markets.
  • Fee Deduction:
    • BUY: Fee is taken in Tokens from the proceeds.
    • SELL: Fee is taken in USDC from the proceeds.
  • Effective Rates:
    • Buying: Peaks at ~1.6% at $0.50 price.
    • Selling: Peaks at ~3.7% at $0.30 price. Selling is generally more expensive because USDC is taken directly.
  • Fee Precision: Rounded to 4 decimal places (min 0.0001 USDC). Small trades at extremes might be fee-free.
  • Maker Rebates: Distributed daily in USDC to makers who provide liquidity that gets filled.
  • Strategy Implications:
    • Prefer Maker orders (Limit orders that add liquidity) to avoid fees and potentially earn rebates.
    • Selling at low prices as a taker is particularly costly.
  • 吃单手续费:仅适用于15分钟加密货币市场。
  • 手续费扣除
    • 买入:手续费从交易所得的代币中扣除。
    • 卖出:手续费从交易所得的USDC中扣除。
  • 实际费率
    • 买入:在价格为0.50美元时,费率峰值约为1.6%。
    • 卖出:在价格为0.30美元时,费率峰值约为3.7%。由于直接扣除USDC,卖出通常成本更高。
  • 手续费精度:四舍五入至4位小数(最低0.0001 USDC)。极端情况下的小额交易可能免手续费。
  • 挂单返利:每日向提供流动性且订单成交的挂单者发放USDC返利。
  • 策略启示
    • 优先选择挂单订单(Maker orders)(增加流动性的限价订单),以避免手续费并可能获得返利。
    • 作为吃单者在低价卖出成本尤其高昂。

Common Code Patterns

常见代码模式

Market Data

市场数据

python
from src.trading.orders import get_midpoint, get_spread, check_liquidity
python
from src.trading.orders import get_midpoint, get_spread, check_liquidity

Get accurate midpoint price

Get accurate midpoint price

price = get_midpoint(token_id)
price = get_midpoint(token_id)

Check if liquidity is good

Check if liquidity is good

if check_liquidity(token_id, size=100, warn_threshold=0.05): # Safe to trade
undefined
if check_liquidity(token_id, size=100, warn_threshold=0.05): # Safe to trade
undefined

Order Placement

订单挂单

python
from src.trading.orders import place_batch_orders, place_market_order
python
from src.trading.orders import place_batch_orders, place_market_order

Batch Orders

Batch Orders

results = place_batch_orders(orders)
results = place_batch_orders(orders)

Market Sell

Market Sell

result = place_market_order(token_id, amount=10.0, side="SELL", order_type="FAK")
undefined
result = place_market_order(token_id, amount=10.0, side="SELL", order_type="FAK")
undefined

Standard Emoji Guide

标准表情符号指南

Position Monitoring

头寸监控

  • 👀 Monitoring positions
  • 📈 UP side position (winning if PnL positive)
  • 📉 DOWN side position (winning if PnL positive)
  • 📦 Position size display
  • 🧮 PnL percentage display
  • 👀 监控头寸
  • 📈 看涨(UP)头寸(盈利为正则获利)
  • 📉 看跌(DOWN)头寸(盈利为正则获利)
  • 📦 头寸规模显示
  • 🧮 盈亏(PnL)百分比显示

Position Status

头寸状态

  • ⏰ Exit plan active (limit sell order placed)
  • ⏳ Exit plan pending (waiting for conditions)
  • ⏭️ Exit skipped (position below MIN_SIZE threshold)
  • 📊 Scaled in position indicator
  • ⏰ 退出计划已激活(已挂出限价卖出订单)
  • ⏳ 退出计划待处理(等待条件满足)
  • ⏭️ 跳过退出(头寸低于MIN_SIZE阈值)
  • 📊 已加仓头寸标识

Order Lifecycle

订单生命周期

  • 🚀 Trade execution / Entry
  • 🎯 Limit order placement
  • ✅ Success / Order filled
  • 🧹 Order cancellation
  • ❌ Error/Failure
  • 🚀 交易执行 / 入场
  • 🎯 限价订单挂单
  • ✅ 成功 / 订单成交
  • 🧹 订单取消
  • ❌ 错误/失败

Risk Management

风险管理

  • 🛑 Stop loss triggered
  • 🔄 Reversal / Trend flip
  • ⚠️ Warning / Validation issue
  • 🔧 Position repair/sync
  • 🛑 止损已触发
  • 🔄 反转 / 趋势翻转
  • ⚠️ 警告 / 验证问题
  • 🔧 头寸修复/同步

System

系统

  • 💰 Money/Balance/Settlement
  • 🌍 Geographic restriction
  • 🧟 Ghost trade detection
  • 💰 资金/余额/结算
  • 🌍 地域限制
  • 🧟 幽灵交易检测