This is the merged final spec. Base: Claude Opus 4.6. Panel additions cherry-picked from: Gemini 3.1 Pro, Grok 4.1 (Fast), Grok 4.1, DeepSeek V3.1, GPT-4.1, Sonar Reasoning Pro. Panel reviews include both the initial B+ round and the A+ improvement round from the
aplus/subfolder. All panel additions are tagged[PANEL: Model Name].
This spec adapts the forex TA engine (19-section, ~1475-line master doc at memory/forex-data-collection.md) for crypto markets. It references the forex spec as base — only documents differences.
Target Assets
Pipeline context
Minor tweak
SuperTrend parameters: Keep 10-period ATR, multiplier 2 as default. Also run a second SuperTrend with multiplier 3 in parallel. Store both as st_2x and st_3x. Over time the database reveals which multiplier performs better per asset and timeframe.
[PANEL: Opus A+] Single SuperTrend as default — consolidate to multiplier 3: Remove parallel st_2x computation entirely from day-one data collection. Make the multiplier a config parameter per asset (default: 3 for all crypto assets). Multiplier 2 can be re-enabled per asset in config for A/B testing once 200+ SuperTrend flips exist per asset/timeframe. Rationale: crypto volatility makes multiplier 2 whipsaw too often; running both from day one doubles computation and storage with no actionable comparison data for months.
ATR thresholds: Crypto ATR is structurally higher than forex. Use the same 90-day percentile ranking (atr_14_percentile_90d) but calculate per-asset against its OWN history — never cross-asset.
Pullback entry — stop buffer: Forex uses "SuperTrend line minus 5 pips." Crypto has no pips. Use stop_buffer = 0.1 * ATR(14) as the ONLY method for all assets. The multiplier (0.1) is configurable per asset. Drop the percentage-of-price approach (0.1% * price for BTC etc.) entirely.
[PANEL: Opus A+] Eliminate percentage-based stop buffer: The percentage method doesn't adapt to volatility regimes — during a low-vol consolidation 0.1% may be fine, during a high-vol event it is suicidal. ATR-adaptive approach automatically scales. Having two methods creates ambiguity and bugs. One formula only. Add validation: if stop_buffer < 0.02 * price, log a warning (buffer is less than 0.02% of price, likely too tight).
R-multiple targets: Keep the same 2R through 6R structure. No change — these are ATR-relative already.
Outcome tracking: Identical to forex. No change.
SuperTrend flip logic, flip event records, multi-timeframe alignment count, all outcome tracking fields (MFE, MAE, hit_2r through hit_6r, time_to_Xr).
Minor tweak
ZigZag Deviation parameter: Use Deviation 5 for ALL assets as the primary (same as forex). For altcoins only, run a parallel Deviation 8 stored with suffix _zz8. Remove Deviation 10 entirely — it produces too few swing points and trend lines drawn from points too far apart are not useful below daily timeframe.
[PANEL: Opus A+] ZigZag consolidation: BTC gets Deviation 5 only (mature enough that 5% reversals are meaningful). ETH gets Deviation 5 only. Altcoins get Deviation 5 (primary) + Deviation 8 (secondary, _zz8 suffix). Deviation 10 eliminated — the review confirmed it misses actionable swings.
HTF validation pairings: Same structure but add one row:
| Chart Timeframe | Swing point must match high or low of a closed... |
|---|---|
| 5min | 1H candle |
| 15min | 4H candle |
| 1H | Daily candle |
| 4H | Weekly candle |
| Daily | Monthly candle |
The 5min-to-1H pairing is new. Crypto's 24/7 nature means 5min data has volume at all hours, unlike forex where 5min during Asia is mostly noise.
[PANEL: Opus A+] Defer 5min timeframe to v2: The storage and compute cost of tracking 5min ZigZag swings, trend lines, and S&R zones for 15-20 assets is substantial. For v1, start at 15min as the lowest timeframe. Add enable_5min_timeframe: false as a config flag. Enable after pipeline is stable and prediction pipeline specifically requests sub-15min signals.
Trend line touch threshold: Drop the pip reference entirely. Use 0.1 * ATR(14) only.
[PANEL: Opus A+] Three trend line sets down to two: Drop ZZ-only (noisiest). Keep ZZ+HTF (best quality) and HTF-only (simplest). This cuts trend line computation by 33% and reduces trend line event noise.
RSI trend lines, all stored fields, trend line events (touch/break/retest).
No change
Works as-is. All measurements are in candles and ATR multiples. The 10-candle pairing window, sequence tracking, and outcome fields transfer directly.
No change
RSI is asset-agnostic. All four divergence types, detection logic, strength calculation, and outcome tracking work identically.
Minor tweak
Moving Averages: No change to SMA 20/50/100/200 or golden/death cross logic.
RSI, MACD, Bollinger Bands, Stochastic, ADX/DMI, Keltner Channels: No change. Asset-agnostic.
VWAP: Major difference in anchoring.
vwap_24h, vwap_weekly (rolling 7 days, not 5 — crypto trades weekends).vwap_48h (too correlated with 24h to add value) and vwap_monthly (too slow-moving; SMA200 already serves this function).[PANEL: Opus A+] VWAP simplification: Four VWAPs → two. 48h VWAP adds almost nothing over 24h. Monthly VWAP on a 1H chart is essentially a flat line. Removing two VWAP calculations per asset per candle saves meaningful compute across 15-20 assets × 6 timeframes × 24/7.
[PANEL: Grok 4.1] VWAP simplification confirms two VWAPs: 24h for intraday institutional reference, weekly for swing reference. Drop 48h and monthly. Retain SD bands on both.
Volume-Pressure Indicators (OBV, CMF, Force Index): No change to calculation. Crypto exchanges report REAL volume (denominated in base asset or USDT), not tick volume — better data than forex. Use actual volume.
Fibonacci Retracement: No change.
Support/Resistance Zones: See Section 17 for crypto-specific S&R changes.
Pivot Points: No change to calculation. Daily period uses UTC 00:00 close (crypto convention), not 5PM ET.
Round Numbers: Major change. Replace the .0025 forex grid entirely.
| Asset | Grid Levels | "Big Figure" Equivalents |
|---|---|---|
| BTC | $100, $250, $500, $1,000, $2,500, $5,000, $10,000, $25,000, $50,000, $100,000 | $10K, $25K, $50K, $100K |
| ETH | $10, $25, $50, $100, $250, $500, $1,000, $2,500, $5,000 | $1K, $2.5K, $5K |
| SOL | $1, $2.50, $5, $10, $25, $50, $100, $250 | $10, $25, $50, $100 |
| Altcoins <$10 | $0.10, $0.25, $0.50, $1.00, $2.50, $5.00 | $1.00, $5.00 |
| Altcoins <$1 | $0.01, $0.025, $0.05, $0.10, $0.25, $0.50 | $0.10, $0.50 |
Config mapping: each asset gets its round-number grid based on current price range. Recalculate grid assignment weekly (an altcoin at $0.80 might cross to $1.20 and need a different grid).
S&R scoring: "Big Figure" equivalents get +4, mid-tier get +2, finest grid get +1.
[PANEL: DeepSeek V3.1] Logarithmic spacing alternative: Consider logarithmic spacing (e.g., 1.0, 1.5, 2.0, 3.0, 5.0, 7.5, 10.0 multiples) for low-price altcoins as a simpler-to-maintain alternative to the tiered grid.
[PANEL: Grok 4.1 Fast] Dynamic round-number reclassification: Make grid recalculation dynamic — trigger on 20% price change OR weekly, whichever comes first. Use log-scale intervals (e.g., 1%, 2.5%, 5%) for asset-agnostic adaptation to rapid altcoin price moves.
Pair Correlations & Lead-Lag: Replace forex-specific pairs:
btc_eth_corr: BTC vs ETH (usually 0.85+, drops during "alt season")btc_sol_corr: BTC vs SOLeth_sol_corr: ETH vs SOLbtc_sp500_corr: BTC vs S&P 500 (macro risk correlation)btc_gold_corr: BTC vs Goldbtc_dxy_corr: BTC vs Dollar Index (inverse relationship)altcoin_btc_avg_corr: average correlation of all tracked altcoins vs BTC[PANEL: Grok 4.1 Fast] BTC/S&P correlation is regime-dependent: Do NOT assume correlation is 0.85+ "usually." 2024-2026 data shows range from -0.3 to +0.7 depending on macro regime. Flag regime change when correlation deviates >2 SD from 30-day rolling average. Treat as regime-conditional, not constant.
Remove btc_gold_ratio and btc_gold_corr as derived fields. Keep raw gold price as cross-market input. The "digital gold" narrative operates on monthly timescales — irrelevant for this engine's trading timeframes.
[PANEL: Opus A+] Remove BTC/Gold ratio: BTC/gold correlation is unstable, often near zero for extended periods. Drop the derived ratio and correlation calculations. Raw gold price is sufficient.
Lead-lag: BTC almost always leads. Track whether ETH or SOL ever leads BTC by 1-4 candles.
[PANEL: Sonar Reasoning Pro] Maker vs Taker volume ratio: Track maker vs taker volume by asset per hour/session. maker_vol_ratio, taker_vol_ratio. Extreme taker volume (market orders) = urgency = continuation. Extreme maker volume (limit orders) = distribution/accumulation = reversal setup. Source: Binance public trades API (free, filterable by maker/taker flag). Store hourly aggregates.
Minor tweak
Momentum Squeeze: Same trigger (BB inside KC, RSI 40-60, ATR below average). No change.
Trend Exhaustion: Same logic. Volume spike threshold: start with 3x average for crypto (vs 2x in forex). Make configurable per asset. Crypto volume spikes can be 5-10x average.
Breakout Setup: Same logic. No change.
Mean Reversion Extreme: Configurable multiplier — default 3x ATR for BTC, 4x for altcoins.
Multi-Indicator Confluence Score: Same -5 to +5 scoring per indicator, -35 to +35 composite. No change.
[PANEL: Grok 4.1 Fast] Volume spike threshold time-aware: Make volume spike threshold context-aware: 2x average during US off-hours, 3x during US hours, 4x during US/Europe overlap. Alternatively use rolling percentile (>90th daily percentile = signal). A random Tuesday 3x spike is different from a FOMC day 3x spike.
[PANEL: Sonar Reasoning Pro] Confluence simplification: Consider reducing from 5 named confluence events to 2 core events — (1) Breakout Setup, (2) Mean Reversion Extreme — for v1. Test both before expanding. Current 5 events risk firing continuously and producing noise.
Major rewrite
This is the biggest structural difference between forex and crypto. The forex spec relies on OANDA order/position books and CFTC COT data. None of that exists in crypto. Replace entirely with crypto-native equivalents.
Architecture note: Use Binance Combined WebSocket streams (wss://stream.binance.com/stream) as PRIMARY data source for real-time feeds. REST API for historical backfill and OI snapshots only. This eliminates ~90% of REST API calls and makes rate limiting a non-issue.
[PANEL: Opus A+] Explicit WebSocket architecture: Subscribe to Binance Combined WebSocket. Stream subscriptions per asset: <symbol>@kline_<interval> (candles), <symbol>@depth20@100ms (order book top 20), <symbol>@aggTrade (real-time trades for VWAP/volume). For futures: <symbol>@markPrice (mark price + funding rate, updates every 3s), <symbol>@forceOrder (liquidation events). At 15 assets × 6 timeframes × 3 stream types = 270 spot streams + 15 × 3 = 45 futures streams = 315 total — well within Binance's 1024 stream limit per connection. REST ONLY for: historical backfill, OI snapshots (no WebSocket), long/short ratio snapshots, funding rate history.
Source: Binance Futures API (primary), Bybit API (fallback), OKX API (tertiary)
Pull every 5 minutes (via REST — no WebSocket stream available):
total_open_interest: total OI across tracked exchanges (contracts and USD value)oi_change_1h, oi_change_4h, oi_change_24h: rate of changeoi_vs_price_divergence: boolean — OI rising while price falling (or vice versa)oi_percentile_90d: 90-day percentile rank (0-100)[PANEL: DeepSeek V3.1] Reduce OI polling to 15min: OI doesn't change fast enough to warrant 5-minute polling across many assets. 15min polling avoids rate limits while preserving signal quality.
Source: Binance Futures API (primary), Bybit (fallback), Coinglass (tertiary via WebSocket markPrice stream for near-real-time updates)
Pull every 1 hour (predicted rates update continuously via WebSocket):
funding_rate_current: current funding rate (typically -0.01% to +0.10% per 8h)funding_rate_predicted: next predicted funding ratefunding_rate_annualized: current_rate * 3 * 365funding_rate_percentile_30d: percentile rank (0-100), NOT z-score — funding rates are highly non-normal (bimodal), z-score gives false signals. Extreme signals at <5th and >95th percentile.funding_extreme_long: boolean — funding > 0.05% per 8hfunding_extreme_short: boolean — funding < -0.01% per 8hfunding_flip: boolean — funding changed sign this period[PANEL: Opus A+] Use percentile not z-score: Funding rates are bimodal (extreme positive or extreme negative). Z-score assumes normal distribution and produces false signals. Replace funding_rate_zscore_30d with funding_rate_percentile_30d.
[PANEL: Gemini 3.1 Pro] Predicted rate logic: Only weight the predicted funding rate heavily in the final 60 minutes before each 8-hour settlement window. Outside that window, predicted rate fluctuates wildly based on minute-to-minute premium index — using it continuously causes false positives. Add funding_near_settlement: boolean = true when within 60 minutes of next 00:00/08:00/16:00 UTC settlement.
[PANEL: Grok 4.1] Adaptive funding pull frequency: Pull funding every 15 minutes when atr_14_percentile_90d > 80 OR liquidation_spike = true. During low-vol regimes, hourly is sufficient. Store additional field funding_rate_volatility_adjusted to track intraday shifts.
Source: Binance forceOrder WebSocket stream (primary, real-time), Coinglass API (secondary, accept 5-15min lag)
Important caveat: Binance removed their public liquidation WebSocket stream in 2023 and replaced it with aggregated forceOrder data that only shows a fraction of actual liquidations. Treat as directional (which side is getting liquidated more), not precise dollar amounts. Coinglass free tier has 5-15 minute lag.
Pull every 5 minutes (Coinglass REST for aggregates; Binance WebSocket for real-time direction):
liquidations_long_1h: USD value of long liquidations in the last hourliquidations_short_1h: USD value of short liquidations in the last hourliquidation_ratio: long_liq / (long + short liq). Above 0.7 = cascade selling. Below 0.3 = short squeeze.liquidation_spike: boolean — total liquidations exceeded 3x the 24h hourly averagecumulative_liquidations_24h: total liquidations last 24 hoursliquidation_data_quality: enum ('realtime', 'lagged_5min', 'lagged_15min', 'degraded') — tracks which source is activeSource: Binance Futures API (free)
Note: Binance topTraderLongShortRatio is T+15 min, not real-time. Use for regime confirmation only, not immediate trade signals.
Pull every 15 minutes:
long_short_ratio_accounts: accounts holding long vs shortlong_short_ratio_positions: long position value vs short position valuetop_trader_long_short_ratio: top traders only (Binance provides separately)retail_vs_whale_divergence: boolean — retail positioned opposite to top traderslong_short_percentile_30d: percentile rank vs 30-day history (replace z-score)Source: CryptoQuant API (free tier — severely limited, daily granularity only on free tier), Glassnode (limited free)
Reality check: CryptoQuant free tier gives daily granularity only, delayed. The 30-minute polling cadence in the original spec requires their $30/month plan. Options:
Pull daily (free tier) or every 30 minutes (paid tier):
exchange_netflow_btc: net BTC flowing into (positive) or out of (negative) exchangesexchange_netflow_eth: same for ETHexchange_reserve_btc: total BTC held on exchangesexchange_reserve_change_7d: 7-day change in exchange reservesexchange_flow_available: boolean — flag as false if data source is degraded, skip all exchange flow cross-section flags when false[PANEL: DeepSeek V3.1] Miner Flows: Add miner_outflow_24h (BTC miner outflows to exchanges), miner_outflow_7d, miner_outflow_zscore_30d. Miner selling is ~900 BTC/day new supply. Miner outflow spikes precede price drops 70% of the time with 2-3 day lead time. Source: CryptoQuant API free tier or Glassnode.
[PANEL: DeepSeek V3.1] Stablecoin Exchange Reserve Ratio: Add stablecoin_reserve_ratio (USDT+USDC on exchanges / total stablecoin supply), reserve_ratio_change_7d. When <20%, insufficient buying power. When >30%, accumulation phase. Leading indicator with 1-2 week predictive window. Source: CryptoQuant, DefiLlama (free).
Pull every 1 minute (via WebSocket bid/ask from order book stream):
bid_ask_spread: current spread on Binance (primary exchange)spread_zscore_24h: current spread vs rolling 24h averageRemove cross_exchange_spread (Binance vs Coinbase price difference). Cross-exchange arbitrage spreads normalize in seconds — not actionable for a TA engine on 15min+ timeframes. Eliminates a Coinbase API dependency.
[PANEL: Opus A+] Remove cross-exchange spread: Implementation complexity of syncing two exchange WebSocket feeds for a signal that normalizes in seconds is not worth it. Binance-only bid-ask spread captures liquidity conditions adequately.
Source: Binance WebSocket <symbol>@depth20@100ms stream (free, real-time)
Capture every 60 seconds (snapshot from rolling stream):
ob_bid_depth_1pct: total bid volume within 1% of mid priceob_ask_depth_1pct: total ask volume within 1% of mid priceob_imbalance_1pct: bid_depth / (bid_depth + ask_depth), range 0-1. Below 0.3 = sellers overwhelming buyers.ob_bid_wall_price: price level with largest single bid within 2% of midob_ask_wall_price: same for asksob_bid_wall_size_usd, ob_ask_wall_size_usd: USD value of wallob_wall_persistent: boolean — has the wall persisted for >10 consecutive snapshots (10+ minutes)Feed persistent walls into S&R engine as Method 11 (order book walls) with weight 1.5x, but ONLY when wall has persisted >10 snapshots. Walls that appear and disappear in seconds are spoofing — transient walls should be ignored.
Cross-section flag: ob_wall_at_sr_zone = true when an order book wall is within 0.1*ATR of an existing S&R zone with score >50.
[PANEL: Opus A+] Order book depth is MUST-HAVE: The single most actionable short-term predictor missing from the original spec. A 500 BTC bid wall at $98K aligning with a multi-touch S&R zone is dramatically more likely to hold. The imbalance ratio is a real-time supply/demand gauge. Cost: $0, no rate limit impact from WebSocket.
[PANEL: Gemini 3.1 Pro] Order book imbalance: Same implementation. Pull top 100 levels for richer imbalance calculation, not just top 20. Include bid_depth_5pct and ask_depth_5pct for wider perspective.
[PANEL: GPT-4.1] Order book microstructure MUST-HAVE: Predicts directional moves 5-30 min ahead. When bid side is 10x deeper than ask, price almost always moves up before equilibrium. Enhances S&R zone validation and reduces false breakout signals.
Source: Calculated from Binance spot price + Binance futures mark price (already collected). Zero additional API cost.
Calculate every 1 minute:
perp_basis_pct: (binance_perp_mark_price - binance_spot_price) / binance_spot_price * 100perp_basis_zscore_24h: z-score vs rolling 24hperp_basis_zscore_7d: z-score vs rolling 7dperp_basis_annualized: perp_basis_pct * 365 * 3 (assuming 8h funding periods). Annualized >30% = unsustainable, correction likely. Annualized <-10% = short squeeze likely.perp_basis_extreme_long: boolean — annualized basis > 30%perp_basis_extreme_short: boolean — annualized basis < -10%perp_basis_flip: boolean — basis changed sign this periodCross-section flag: basis_funding_agreement = true when both basis and funding rate point the same direction (both positive = leveraged longs dominant, both negative = leveraged shorts dominant). basis_funding_divergence = true when they disagree (rare but highly informative — means 8h funding settlement is lagging real-time sentiment shift).
[PANEL: Opus A+] Basis as real-time funding leading indicator: Funding rates settle every 8 hours. Between settlements, the spot-perp basis is the REAL-TIME version — updates every second. A basis spiking to +0.05% while funding won't settle for 6 hours gives 6 hours of lead time over funding data. Annualized basis is comparable to TradFi carry trade yields. Cost: $0 (calculated from existing data).
[PANEL: Gemini 3.1 Pro] Perp-spot basis MUST-HAVE: When perps trade at heavy discount to spot, short squeeze is highly probable. Calculate perp_basis_pct and basis_zscore_24h.
[PANEL: DeepSeek V3.1] Futures basis tracking: Add basis_annualized, basis_zscore_30d, basis_extreme_long (>20%), basis_extreme_short (<-5%). Extreme basis >20% precedes liquidations 85% of the time.
Source: Calculated from existing data (OI + average leverage ratios from Binance). Zero additional API cost.
Calculate every 15 minutes:
Model: use current price (or 24h VWAP as refined entry proxy) + reported leverage ratios to estimate liquidation clusters.
estimated_liq_cluster_long_1/2/3: top 3 price levels with highest estimated long liquidation densityestimated_liq_cluster_short_1/2/3: top 3 price levels for shortsliq_cluster_long_total_usd: estimated USD at risk in nearest long liquidation clusterliq_cluster_short_total_usd: same for shortsliq_magnet_direction: enum ('long_liq_below', 'short_liq_above', 'balanced') — which side has more liquidation fuel. Price tends to move TOWARD the larger cluster.Cross-section flag: liq_cluster_at_sr_zone = true when estimated liquidation cluster is within 0.5*ATR of an existing S&R zone with score >40.
Feed into S&R engine as Method 12 (liquidation magnets) with weight 2.0x.
[PANEL: Opus A+] Liquidation clusters as MUST-HAVE leading indicators: The spec tracked liquidations AFTER they happen (Section 7.3). This predicts WHERE they will happen. Market makers push price toward liquidation clusters because forced selling/buying provides them liquidity. Knowing $800M in long liquidations sits at $94K-$95K while only $200M in short liquidations is at $102K-$103K tells you path of least resistance. This is the difference between lagging and leading indicator.
Major rewrite
Bond Yields: Keep US Treasury yields only. Drop all non-US yield spreads.
us_2y_yield, us_10y_yield, us_yield_curve_slopeyield_momentum_5d: 5-day rate of change of US 10YEquity Indices: Keep S&P 500 and Nasdaq. Drop Nikkei and DAX.
btc_sp500_corr_20d: rolling 20-day correlation. Track whether crypto is trading as risk asset or decorrelating.Commodities: Keep gold price as a raw cross-market input. Drop oil and copper. Drop btc_gold_ratio and btc_gold_corr (operate on monthly timescales, not useful here).
Volatility: Keep VIX and VIX term structure.
btc_realized_vol_30d: BTC 30-day realized volatility (annualized). Compare to VIX for cross-asset vol regime.dvol (if available): Deribit BTC Volatility Index — the crypto-native VIX equivalent. Source: Deribit API (free).Dollar Index: Keep DXY. BTC has meaningful inverse correlation with DXY.
Risk-On/Off Score: Redefine for crypto context.
risk_on_off_score: equities up + yields stable + VIX down + DXY down + funding rates positive = risk-on (bullish crypto). Opposite = risk-off.crypto_risk_score: funding rates + liquidation direction + exchange flows + altcoin correlation. Crypto-specific sentiment gauge independent of TradFi.Cross-market data staleness: Cross-market data (equities, yields, VIX) only updates during US market hours (08:00-17:00 ET, Mon-Fri). Outside these hours, use last close price and flag as stale. Store cross_market_data_fresh: boolean = false outside US market hours.
[PANEL: Grok 4.1 Fast] Staleness flag: When S&P data is 1 hour stale at 5PM ET, BTC/S&P correlation calculation produces misleading results. Explicitly mark cross-market data with staleness timestamps and skip correlation-dependent signals when data is stale.
BTC Dominance (replaces DXY as "base currency strength"):
btc_dominance: BTC market cap / total crypto market cap (%). Source: CoinGecko API (free).btc_dominance_trend: rising = money flowing from alts to BTC (risk-off within crypto), falling = alt seasonbtc_dominance_roc_7d: 7-day rate of changeETH/BTC Ratio (crypto equivalent of a major cross pair):
eth_btc_ratio: ETH price / BTC priceeth_btc_trend: rising = ETH outperforming = risk appetite growingeth_btc_supertrend: SuperTrend on this ratio — trend flips signal rotationStablecoin Supply:
usdt_market_cap: total USDT supplyusdc_market_cap: total USDC supplystablecoin_supply_change_7d: week-over-week change[PANEL: Gemini 3.1 Pro] Stablecoin Peg Monitoring: Add usdt_usd_premium tracking. Track USDT/USD or USDC/USDT pairs on Binance Spot. When USDT trades at premium to USD (offshore/P2P), indicates massive retail fiat inflow (bullish). Discount indicates capital flight. Source: Binance Spot (free).
[PANEL: GPT-4.1] Stablecoin peg deviation is MUST-HAVE: Loss of peg (USDT deviating from $1) is a systemic risk event. Early detection is critical for tail risk management. Source: Binance, Coinbase, CoinGecko real-time price of stablecoins vs USD.
Network Activity Metrics (replaces DeFi TVL which has circular price dependency):
eth_gas_price_gwei: average gas price on Ethereum. Source: Etherscan API (free tier).sol_priority_fee_avg: average priority fee on Solana. Source: Solana RPC (free public endpoints).[PANEL: Opus A+] Remove DeFi TVL, replace with gas fees: TVL changes are mostly driven by price changes in the underlying assets — circular signal. TVL in native asset terms is better but still complex to implement correctly. Replace with ETH gas fees (Etherscan free API) and SOL priority fees (Solana RPC free). Gas fees are real-time proxies for on-chain activity without the circular dependency problem. Gas spikes have preceded ETH price moves by 1-4 hours historically.
[PANEL: DeepSeek V3.1] ETH Gas Price tracking: gas_price_gwei, gas_price_percentile_90d, gas_spike (>200 gwei) — high gas predicts ETH outperformance vs BTC in next 48h.
[PANEL: Grok 4.1] Staking Metrics for ETH/SOL: Add staked_eth_pct_total_supply, staked_sol_pct_total_supply, lido_apy_7d_avg, staking_inflow_outflow_24h. Pull every 1 hour. Boolean staking_spike_bullish for inflows >2 SD above 30-day mean. Staking rate changes influence holder behavior (lockup vs selling), impacting supply dynamics. Source: Lido Finance API (free), StakingRewards API (free tier).
Major rewrite — becomes "Crypto Relative Strength"
For each tracked asset, calculate:
asset_strength_roc_24h: 24-hour rate of change vs USDTasset_strength_vs_btc_24h: 24-hour rate of change vs BTCasset_strength_zscore_30d: z-score of 24h performance vs own 30-day historyasset_strength_rank: rank among all tracked assets (1 = strongest, N = weakest)altcoin_avg_strength_vs_btc: average of all tracked altcoins' asset_strength_vs_btc_24h — single number captures "alt season" vs "BTC dominance" without subjective sector classificationsPull every 5 minutes from exchange price data.
Remove: Sector rotation tracking (layer1_avg_strength, defi_avg_strength, meme_avg_strength, sector_leader, rotation_signal). Reasons:
[PANEL: Opus A+] Sector rotation removal: The single altcoin_avg_strength_vs_btc metric replaces the entire sector framework with one objective number. If SOL is outperforming BTC, you can see that directly without knowing whether SOL is classified as "L1" or "DeFi." Add sector groupings in v2 only if altcoin predictions prove to be core.
[PANEL: DeepSeek V3.1 / Grok 4.1 Fast / GPT-4.1] Confirm sector rotation deferral: All panel members agree — defer sector rotation to v2. Start with BTC/ETH/SOL correlations only. Sector analysis adds maintenance overhead with uncertain signal value.
Major rewrite
[PANEL: Grok 4.1 Fast] Use hard session windows, not soft boundaries: Soft boundaries don't work operationally — no binary session state = hard to code.
| Session | UTC Hours | ET Hours | Character |
|---|---|---|---|
| Asia | 23:00-08:00 | 7:00 PM - 4:00 AM | Lower volume, sharp moves on thin liquidity |
| Europe | 07:00-16:00 | 3:00 AM - 12:00 PM | Volume picks up, often sets directional bias |
| US | 12:00-21:00 | 8:00 AM - 5:00 PM | Highest volume, TradFi correlation strongest |
| US/Europe Overlap | 12:00-16:00 | 8:00 AM - 12:00 PM | Peak activity window |
| Off-hours | 21:00-23:00 | 5:00 PM - 7:00 PM | Lowest volume, transition period |
Session overlaps are OK — a timestamp can belong to multiple sessions. Use UTC timestamps throughout.
session_open_price, session_high, session_low, session_closesession_range_pct: total range as percentage (replace pip-based measurement)session_direction: bullish/bearish/neutralsession_volume: actual traded volume (not tick count — crypto has real volume data)asia_range_pct: total range during Asia. Below 20th percentile = compressed, European breakout likely.us_open_initial_balance_high/low: high and low of first hour of US session (12:00-13:00 UTC). When TradFi money shows up and often sets direction.cme_gap: gap between CME Bitcoin futures Friday close and Sunday open. CME gaps fill ~80% of the time. Fields: cme_gap_pct, cme_gap_direction, cme_gap_filled, cme_gap_fill_hours.us_to_asia_continuation: did Asia session continue the US session direction, or reverse?weekend_behavior: track Saturday and Sunday as separate sessions with their own range/direction stats.us_holiday: boolean onlycme_futures_hours: CME crypto futures trade Sun-Fri only. Track whether CME open/close creates volume spikes in spot markets.funding_rate_settlement: every 8 hours on most exchanges (00:00, 08:00, 16:00 UTC on Binance). Brief volatility spikes around settlement.Minor tweak
Minor tweak
Keep from forex: FOMC, NFP, CPI (these move BTC through risk sentiment). Drop ECB, BOJ, and non-US central bank events.
Add crypto-specific events:
eth_upgrade_date: Ethereum network upgrades (major events that move ETH)btc_halving_countdown: days until next BTC halving. Only trigger alerts when within 60 days of halving — a 2+ year countdown is calendar noise.sec_hearing_date: major SEC/regulatory eventstoken_unlock_date: scheduled token unlocks for tracked altcoins. Only track altcoins with: >$50M market cap AND upcoming unlock in next 30 days AND unlock represents >1% of circulating supply. Drop all other unlocks.etf_flow_daily: daily BTC/ETH ETF inflow/outflow. Source: free trackers.cme_settlement_time: CME crypto futures settlement — 16:00 ET. Can create volume spikes.etf_creation_redemption_deadline: daily deadline for authorized participants.funding_rate_settlement: every 8 hours (00:00/08:00/16:00 UTC Binance).Post-release tracking: Same structure (5min, 30min, 1h, 4h moves after event). Works identically.
[PANEL: Grok 4.1 Fast] BTC halving countdown 60-day window: Only trigger halving_countdown alerts when within 60 days. A countdown 2+ years out is noise.
[PANEL: Grok 4.1 Fast] Token unlocks — selective tracking: Most token unlocks are already priced in. Only track those meeting all three criteria: >$50M market cap, unlock within 30 days, AND >1% of circulating supply in the unlock. Drop everything else.
[PANEL: GPT-4.1] New token listings/delistings: Track major exchange listings/delistings via RSS feeds or scraping. Listings trigger volatility and regime changes. NICE-TO-HAVE for v2.
[PANEL: GPT-4.1] Real-time crypto news/sentiment: Crypto reacts fast to breaking news (hacks, regulatory moves, exploits). Consider CryptoPanic API (free) for news feed integration. NICE-TO-HAVE, assess before v2 build.
Minor tweak
Seasonal factors (collect data but do NOT generate signals until backtested):
btc_halving_cycle_phase: months since last halving (0-48). Historically, biggest rallies come 12-18 months after halving.q4_seasonality: Q4 has historically been bullish for BTC — formally backtest before treating as signal (true for 2020/2021, false for 2022).january_effect: track whether BTC shows January seasonality.tax_season_april: US tax season creates potential selling pressure.Drop: fiscal_year_end_japan, daylight_savings_transition.
Institutional Fix Times — replace forex fixes with:
cme_settlement_time: 16:00 ETetf_creation_redemption_deadline: late-day flowsfunding_rate_settlement: 00:00/08:00/16:00 UTC[PANEL: Grok 4.1 Fast] Backtest seasonal claims before signaling: "Q4 has historically been bullish for BTC" — true for 2020, 2021; false for 2022. This is cherry-picked data. Run 10-year backtest on Q4 vs rest-of-year returns. If p-value >0.05, drop the feature. Otherwise include with confidence interval and years of data range.
[PANEL: Grok 4.1 Fast] Halving cycle section = over-engineered at launch: Tax season April effect, January effect, Q4 rally, halving cycle phase — for altcoins this is pure noise. Even for BTC, these patterns are weak. Collect the data (it's free) but do NOT generate signals until formally backtested. Move seasonal signal generation to Phase 6 (optional).
Minor tweak
fwd_return_1h_pct, fwd_return_4h_pct, fwd_return_24h_pct. Also keep USD-denominated absolute returns for BTC (1% at $100K = $1,000, relevant for position sizing).btc_sp500_corr_20d, btc_gold_corr_20d, btc_dxy_corr_20d, btc_eth_corr_20d, btc_sol_corr_20d. correlation_regime_break: flag when any key correlation deviates >2 SD from 90-day norm.nrr_daily_weekly = Daily Range% / (Weekly Range% / 7). Monthly: nrr_weekly_monthly = Weekly Range% / (Monthly Range% / 4.33).Minor tweak + major operational additions
Rename forex_candles → crypto_candles. Same schema. Replace pair with symbol (e.g., BTCUSDT). Replace tick_volume with volume (actual traded volume in quote currency).
[PANEL: Opus A+] Split into 4 SQLite database files:
candles.db — OHLCV candles + all indicator values (highest write volume, append-only)events.db — SuperTrend flips, trend line events, divergences, confluence events, S&R zone events (moderate write volume, append-only)orderflow.db — funding rates, OI, liquidations, long/short ratios, order book snapshots, whale transactions, perp basis (high write volume, mix of append and update)context.db — cross-market data, relative strength, session stats, economic calendar, Fear & Greed, stablecoin supply, derived metrics (low-moderate write volume)All databases: WAL mode enabled. Batch writes: accumulate up to 30 seconds of data in memory per database, then flush in a single transaction. Reduces transaction count by 30-60x.
Cross-database joins: perform in application layer (avoid SQLite ATTACH for real-time queries — performance issues under concurrent access).
Daily maintenance job at 04:00 UTC (lowest global activity): VACUUM each database, rebuild indexes, log file sizes.
[PANEL: Gemini 3.1 Pro] In-memory state manager: Keep 1min/5min polling data in Node.js memory (or Redis). Only batch-write 15min/1H aggregates to SQLite — prevents catastrophic 'database is locked' errors when AI agents are running complex read queries simultaneously.
-- candles.db
CREATE TABLE crypto_candles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL, -- 'BTCUSDT'
timeframe TEXT NOT NULL, -- '1m','5m','15m','1h','4h','1d','1w'
open_time INTEGER NOT NULL, -- Unix ms UTC
open REAL NOT NULL,
high REAL NOT NULL,
low REAL NOT NULL,
close REAL NOT NULL,
volume REAL NOT NULL, -- actual traded volume in USDT
close_time INTEGER NOT NULL,
-- SuperTrend (single multiplier, default 3)
st_3x_value REAL,
st_3x_direction INTEGER, -- 1 bullish, -1 bearish
-- ATR
atr_14 REAL,
atr_14_percentile_90d REAL,
-- RSI
rsi_14 REAL,
-- MACD
macd_line REAL,
macd_signal REAL,
macd_histogram REAL,
-- Bollinger Bands
bb_upper REAL,
bb_middle REAL,
bb_lower REAL,
bb_width REAL,
-- VWAP (rolling)
vwap_24h REAL,
vwap_24h_upper_1sd REAL,
vwap_24h_lower_1sd REAL,
vwap_24h_upper_2sd REAL,
vwap_24h_lower_2sd REAL,
vwap_weekly REAL,
vwap_weekly_upper_1sd REAL,
vwap_weekly_lower_1sd REAL,
vwap_weekly_upper_2sd REAL,
vwap_weekly_lower_2sd REAL,
-- Moving Averages
sma_20 REAL,
sma_50 REAL,
sma_100 REAL,
sma_200 REAL,
-- ADX/DMI
adx_14 REAL,
di_plus_14 REAL,
di_minus_14 REAL,
-- Stochastic
stoch_k REAL,
stoch_d REAL,
-- Volume indicators
obv REAL,
cmf_20 REAL,
force_index_13 REAL,
-- Confluence score
multi_indicator_confluence_score INTEGER, -- -35 to +35
-- MTF alignment
mtf_alignment_count INTEGER,
-- Maker/Taker volume ratio
maker_vol_ratio REAL,
taker_vol_ratio REAL,
-- Data quality
data_source TEXT DEFAULT 'binance',
recalculated_after_gap INTEGER DEFAULT 0, -- boolean
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, timeframe, open_time)
);
CREATE INDEX idx_crypto_candles_symbol_tf_time ON crypto_candles(symbol, timeframe, open_time DESC);
CREATE INDEX idx_crypto_candles_time ON crypto_candles(open_time DESC);
-- events.db
CREATE TABLE st_flip_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
flip_time INTEGER NOT NULL,
flip_direction INTEGER NOT NULL, -- 1 bull flip, -1 bear flip
price_at_flip REAL NOT NULL,
atr_at_flip REAL,
rsi_at_flip REAL,
funding_rate_at_flip REAL,
oi_at_flip REAL,
perp_basis_at_flip REAL,
fwd_return_1h_pct REAL,
fwd_return_4h_pct REAL,
fwd_return_24h_pct REAL,
fwd_return_7d_pct REAL,
mfe_pct REAL,
mae_pct REAL,
hit_2r INTEGER, -- boolean
hit_3r INTEGER,
hit_4r INTEGER,
hit_6r INTEGER,
time_to_2r_candles INTEGER,
confluence_score_at_flip INTEGER,
session TEXT, -- 'asia','europe','us','overlap','offhours'
us_market_hours INTEGER, -- boolean
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE INDEX idx_st_flips_symbol_tf_time ON st_flip_events(symbol, timeframe, flip_time DESC);
CREATE TABLE trend_line_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
event_type TEXT NOT NULL, -- 'touch','break','retest'
trend_line_id INTEGER NOT NULL,
event_time INTEGER NOT NULL,
price_at_event REAL NOT NULL,
trend_line_slope REAL,
trend_line_set TEXT, -- 'zz_htf','htf_only','rsi'
atr_at_event REAL,
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE rsi_divergence_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
divergence_type TEXT NOT NULL, -- 'regular_bull','regular_bear','hidden_bull','hidden_bear'
detected_time INTEGER NOT NULL,
price_swing_1 REAL,
price_swing_2 REAL,
rsi_swing_1 REAL,
rsi_swing_2 REAL,
divergence_strength REAL, -- 0-100
fwd_return_4h_pct REAL,
fwd_return_24h_pct REAL,
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE confluence_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
event_type TEXT NOT NULL, -- 'momentum_squeeze','trend_exhaustion','breakout_setup','mean_reversion_extreme'
event_time INTEGER NOT NULL,
direction INTEGER, -- 1 or -1
confluence_score INTEGER,
funding_rate_at_event REAL,
oi_at_event REAL,
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE sr_zones (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
zone_low REAL NOT NULL,
zone_high REAL NOT NULL,
zone_type TEXT NOT NULL, -- 'support','resistance','both'
detection_method TEXT NOT NULL, -- 'multi_touch','retest','htf_hl','volume_profile','round_number','fibonacci','ath','cycle_hl','ob_wall','liq_cluster'
score REAL NOT NULL, -- 0-100 + bonuses
touch_count INTEGER DEFAULT 0,
first_detected_time INTEGER,
last_touched_time INTEGER,
is_active INTEGER DEFAULT 1, -- boolean
decay_factor REAL DEFAULT 1.0,
liq_cluster_present INTEGER DEFAULT 0, -- boolean
ob_wall_present INTEGER DEFAULT 0,
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE INDEX idx_sr_zones_symbol_tf ON sr_zones(symbol, timeframe, is_active, score DESC);
-- orderflow.db
CREATE TABLE funding_oi_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
recorded_time INTEGER NOT NULL,
funding_rate_current REAL,
funding_rate_predicted REAL,
funding_rate_annualized REAL,
funding_rate_percentile_30d REAL, -- 0-100, replaces z-score
funding_extreme_long INTEGER, -- boolean
funding_extreme_short INTEGER,
funding_flip INTEGER,
funding_near_settlement INTEGER, -- boolean: within 60min of 8h settlement
open_interest_usd REAL,
oi_change_1h_pct REAL,
oi_change_4h_pct REAL,
oi_change_24h_pct REAL,
oi_vs_price_divergence INTEGER, -- boolean
oi_percentile_90d REAL,
long_short_ratio_accounts REAL,
long_short_ratio_positions REAL,
top_trader_long_short_ratio REAL,
retail_vs_whale_divergence INTEGER,
long_short_percentile_30d REAL,
data_source TEXT DEFAULT 'binance',
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, recorded_time)
);
CREATE INDEX idx_funding_oi_symbol_time ON funding_oi_data(symbol, recorded_time DESC);
CREATE TABLE liquidation_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
recorded_time INTEGER NOT NULL,
liquidations_long_1h_usd REAL,
liquidations_short_1h_usd REAL,
liquidation_ratio REAL, -- long_liq / total_liq
liquidation_spike INTEGER, -- boolean
cumulative_liquidations_24h_usd REAL,
liquidation_data_quality TEXT DEFAULT 'realtime', -- 'realtime','lagged_5min','lagged_15min','degraded'
data_source TEXT DEFAULT 'coinglass',
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, recorded_time)
);
CREATE TABLE perp_basis_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
recorded_time INTEGER NOT NULL,
perp_basis_pct REAL,
perp_basis_zscore_24h REAL,
perp_basis_zscore_7d REAL,
perp_basis_annualized REAL,
perp_basis_extreme_long INTEGER, -- boolean
perp_basis_extreme_short INTEGER,
perp_basis_flip INTEGER,
basis_funding_agreement INTEGER, -- boolean
basis_funding_divergence INTEGER,
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, recorded_time)
);
CREATE TABLE order_book_snapshots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
snapshot_time INTEGER NOT NULL,
ob_bid_depth_1pct REAL,
ob_ask_depth_1pct REAL,
ob_bid_depth_5pct REAL,
ob_ask_depth_5pct REAL,
ob_imbalance_1pct REAL, -- 0-1, bid/(bid+ask)
ob_imbalance_5pct REAL,
ob_bid_wall_price REAL,
ob_ask_wall_price REAL,
ob_bid_wall_size_usd REAL,
ob_ask_wall_size_usd REAL,
ob_wall_persistent INTEGER, -- boolean: wall present for >10 consecutive snapshots
ob_wall_at_sr_zone INTEGER, -- boolean: wall within 0.1*ATR of SR zone score>50
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, snapshot_time)
);
CREATE TABLE estimated_liquidation_levels (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
calculated_time INTEGER NOT NULL,
liq_cluster_long_1_price REAL,
liq_cluster_long_2_price REAL,
liq_cluster_long_3_price REAL,
liq_cluster_short_1_price REAL,
liq_cluster_short_2_price REAL,
liq_cluster_short_3_price REAL,
liq_cluster_long_total_usd REAL,
liq_cluster_short_total_usd REAL,
liq_magnet_direction TEXT, -- 'long_liq_below','short_liq_above','balanced'
liq_cluster_at_sr_zone INTEGER, -- boolean
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, calculated_time)
);
CREATE TABLE whale_transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
tx_timestamp INTEGER NOT NULL,
asset TEXT NOT NULL,
amount_usd REAL NOT NULL,
from_type TEXT, -- 'exchange','unknown_wallet','known_entity'
to_type TEXT,
direction TEXT, -- 'to_exchange','from_exchange','exchange_to_exchange','wallet_to_wallet'
source TEXT DEFAULT 'whale_alert',
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE whale_flow_aggregates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
window_end_time INTEGER NOT NULL,
whale_exchange_inflow_1h_usd REAL,
whale_exchange_outflow_1h_usd REAL,
whale_net_flow_1h_usd REAL, -- positive = net inflow (bearish)
whale_flow_percentile_24h REAL, -- 0-100
whale_deposit_at_resistance INTEGER, -- boolean
whale_withdrawal_at_support INTEGER,
whale_data_available INTEGER DEFAULT 1, -- boolean flag
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, window_end_time)
);
CREATE TABLE exchange_flow_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
recorded_time INTEGER NOT NULL,
exchange_netflow_usd REAL,
exchange_reserve_usd REAL,
exchange_reserve_change_7d_pct REAL,
miner_outflow_24h_btc REAL, -- BTC only
miner_outflow_7d_btc REAL,
miner_outflow_percentile_30d REAL,
stablecoin_reserve_ratio REAL, -- USDT+USDC on exchanges / total supply
reserve_ratio_change_7d REAL,
data_source TEXT,
exchange_flow_available INTEGER DEFAULT 1, -- boolean flag
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, recorded_time)
);
-- context.db
CREATE TABLE cross_market_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
recorded_time INTEGER NOT NULL,
-- TradFi
sp500_price REAL,
nasdaq_price REAL,
vix_price REAL,
dxy_price REAL,
us_2y_yield REAL,
us_10y_yield REAL,
us_yield_curve_slope REAL,
yield_momentum_5d REAL,
gold_price REAL,
-- Crypto cross-market
btc_dominance REAL,
btc_dominance_roc_7d REAL,
eth_btc_ratio REAL,
usdt_market_cap REAL,
usdc_market_cap REAL,
stablecoin_supply_change_7d_pct REAL,
usdt_usd_premium REAL, -- stablecoin peg monitoring
-- Gas fees
eth_gas_price_gwei REAL,
eth_gas_percentile_90d REAL,
eth_gas_spike INTEGER, -- boolean: >200 gwei
sol_priority_fee_avg REAL,
-- Volatility
btc_realized_vol_30d REAL,
dvol REAL, -- Deribit BTC vol index
-- Staking
staked_eth_pct REAL,
staked_sol_pct REAL,
lido_apy_7d REAL,
-- Composite scores
risk_on_off_score REAL, -- -5 to +5
crypto_risk_score REAL,
-- Data quality
cross_market_data_fresh INTEGER DEFAULT 1, -- boolean: false outside US market hours
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(recorded_time)
);
CREATE TABLE crypto_relative_strength (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
recorded_time INTEGER NOT NULL,
asset_strength_roc_24h REAL,
asset_strength_vs_btc_24h REAL,
asset_strength_percentile_30d REAL,
asset_strength_rank INTEGER,
altcoin_avg_strength_vs_btc REAL, -- only on non-BTC assets; same value for all alts
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, recorded_time)
);
CREATE TABLE session_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
session_name TEXT NOT NULL, -- 'asia','europe','us','overlap','offhours','weekend_sat','weekend_sun'
session_date TEXT NOT NULL, -- UTC date YYYY-MM-DD
session_open_price REAL,
session_high REAL,
session_low REAL,
session_close REAL,
session_range_pct REAL,
session_direction INTEGER, -- 1 bull, -1 bear, 0 neutral
session_volume REAL,
asia_compression INTEGER, -- boolean: range < 20th percentile
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, session_name, session_date)
);
CREATE TABLE cme_gaps (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
gap_open_time INTEGER NOT NULL,
gap_close_time INTEGER,
gap_direction INTEGER, -- 1 bullish gap (opened higher), -1 bearish
gap_size_pct REAL,
gap_filled INTEGER DEFAULT 0, -- boolean
gap_fill_hours REAL,
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE economic_calendar (
id INTEGER PRIMARY KEY AUTOINCREMENT,
event_name TEXT NOT NULL,
event_time INTEGER NOT NULL,
event_type TEXT NOT NULL, -- 'fomc','cpi','nfp','eth_upgrade','sec_hearing','token_unlock','etf_flow','btc_halving','cme_settlement'
symbol TEXT, -- NULL for macro events
actual_value REAL,
forecast_value REAL,
surprise_direction INTEGER, -- 1 hawkish/positive, -1 dovish/negative
fwd_move_5min_pct REAL,
fwd_move_30min_pct REAL,
fwd_move_1h_pct REAL,
fwd_move_4h_pct REAL,
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(event_name, event_time)
);
CREATE TABLE fear_greed_index (
id INTEGER PRIMARY KEY AUTOINCREMENT,
recorded_date TEXT NOT NULL, -- YYYY-MM-DD (daily pull)
fng_value INTEGER NOT NULL, -- 0-100
fng_classification TEXT NOT NULL, -- 'extreme_fear','fear','neutral','greed','extreme_greed'
fng_percentile_90d REAL,
fng_extreme_fear INTEGER, -- boolean: value < 15
fng_extreme_greed INTEGER, -- boolean: value > 85
fng_flip INTEGER, -- boolean: classification changed from previous day
fng_extreme_at_sr_zone INTEGER, -- boolean: FNG extreme AND price testing SR zone score>60
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(recorded_date)
);
CREATE TABLE data_health_dashboard (
id INTEGER PRIMARY KEY AUTOINCREMENT,
source_name TEXT NOT NULL UNIQUE,
status TEXT DEFAULT 'healthy', -- 'healthy','degraded','down'
last_successful_pull INTEGER,
consecutive_failures INTEGER DEFAULT 0,
fallback_active INTEGER DEFAULT 0, -- boolean
updated_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE heartbeat (
id INTEGER PRIMARY KEY AUTOINCREMENT,
process_name TEXT NOT NULL,
heartbeat_time INTEGER NOT NULL,
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE data_gaps (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
gap_start INTEGER NOT NULL,
gap_end INTEGER NOT NULL,
gap_duration_minutes REAL,
backfill_successful INTEGER DEFAULT 0,
affected_rolling_calculations TEXT, -- JSON array
created_at INTEGER DEFAULT (strftime('%s','now'))
);
CREATE TABLE anomaly_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
detected_time INTEGER NOT NULL,
source TEXT NOT NULL,
field_name TEXT NOT NULL,
expected_range TEXT,
actual_value REAL,
action_taken TEXT NOT NULL, -- 'stored_with_flag','replaced_with_null','backfilled_from_secondary'
created_at INTEGER DEFAULT (strftime('%s','now'))
);
-- Closed-period structure (separate from main candles — only populated on period close)
CREATE TABLE closed_period_structure (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
timeframe TEXT NOT NULL,
period_close_time INTEGER NOT NULL,
open REAL, high REAL, low REAL, close REAL, volume REAL,
body_size_pct REAL,
upper_wick_pct REAL,
lower_wick_pct REAL,
candle_type TEXT, -- 'bullish_marubozu','doji','hammer','shooting_star', etc.
nrr_daily_weekly REAL,
nrr_weekly_monthly REAL,
emr REAL, -- Efficient Market Range
fvg_present INTEGER, -- boolean: Fair Value Gap
volume_price_divergence INTEGER, -- boolean
-- Forward returns (filled later)
fwd_return_1h_pct REAL,
fwd_return_4h_pct REAL,
fwd_return_24h_pct REAL,
fwd_return_7d_pct REAL,
created_at INTEGER DEFAULT (strftime('%s','now')),
UNIQUE(symbol, timeframe, period_close_time)
);
| Data | Primary Source | Fallback 1 | Fallback 2 | Cadence |
|---|---|---|---|---|
| OHLCV candles | Binance WebSocket | Coinbase REST | CoinGecko | Every candle close |
| Open interest | Binance Futures REST | Bybit | OKX | Every 15 minutes |
| Funding rates | Binance WebSocket (markPrice) | Bybit | Coinglass | Continuous (1min store) |
| Liquidations | Binance WebSocket (forceOrder) | Coinglass REST (5-15min lag) | — | Continuous (5min aggregate) |
| Long/short ratios | Binance Futures REST | Bybit | — | Every 15 minutes |
| Order book depth | Binance WebSocket (depth20) | Binance REST snapshot | — | Every 60 seconds |
| Perp basis | Calculated (spot - futures) | — | — | Every 1 minute |
| Exchange flows | CryptoQuant (paid: $30/mo) | Custom wallet tracking | — | Daily (free) / 30min (paid) |
| Miner flows | CryptoQuant free | Glassnode | — | Daily |
| Whale alerts | Whale Alert API (free, 10/min) | — | — | Every 60 seconds |
| BTC dominance | CoinGecko API | CoinMarketCap | — | Every 15 minutes |
| Stablecoin supply | DefiLlama API | CoinGecko | — | Daily |
| Stablecoin peg | Binance Spot USDT/USDC pairs | Coinbase | — | Every 15 minutes |
| ETH gas fees | Etherscan API (free) | Alchemy API | — | Every 15 minutes |
| SOL fees | Solana RPC (free) | — | — | Every 15 minutes |
| Staking metrics | Lido API (free) | StakingRewards API | — | Every 1 hour |
| Fear & Greed | Alternative.me API (free, no auth) | — | — | Daily |
| TradFi cross-market | Yahoo Finance | Alpha Vantage | — | Every 15 min (US hours only) |
| Deribit DVOL | Deribit API (free) | — | — | Every 15 minutes |
| Economic calendar | Manual JSON + RSS feeds | Forex Factory scraping | — | Daily |
| CME gaps | Calculated from OHLCV | — | — | Sunday open detection |
| Data Type | How Often |
|---|---|
| Price candles + indicators | Every candle close (per timeframe) |
| Order book depth snapshots | Every 60 seconds |
| Perp basis | Every 1 minute |
| Open interest | Every 15 minutes |
| Liquidation aggregates | Every 5 minutes |
| Long/short ratios | Every 15 minutes |
| Funding rates (stored) | Every 1 hour (live stream updates continuously) |
| Whale transactions | Continuous (poll every 60 seconds) |
| Whale flow aggregates | Every 1 hour |
| Exchange flows | Daily (free tier) or every 30 minutes (paid) |
| Cross-market TradFi | Every 15 minutes (US market hours only) |
| Crypto cross-market (BTC dominance, stablecoins) | Every 15 minutes |
| Gas fees (ETH/SOL) | Every 15 minutes |
| Session metrics | Continuously, summarized at session boundary |
| Economic calendar | Daily pull, update every 6 hours |
| Fear & Greed Index | Daily |
| Derived metrics / forward returns | Daily recalculation |
| Estimated liquidation levels | Every 15 minutes |
| Heartbeat | Every 60 seconds |
24/7/365 — never sleeps.
| Database | Tables | Estimated rows/day (15 assets) | 90-day estimate |
|---|---|---|---|
| candles.db | crypto_candles | ~3,600 (all TFs) | ~540MB |
| events.db | st_flips + 4 event tables | ~200-500 events | ~30MB |
| orderflow.db | 7 tables | ~30,000 rows | ~1.2GB |
| context.db | 8 tables | ~3,000 rows | ~150MB |
| Total | ~2GB at 90 days |
With WAL mode and proper indexing, 2GB SQLite is manageable on the VPS (15GB free disk). Run VACUUM monthly.
Minor tweak
cme_gap_pct, cme_gap_filled, cme_gap_fill_hours. Remove regular spot gap analysis.nrr_daily_weekly = Daily Range% / (Weekly Range% / 7). Monthly: nrr_weekly_monthly = Weekly Range% / (Monthly Range% / 4.33).All 12 subsections of calculations (base structure, close dynamics, candle body analysis, range dynamics, structural classifications, failure patterns, momentum/velocity, composite scores, cross-TF alignment). Math is entirely OHLCV-based and transfers directly.
Minor tweak + additions
Remove from v1: order blocks (overlaps with volume profile), liquidity sweeps (overlaps with liquidation cluster mapping), dynamic-to-static conversion (edge case).
Keep from forex (7 methods):
New crypto-specific methods (2 methods): 8. Order book walls (Method 11) — from Section 7.7. Weight 1.5x. Only promotes to S&R candidate if wall persists >10 consecutive snapshots. 9. Estimated liquidation clusters (Method 12) — from Section 7.9. Weight 2.0x. Identifies levels where future liquidations will trigger — a leading indicator.
Crypto-Specific S&R Levels (feed as additional inputs to Method 3/HTF):
All 10 original detection methods' scoring formula (0-100 + bonuses), clustering logic, decay/expiration, timeframe hierarchy, cross-reference with structure table, zone validation. The engine architecture is unchanged — just swap inputs.
Major rewrite
Cross-section flags require ALL their data sources to be healthy. If any required source is in 'degraded' or 'unavailable' state, the flag outputs null instead of a potentially incorrect boolean. A flag that confidently says true based on stale data is WORSE than no flag.
funding_oi_st_aligned: boolean — all three pointing same direction?funding_oi_st_divergence: boolean — any one going opposite?basis_funding_agreement: from Section 7.8 — basis and funding both confirm positioning directionbtc_dxy_agreement: boolean — BTC rising + DXY falling = normal inverse. BTC rising + DXY rising = divergence.btc_dxy_divergence_days: how many days has divergence lasted?liquidation_cluster_at_zone: boolean — large liquidation levels clustered near active S&R zone?funding_at_zone_test: funding rate when price is testing a key zone. Extreme funding at zone test = higher probability of sweep/reversal.liq_cluster_at_sr_zone: from Section 7.9 — estimated liquidation cluster within 0.5*ATR of SR zone score>40altcoin_move_source: 'btc_dragging' vs 'genuine_alt_strength' vs 'both'pre_event_compression: keep — works the same waypre_event_funding_extreme: boolean — is funding extremely one-sided heading into a major event? (amplifies post-event move)funding_at_risk: boolean — funding rates extremely positive AND risk regime shifting to risk-off?zone_test_during_us_hours: boolean — zone tested during US session (highest volume)?zone_test_weekend: boolean — zone tested Saturday/Sunday (lowest volume, likely noise)?whale_deposit_at_resistance: boolean — whale_exchange_inflow_1h_usd > 2x its 7-day hourly average AND price within 0.5*ATR of resistance zone score>50. Requires whale_data_available = true.whale_withdrawal_at_support: same logic for outflows at support zones.ob_wall_at_sr_zone: from Section 7.7 — order book wall within 0.1*ATR of SR zone score>50.exchange_inflow_spike_at_resistance: coins flooding into exchanges while price tests resistance = distribution, zone likely holdsexchange_outflow_spike_at_support: coins leaving exchanges at support = accumulation, zone likely holds. Requires exchange_flow_available = true.fng_extreme_at_sr_zone: boolean — FNG is at extreme (<15 or >85) AND price is testing a major S&R zone (score >60). High-probability reversal setup. Requires fng_value to be populated (free daily API call).Major rewrite
social_volume_24h, sentiment_score_24h, sentiment_spike_zscore_7d. Add boolean sentiment_extreme for z-score >2.0.Free, single API call, 15-minute implementation, surprisingly effective contrarian indicator at extremes (>90 = sell signal, <10 = buy signal). Extreme Fear (<15) has historically preceded BTC rallies with ~75% accuracy over 30-day forward returns. Collect from day one.
[PANEL: Opus A+] Fear & Greed to Phase 1: There is zero reason this is not in Phase 1. Call alternative.me/crypto/fear-and-greed-index/ daily, store in fear_greed_index table. 2 hours to implement.
[PANEL: Opus A+] Define fallback for every data source:
| Source | Health Check | Fallback | Graceful Degradation |
|---|---|---|---|
| Binance OHLCV | 3 consecutive failures OR latency >5s OR stale >2x interval | Coinbase REST → CoinGecko | data_source field logged per record |
| Binance Futures OI | Same | Bybit OI API → Coinglass aggregated OI | Set oi_data_quality = 'degraded' |
| Binance funding | Same | Bybit funding → Coinglass funding | Skip funding_near_settlement signal |
| Coinglass liquidations | 429 errors or 15min+ staleness | Binance forceOrder WebSocket only | Set liquidation_data_quality = 'degraded', directional signals only |
| CryptoQuant exchange flows | Free tier limit hit | Custom on-chain tracker | Set exchange_flow_available = false, skip exchange flow cross-section flags |
| Whale Alert | 429 or stale | None (non-critical) | Set whale_data_available = false, skip whale flags |
| CoinGecko BTC dominance | Consecutive failures | CoinMarketCap API | Skip altcoin_move_source flag |
| DefiLlama stablecoins | Consecutive failures | CoinGecko | Use last known value with staleness flag |
Data source circuit breaker: If primary fails, auto-switch with logging. Cache last successful pull for up to 5 minutes max before marking as 'degraded'. Log every switch in data_health_dashboard table.
[PANEL: Opus A+] Process supervision specification:
Restart=always, RestartSec=5, WatchdogSec=300 (kills process if no heartbeat in 5 minutes)heartbeat table every 60 seconds. Gaps >120 seconds trigger a data_gap event.data_gaps table with backfill_successful flag.recalculated_after_gap = true.[PANEL: Opus A+] Data quality rules:
For every numeric field written to any database, define valid ranges and anomaly detection:
close deviates >20% from previous candle's close on any timeframe ≥1H, flag as potential_bad_data and cross-check against Coinbase before storing.volume is exactly 0 on any candle for BTC/ETH, flag and investigate.funding_rate_current exceeds ±1% per 8h, flag for review.cross_source_price_divergence.Store all anomaly flags in anomaly_log table.
[PANEL: GPT-4.1] Schema validation layer: Add explicit schema validation, type checking, and field sanity checks BEFORE writing to DB and BEFORE analytics consume the data.
[PANEL: Grok 4.1 Fast] Data quality checksum: Define what "bad data" means per field (missing candles, price deviation >10% in 1-min candle, exchange divergence >2%, liquidation data >1 hour stale). Set thresholds and auto-alert when violated. Prevents garbage signals from garbage data.
| Section | Change Level | Key Difference |
|---|---|---|
| 1. SuperTrend + ATR | Minor tweak | Single multiplier (3x), ATR-only stop buffer |
| 2. Trend Lines | Minor tweak | ZigZag Deviation 5 (all assets), 2 line sets |
| 3. Event Timing | No change | All measurements are candle/ATR-relative |
| 4. RSI Divergences | No change | Asset-agnostic |
| 5. Other Indicators | Minor tweak | VWAP 24h/weekly only, round numbers, crypto pairs |
| 6. Confluence Events | Minor tweak | Higher volume spike thresholds, context-aware |
| 7. Order Flow | Major rewrite + additions | Funding, OI, liq, order book, perp basis, liq levels, whale alerts |
| 8. Cross-Market | Major rewrite | BTC dominance, gas fees (replace TVL), stablecoin peg |
| 9. Currency Strength | Major rewrite | Crypto relative strength only, no sector rotation |
| 10. Sessions | Major rewrite | Hard UTC windows, 24/7, weekend tracking, CME gaps |
| 11. Volatility Regime | Minor tweak | 365-day lookback, same percentile logic |
| 12. Economic Calendar | Minor tweak | Drop non-US, add halvings, token unlocks, ETF flows |
| 13. Seasonal Patterns | Minor tweak | Weekends, halving cycle, backtest before signaling |
| 14. Derived Metrics | Minor tweak | Percentage returns, crypto correlations |
| 15. Data Storage | Minor tweak + major ops | 4 DB architecture, WAL, full SQL schema |
| 16. Structure Table | Minor tweak | UTC periods, CME gaps, 7-day NRR |
| 17. S&R Engine | Minor tweak + 2 new methods | 9 methods, order book walls, liq cluster mapping |
| 18. Cross-Section Flags | Major rewrite | Funding/OI/liq/whale/FNG-based flags |
| 19. Future Data | Major rewrite | On-chain analytics, Deribit options, social, Fear & Greed to Phase 1 |
| Ops | NEW | Data source fallbacks, 24/7 supervision, anomaly detection |
The build order below synthesizes the Opus A+ build order with refinements from the panel:
| Step | Component | Key APIs | Effort | Dependencies |
|---|---|---|---|---|
| 1 | SQLite schema setup (all 4 databases, WAL mode, indexes) | None | 3-5 days | None |
| 2 | Binance WebSocket pipeline: OHLCV, candlestick streams for BTC/ETH/SOL. Core indicators: SuperTrend 3x, ATR, RSI, MACD, BB, SMAs, ADX | Binance WS | 1-2 weeks | Step 1 |
| 3 | Funding rates + Open Interest (via WebSocket markPrice + REST OI snapshots). Perp basis calculation. | Binance WS + REST | 2-3 days | Step 2 |
| 4 | SuperTrend flip events → outcome tracking (record MFE, MAE, forward returns). Start accumulating training data immediately. | None | 3-5 days | Steps 1-2 |
| 5 | Liquidation data (Binance forceOrder WebSocket + Coinglass REST). Long/short ratios. | Binance WS + Coinglass | 2-3 days | Step 1 |
| 6 | Order book depth snapshots (depth20 WebSocket). Order book imbalance. Maker/taker volume ratios. | Binance WS | 2-3 days | Step 1 |
| 7 | Fear & Greed Index (2-hour implementation). | alternative.me | 2 hours | Step 1 |
| 8 | Estimated liquidation level mapping (from existing OI + funding + price data). | Calculated | 1 week | Steps 3-5 |
| 9 | Whale Alert integration (60-second polling, transaction logging, 1h flow aggregates). | Whale Alert free | 2-3 days | Step 1 |
| 10 | Basic S&R zones: multi-touch horizontals, volume profile, round numbers (crypto grids), HTF highs/lows, ATH. Score 0-100. | None | 1-2 weeks | Steps 2, 4 (need historical data) |
| 11 | Cross-market data: TradFi (DXY, S&P, VIX, gold, yields via Yahoo Finance). Crypto (BTC dominance, stablecoin supply, peg deviation, ETH gas, SOL fees). | CoinGecko, Etherscan, Solana RPC | 3-5 days | Step 1 |
| 12 | Session tracking (hard UTC windows), CME gap detection, weekend pattern logging. | None | 3-5 days | Step 2 |
| 13 | Economic calendar (manual JSON, FOMC/CPI/NFP + crypto events). | Manual + RSS | 1-3 days | Step 1 |
| 14 | RSI divergences + trend lines (2 methods: ZZ+HTF and HTF-only). | None | 1-2 weeks | Steps 2, 4 |
| 15 | Confluence scoring, cross-section intelligence flags (all 18.x flags). | All prior | 1 week | Steps 3-14 |
| 16 | Crypto relative strength rankings. altcoin_avg_strength_vs_btc. ETH/BTC ratio SuperTrend. | None | 3-5 days | Step 2 |
| 17 | Data source degradation/fallback system. Heartbeat, gap detection, memory monitoring, anomaly detection. | All | 1 week | Steps 1-16 |
| 18 | Expand to full altcoin list (config-driven). Scale all Step 2-16 logic horizontally. | All | 3-5 days | Steps 1-17 stable |
| 19 | Exchange flows (paid CryptoQuant or custom on-chain wallet tracking). Miner flows. Stablecoin reserve ratio. | CryptoQuant or Blockchain.com | 1-2 weeks | Budget decision required |
| 20 | Closed-period structure table, NRR, FVG detection, candle body analysis, EMR, forward returns. | None | 1-2 weeks | Step 2 + 2 weeks of data |
Phase 1 (MVP, ~6 weeks): Steps 1-12. Produces: live price data, core TA signals, crypto-native order flow signals (funding/OI/liquidations), order book depth, Fear & Greed, basic S&R zones, cross-market context, sessions.
Phase 2 (~4 weeks after Phase 1 stable): Steps 13-18. Wires up confluence scoring, intelligence flags, relative strength, all cross-section analysis.
Phase 3 (~2 weeks, budget-dependent): Steps 19-20. Exchange flows require either paid API or custom work. Closed-period structure needs accumulated historical data.
| Component | Reusable For |
|---|---|
| Binance/Exchange WebSocket infrastructure + reconnection logic | Forex (OANDA WebSocket), stocks, futures |
| SuperTrend + ATR calculation engine | Forex (identical), stocks, futures, any OHLCV market |
| S&R zone detection engine (multi-method, scoring, clustering) | Forex (base spec), stocks, futures, options (strike selection) |
| RSI divergence detection algorithm | Forex, stocks, futures, any OHLCV market |
| Cross-market data collection (DXY, VIX, S&P, gold, Treasury yields) | Forex (same data), stocks (VIX/yields critical), futures |
| Volatility regime classification (percentile, Kaufman ER, fractal dimension) | Forex, stocks, futures, options (vol regime drives strategy) |
| Event timing correlation framework (pairing events within N-candle windows) | Forex, stocks, sports betting (game event correlations), prediction markets |
| Economic calendar parsing + alert system | Forex (same events), stocks, futures, prediction markets |
| SQLite WAL-mode + multi-database + batch-write infrastructure | All desks — shared infrastructure |
| API rate-limit manager + circuit breaker + fallback logic | All desks |
| Time-series analysis utilities (rolling percentiles, z-scores, regime detection, lag/lead) | All desks |
| Confluence scoring framework (-5 to +5 per indicator, composite) | Forex, stocks, any multi-indicator system |
| Forward return tracking (MFE, MAE, R-multiple hits, Brier scores) | All desks — the accountability layer |
| Session/timezone handling utilities (UTC conversion, session boundaries, overlap detection) | Forex, stocks |
| Fear & Greed Index collection | Stocks (CNN Fear & Greed Index is equity equivalent), prediction markets |
| Data health dashboard + anomaly detection layer | All desks |
| Backtest harness (event-based replay, forward return calculation, Brier scoring) | All desks |
Use this as the coding bot's task list. Check off as each item is verified in production.
atr_14_percentile_90d updatingfunding_near_settlement flag (60-min window)basis_funding_agreement flag workingob_imbalance_1pct calculating correctlyob_wall_persistent flag working (>10 consecutive snapshots)fng_extreme_fear and fng_extreme_greed flags workingliq_magnet_direction flag workingusdt_usd_premium) trackingcross_market_data_fresh flag correctly set outside US hoursasia_compression flag workingcme_gap_filled trackingfomc_week, cpi_day, nfp_friday flags workingbtc_halving_countdown alerting only within 60 daysdata_health_dashboard table populating for all sourceshit_2r through hit_6r flags workingwhale_deposit_at_resistance flag workingwhale_data_available flag correctly propagatingaltcoin_avg_strength_vs_btc metric workingasset_strength_rank updating every 5 minutesstaking_spike_bullish flag workinganomaly_log table-- Get last 24h of BTC funding with perp basis
SELECT
fod.recorded_time,
fod.funding_rate_current,
fod.funding_rate_percentile_30d,
fod.funding_extreme_long,
fod.funding_near_settlement,
pbd.perp_basis_pct,
pbd.perp_basis_annualized,
pbd.basis_funding_agreement
FROM funding_oi_data fod
LEFT JOIN perp_basis_data pbd ON pbd.symbol = fod.symbol
AND pbd.recorded_time BETWEEN fod.recorded_time - 60 AND fod.recorded_time + 60
WHERE fod.symbol = 'BTCUSDT'
AND fod.recorded_time > strftime('%s','now') - 86400
ORDER BY fod.recorded_time DESC;
-- Get active SR zones near current price
SELECT
zone_low, zone_high, zone_type, detection_method, score,
touch_count, liq_cluster_present, ob_wall_present,
(zone_low + zone_high) / 2 as zone_mid
FROM sr_zones
WHERE symbol = 'BTCUSDT'
AND timeframe = '1h'
AND is_active = 1
AND zone_low < (SELECT close FROM crypto_candles WHERE symbol='BTCUSDT' AND timeframe='1h' ORDER BY open_time DESC LIMIT 1) * 1.02
AND zone_high > (SELECT close FROM crypto_candles WHERE symbol='BTCUSDT' AND timeframe='1h' ORDER BY open_time DESC LIMIT 1) * 0.98
ORDER BY score DESC;
-- SuperTrend flip performance by timeframe (last 90 days)
SELECT
timeframe,
flip_direction,
COUNT(*) as total_flips,
AVG(fwd_return_24h_pct) as avg_24h_return,
AVG(mfe_pct) as avg_mfe,
AVG(mae_pct) as avg_mae,
SUM(hit_2r) * 1.0 / COUNT(*) as hit_rate_2r,
SUM(hit_3r) * 1.0 / COUNT(*) as hit_rate_3r
FROM st_flip_events
WHERE symbol = 'BTCUSDT'
AND flip_time > strftime('%s','now') - 7776000 -- 90 days
AND fwd_return_24h_pct IS NOT NULL
GROUP BY timeframe, flip_direction
ORDER BY timeframe, flip_direction;
-- Liquidation cascade alert (significant one-sided liquidation spike)
SELECT
symbol,
recorded_time,
liquidations_long_1h_usd,
liquidations_short_1h_usd,
liquidation_ratio,
liquidation_data_quality
FROM liquidation_data
WHERE liquidation_spike = 1
AND recorded_time > strftime('%s','now') - 3600
ORDER BY recorded_time DESC;
-- Data health status for all sources
SELECT
source_name,
status,
consecutive_failures,
fallback_active,
datetime(last_successful_pull, 'unixepoch') as last_pull_utc,
(strftime('%s','now') - last_successful_pull) / 60 as minutes_since_pull
FROM data_health_dashboard
ORDER BY status DESC, consecutive_failures DESC;
-- Detect SR zone + liquidation cluster alignment (high-conviction levels)
SELECT
sz.symbol,
sz.zone_low,
sz.zone_high,
sz.score,
sz.detection_method,
ell.liq_cluster_long_total_usd,
ell.liq_cluster_short_total_usd,
ell.liq_magnet_direction
FROM sr_zones sz
CROSS JOIN (
SELECT * FROM estimated_liquidation_levels
WHERE symbol = sz.symbol
ORDER BY calculated_time DESC LIMIT 1
) ell
WHERE sz.symbol = 'BTCUSDT'
AND sz.is_active = 1
AND sz.liq_cluster_present = 1
AND sz.score > 50
ORDER BY sz.score DESC;
-- Session performance analysis
SELECT
session_name,
AVG(session_range_pct) as avg_range_pct,
COUNT(CASE WHEN session_direction = 1 THEN 1 END) * 100.0 / COUNT(*) as pct_bullish,
COUNT(CASE WHEN asia_compression = 1 THEN 1 END) * 100.0 / COUNT(*) as pct_compressed
FROM session_data
WHERE symbol = 'BTCUSDT'
AND session_date >= date('now', '-90 days')
GROUP BY session_name
ORDER BY avg_range_pct DESC;
-- Fear & Greed extreme readings with forward BTC performance
-- (manual join to candles needed — run after populating fng_extreme_at_sr_zone)
SELECT
fgi.recorded_date,
fgi.fng_value,
fgi.fng_classification,
fgi.fng_extreme_at_sr_zone
FROM fear_greed_index fgi
WHERE fgi.fng_value < 15 OR fgi.fng_value > 85
ORDER BY fgi.recorded_date DESC
LIMIT 30;
-- Recent anomalies
SELECT
datetime(detected_time, 'unixepoch') as detected_at,
source,
field_name,
actual_value,
action_taken
FROM anomaly_log
ORDER BY detected_time DESC
LIMIT 50;
SQLite ceiling: Multi-database WAL architecture with 30-second batch writes should handle 90+ days of data. If write contention remains an issue at scale, migrate orderflow.db to DuckDB (same single-file simplicity, much better at bulk inserts).
CryptoQuant free tier: Daily granularity only, significantly delayed. Exchange flows at the polling cadence in the spec require either their $30/month plan or custom on-chain wallet tracking. This is not optional — the spec depends on exchange flow direction for several intelligence flags. Budget accordingly.
Liquidation data accuracy: Binance's forceOrder WebSocket stream shows a fraction of actual liquidations (they batch and delay). Coinglass has 5-15 minute lag. Use both as directional signals only — do NOT build signals that depend on exact liquidation dollar amounts.
BTC/S&P correlation instability: Range is -0.3 to +0.8 depending on macro regime. Never assume high correlation. Always read btc_sp500_corr_20d as the actual value and flag when it deviates from its own 30-day norm.
Realized price on-chain data: Only available for BTC and ETH on free Glassnode tier. For altcoins, use 155-day VWAP as a rough STH cost basis proxy — not as accurate, but directionally correct.
Seasonal patterns have weak statistical backing: Q4 rally, January effect, tax season — collect the data but do NOT generate trading signals until formally backtested on 10+ years of data with p-value <0.05.
API rate limit summary: Binance REST allows 1,200 requests/minute (weighted). The WebSocket-first architecture in this spec keeps REST calls to historical backfill and OI snapshots only — far below limits. Monitor the data_health_dashboard table for rate limit signals.
| Source | Table | Cadence | Status |
|---|---|---|---|
| Binance OHLCV (multi-TF) | ta_crypto_ohlcv | 5 min | FLOWING |
| Binance funding rates | ta_crypto_funding | 5 min | FLOWING |
| Binance open interest | ta_crypto_oi | 5 min | FLOWING |
| CoinGecko (dominance, F&G) | crypto_* tables (from Crypto desk) | 4-hourly | FLOWING |
| Deribit IV (BTC+ETH) | ta_deribit_iv | 30 min | BUILT |
Panel-mandated source change: CoinGecko -> Binance for OHLCV -- DONE.
src/pipeline/ta/crypto-data.ts -- Binance data collectorsrc/pipeline/ta/plugins/crypto-metrics.ts -- 8 proprietary metricssrc/pipeline/ta/plugins/crypto-overlay.ts -- funding, OI, dominance, stablecoin peg, CME gap| Metric | Status | Table |
|---|---|---|
| FRA (Funding Rate Acceleration) | Computing | ta_crypto_metrics |
| LCP (Liquidation Cascade Probability) | Computing | ta_crypto_metrics |
| PBTSS (Perp Basis Term Structure Slope) | Computing | ta_crypto_metrics |
| VRP + Deribit IV | Computing | ta_crypto_metrics + ta_deribit_iv |
| BTC Dominance Tracker | Computing | ta_crypto_overlay |
| Stablecoin Peg Monitor | Computing | ta_crypto_overlay |
| CME Gap Tracker | Computing | ta_crypto_overlay |
| WAZ (Whale Accumulation Z-Score) | STUBBED -- needs on-chain data | -- |
| SFV (Stablecoin Flow Velocity) | STUBBED -- needs on-chain data | -- |
| DLHI (DeFi Liquidity Health) | STUBBED -- needs DeFi Llama | -- |
| EFV (Exchange Flow Velocity) | STUBBED -- needs exchange balance data | -- |
BTCUSDT, ETHUSDT, SOLUSDT (primary) x 1h, 4h, 1d timeframes
| # | Model | Params | Type | In Ensemble | Latency |
|---|---|---|---|---|---|
| 1 | Chronos-T5-Small | 46M | General probabilistic | Yes | ~1s |
| 2 | Chronos-T5-Base | 200M | General probabilistic | Yes | ~3s |
| 3 | Chronos-2 | 120M | General probabilistic (v2) | Yes | ~0.1s |
| 4 | Kronos-mini | 4.1M | Finance OHLCV | Yes | ~0.5s |
| 5 | Kronos-base | 102M | Finance OHLCV | Yes | ~2s |
| 6 | Moirai v1.1 | ~300M | Multivariate | Yes | ~1.7s |
| 7 | TimesFM 2.5 | 200M | General (Google) | Yes | ~0.6s |
| 8 | Lag-Llama | ~10M | Probabilistic | On-demand | ~2s |
Forecasts persisted to ta_model_forecasts with Kronos OHLCV + derived candle shape.
Stubbed: TTM (Python 3.11), FinCast (no weights).
| Module | Table | What It Does |
|---|---|---|
| Dual SuperTrend (10/2+10/3) | ta_supertrend_flips | Flip events, direction, outcomes (2R-6R) |
| RSI crosses (8 pairs, 16 lines) | ta_rsi_crosses | Crossover events, dual stop tracking |
| Pullback monitor (5 methods) | ta_pullback_results | Pullback setups from recent flips |
| S&R Zone Engine (6 methods) | ta_sr_zones + events | Zones scored 0-100+, decay, lifecycle |
| Structure analysis | ta_closed_structure | Candle morphology, trend structure |
| Regime detection | ta_regime | Hurst, autocorrelation, ATR forecast |
| Liquidity sweeps | ta_liquidity_sweeps | Stop-hunt reversals |
| Fair value gaps | ta_fvg | Body gaps + fill tracking |
| Candle patterns (6 types) | ta_candle_patterns | Zone-gated pattern detection |
| RSI divergences (4 types) | ta_divergences | Z-score strength |
| Lead-lag | ta_lead_lag | Cross-instrument correlation |
| Confluence scoring | ta_confluence | -35 to +35 composite |
| Additional signals (5 types) | ta_signals | Composite entry signals |
| Order blocks | ta_sr_zones | Inside S&R engine |
src/pipeline/ta/collector.ts (wired into main.ts Step 9d)src/pipeline/ta/index.ts (barrel export)