Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How to Build Risk Controls for a Polymarket Trading Bot

说明与用途

Polymarket 交易机器人现在使用集中式风险管理引擎,检查交易规模、组合和市场敞口、价格偏差、流动性、重复订单、开放头寸数量、冷却时间和每日亏损限额,并记录拒绝日志。

问题

Automated trading bots can amplify mistakes, executing the same erroneous trade repeatedly without hesitation.

结果

The bot now rejects unsafe trades, limits exposure, avoids duplicates, and logs reasons, reducing risk of large losses and operational errors.

工作流

  • Define maximum trade size and implement check_trade_size.
  • Separate strategy sizing logic from risk limits using apply_max_size.
  • Set maximum portfolio exposure and implement check_exposure.
  • Set per‑market exposure limit and implement check_market_exposure.
  • Define maximum price deviation and implement price_is_valid.
  • Implement liquidity check with check_liquidity.
  • Create unique event IDs and maintain processed_events to prevent duplicates.
  • Set maximum open positions and implement can_open_position.
  • Implement cooldown logic with cooldown_finished.
  • Set daily loss limit and implement daily_limit_reached.
  • Encapsulate all checks in a RiskEngine.approve method.
  • Log rejection reasons for debugging.
  • Use the same risk engine in dry‑run mode to simulate trades.
  • Implement fail‑closed behavior for missing market data or API failures.
  • Make all limits configurable rather than hard‑coded constants.

证据

A trading bot does not become safer because it is automated.

来源

Without a risk layer, the execution system might immediately submit it.

来源

MAX_TRADE_SIZE = 50

来源

MAX_EXPOSURE = 500

来源

MAX_PRICE_DEVIATION = 0.03

来源

MIN_LIQUIDITY = 100

来源

processed_events = set()

来源

MAX_OPEN_POSITIONS = 10

来源

COOLDOWN_SECONDS = 60

来源

MAX_DAILY_LOSS = 50

来源

class RiskEngine: ... def approve(self, trade, portfolio, market): ...

来源

  • 记录日期: 2026-10-04T19:56:02.278Z