Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/deniszidbaev-cmyk/polyclaw-trading/llms.txt

Use this file to discover all available pages before exploring further.

PolyClaw Trading enforces a deep, layered risk model: every candidate trade must pass per-trade sizing checks, daily budget checks, open-exposure checks, drawdown-mode checks, market-quality filters, signal-confidence thresholds, and freshness checks before execution is permitted. All parameters are read from the process environment at startup and validated by EngineConfig.from_env().
ConfigError is raised for any invalid, out-of-range, or internally inconsistent value. The engine never silently repairs a misconfiguration — a bad parameter fails the startup check and the system halts. Missing values receive documented defaults; malformed values fail closed.

Trade sizing

These variables set the absolute dollar bounds on each order and the risk percentage used for position sizing.
VariableDefaultDescription
MIN_TRADE_USD0.25Minimum order size in USD; orders below this floor are rejected
MAX_TRADE_USD1.00Maximum order size in USD; sized position is clamped to this ceiling
BASE_RISK_PER_TRADE_PCT1.0Fraction of bankroll risked per trade (percentage)
MAX_POSITION_BANKROLL_PCT5.0Maximum single-position size as a percentage of bankroll
MIN_TRADE_RISK_PCT1Minimum per-trade risk percentage (legacy path; used by earlier risk sizing code)
MAX_TRADE_RISK_PCT2Maximum per-trade risk percentage (legacy path; upper bound on risk sizing)
MIN_TRADE_USD cannot exceed MAX_TRADE_USD; the validator raises ConfigError if they are swapped.

Daily & exposure limits

These caps are evaluated fresh before every execution attempt, using the running totals in runtime/bankroll_state.json.
VariableDefaultDescription
MAX_DAILY_RISK_PCT8Maximum percentage of bankroll that may be risked across all trades in one calendar day
MAX_DAILY_NOTIONAL_PCT20Maximum notional dollar value deployed in one calendar day, as a percentage of bankroll
MAX_OPEN_EXPOSURE_PCT20.0Maximum percentage of bankroll that may be simultaneously in open positions
MAX_OPEN_BANK_EXPOSURE_PCT50Maximum percentage of the total bank balance that may be in open positions (broader cap)
MAX_TRADES_PER_DAY6Hard cap on the number of executions per calendar day

Drawdown management

When realized losses breach the trigger threshold, the engine enters drawdown mode and applies reduced risk limits until the recovery threshold is satisfied.
VariableDefaultDescription
DRAWDOWN_TRIGGER_PCT10Drawdown percentage of bankroll that activates reduced-risk mode
DRAWDOWN_RECOVERY_PCT5Drawdown must fall back below this level to exit reduced-risk mode
DRAWDOWN_REDUCED_TRADE_RISK_PCT1Per-trade risk percentage applied while in drawdown mode
DRAWDOWN_REDUCED_DAILY_RISK_PCT10Daily risk cap applied while in drawdown mode
DAILY_PROFIT_RESERVE_SHARE0.50Fraction of intraday profits locked away as reserve
DAILY_PROFIT_RESERVE_TRIGGER_PCT5Daily profit percentage that activates the reserve lock
DAILY_PROFIT_RESERVE_LOCK_PCT50Percentage of accumulated profit locked once the trigger fires
DRAWDOWN_RECOVERY_PCT must be strictly less than DRAWDOWN_TRIGGER_PCT; swapping them raises ConfigError.

Stop/take levels

ATR-based stop and take-profit multipliers must satisfy the configured reward/risk ratio, or startup validation fails.
VariableDefaultDescription
MIN_REWARD_RISK_RATIO1.5Minimum ratio of expected reward to risk required before entry
STOP_LOSS_ATR_MULTIPLIER1.5Stop-loss distance expressed as a multiple of ATR
TAKE_PROFIT_ATR_MULTIPLIER2.5Take-profit distance expressed as a multiple of ATR
MAX_ENTRY_SLIPPAGE_PCT0.05Maximum tolerated price slippage as a fraction of entry price
The validator enforces TAKE_PROFIT_ATR_MULTIPLIER / STOP_LOSS_ATR_MULTIPLIER >= MIN_REWARD_RISK_RATIO.

Market filters

Markets that fail any of these filters are silently skipped — they never reach the signal stage.
VariableDefaultDescription
MIN_MARKET_LIQUIDITY_USD100Minimum on-book liquidity in USD
MIN_MARKET_VOLUME_24H_USD100Minimum 24-hour traded volume in USD
MAX_MARKET_MINUTES_TO_EXPIRY1440Skip markets expiring more than this many minutes in the future
MIN_MARKET_MINUTES_TO_EXPIRY30Skip markets expiring sooner than this many minutes in the future
MIN_ENTRY_PRICE0.05Minimum YES-token price (must be strictly inside (0, 1))
MAX_ENTRY_PRICE0.95Maximum YES-token price (must be strictly inside (0, 1))
MAX_MARKET_MINUTES_TO_EXPIRY must exceed MIN_MARKET_MINUTES_TO_EXPIRY; MIN_ENTRY_PRICE must be less than MAX_ENTRY_PRICE and both must be strictly inside (0, 1).

