Scan Rules (Advanced)
Scan Rules are boolean expressions used to decide whether a symbol matches. The advanced editor uses CEL-style syntax.
Syntax
Use comparisons and boolean logic. Expressions must evaluate to true or false.
// Comparison rsi_14 < 30 close > ma_50 // Boolean logic has_rsi_14 && has_ma_50 && rsi_14 < 30 && close > ma_50 (close > open) || (daily_move_pct > 5) // Perp-only example contract_type == "perp" && has_funding_rate && funding_rate > 0.001
Guard Pattern (Recommended)
For optional metrics, always check the matching has_* flag first. This prevents per-symbol evaluation failures on missing data.
// Good has_rsi_14 && has_ma_50 && rsi_14 < 30 && close > ma_50 // Risky (no guards) rsi_14 < 30 && close > ma_50
Supported Variables
Source of truth: GET /api/crypto/scans/variables?contract_type=spot or GET /api/crypto/scans/variables?contract_type=perp.
Price
close, open, high, low
Indicators
rsi_14, rsi_20, ma_20, ma_50, ma_200, rsi_14_normalized
Volume
volume_quote, volume_base
Derived
daily_move_pct, above_ma50, below_ma50, above_ma200, below_ma200, close_to_ma50, close_to_ma200, bullish_trend, bearish_trend
Previous Candle
prev_close, prev_open, prev_high, prev_low, prev_rsi_14, prev_rsi_20, prev_ma_50, prev_ma_200, prev_volume_quote, prev_volume_base
Deltas
delta_close, delta_rsi_14, delta_volume_quote
Metadata
symbol, exchange, contract_type
Safety Flags
has_open, has_high, has_low, has_volume_quote, has_volume_base, has_rsi_14, has_rsi_20, has_ma_20, has_ma_50, has_ma_200, has_prev_close, has_prev_rsi_14, has_prev_rsi_20, has_prev_ma_50, has_prev_ma_200, has_prev_volume_quote, has_prev_volume_base, has_delta_close, has_delta_rsi_14, has_delta_volume_quote, has_funding_rate, has_mark_premium
Perp-only
funding_rate, mark_premium
Validation Rules
- Expression must return boolean
- Max length and AST complexity limits are enforced
- Banned functions:
matches(),split(),join() - Validation warnings are returned for likely missing guards