Signal thresholds

VariableDefaultDescription
MIN_EXECUTION_CONFIDENCE0.72Minimum composite signal confidence score to allow execution
MIN_SEMANTIC_MAPPING_CONFIDENCE0.90Minimum confidence that the market question maps to a supported BTC binary outcome
ALLOW_EXTREME_PRICE_STRATEGY0When 0, markets near MIN_ENTRY_PRICE or MAX_ENTRY_PRICE boundaries are rejected
MIN_CONVICTION0.55Minimum internal conviction score used in earlier signal stages

Signal score weights

SIGNAL_SCORE_WEIGHTS is a JSON object that controls how each signal component contributes to the final composite confidence. All weights must sum to exactly 1.0; any deviation raises ConfigError.
{
  "trend": 0.25,
  "rsi": 0.15,
  "patterns": 0.25,
  "candle_quality": 0.15,
  "market_quality": 0.10,
  "poc_context": 0.05,
  "timeframe": 0.05
}
Set the variable as a single-line JSON string in .env.local:
SIGNAL_SCORE_WEIGHTS={"trend":0.25,"rsi":0.15,"patterns":0.25,"candle_quality":0.15,"market_quality":0.10,"poc_context":0.05,"timeframe":0.05}
All seven keys are mandatory. Extra or missing keys raise ConfigError. Each weight must be a finite number in [0, 1].

Penalties

Penalty values are subtracted from the raw signal score when the corresponding condition is detected. Each must be in [0, 1].
VariableDefaultDescription
CONTRADICTION_PENALTY0.35Applied when 5m and 15m signals directly contradict each other
SPARSITY_PENALTY0.15Applied when candle density is too low to be reliable
EXPIRY_PENALTY0.20Applied when the market is approaching the MIN_MARKET_MINUTES_TO_EXPIRY boundary
EXTREME_PRICE_PENALTY0.15Applied when the YES-token price is near an extreme bound
OVEREXTENSION_PENALTY0.15Applied when price is extended far beyond the EMA by more than MAX_EMA_EXTENSION_ATR ATRs
TIMEFRAME_CONFLICT_PENALTY0.35Applied when the two timeframes disagree without a clear directional read
TIMEFRAME_NEUTRAL_PENALTY0.10Applied when one timeframe is neutral rather than confirming
TIMEFRAME_ALIGNMENT_BONUS0.10Bonus added when both timeframes agree on direction

Cooldowns & circuit breaker

VariableDefaultDescription
FAILED_ORDER_COOLDOWN_SEC1800Per-market cooldown in seconds after a failed live order
MAX_DECISION_AGE_SEC600Maximum age in seconds of a cached decision before it must be regenerated
MAX_MARKET_AGE_SEC600Maximum age in seconds of fetched market data
MAX_CANDLE_AGE_SEC1200Maximum age in seconds of the candle dataset
MAX_BANKROLL_AGE_SEC600Maximum age in seconds of the bankroll state snapshot
PANIC_STOP0Hard halt for all trade-gate execution (1 = halted)
PANIC_AUTO_THRESHOLD5Number of consecutive failed live orders that automatically trip PANIC_STOP; 0 disables

Indicator parameters

These control the core technical indicators used by the deterministic signal engine.
VariableDefaultDescription
EMA_FAST_PERIOD8Fast EMA period (candles)
EMA_SLOW_PERIOD21Slow EMA period (candles); must exceed EMA_FAST_PERIOD
RSI_PERIOD14RSI lookback period (candles)
ATR_PERIOD14ATR lookback period (candles)
BULLISH_RSI_MIN52Lower bound of the bullish RSI zone
BULLISH_RSI_MAX72Upper bound of the bullish RSI zone
BEARISH_RSI_MIN28Lower bound of the bearish RSI zone
BEARISH_RSI_MAX48Upper bound of the bearish RSI zone
RSI_OVERBOUGHT75RSI level considered overbought
RSI_OVERSOLD25RSI level considered oversold
MIN_EMA_SPREAD_PCT0.003Minimum fractional spread between fast and slow EMA required for a trend signal
MAX_EMA_EXTENSION_ATR2.0Maximum ATR multiples of EMA extension before OVEREXTENSION_PENALTY applies
Validation rules enforced at startup: EMA_FAST_PERIOD < EMA_SLOW_PERIOD; BULLISH_RSI_MIN <= BULLISH_RSI_MAX; BEARISH_RSI_MIN <= BEARISH_RSI_MAX; bearish and bullish RSI zones must not overlap (BEARISH_RSI_MAX < BULLISH_RSI_MIN); RSI_OVERSOLD < RSI_OVERBOUGHT.

Build docs developers (and LLMs) love