""" CRE v1.0 — Central configuration. Single source of truth for runtime settings AND version-controlled strategy thresholds (spec §7). Engine code reads from here; never hard-codes a number. THRESHOLDS is snapshotted into config_versions at boot so every signal is traceable to the exact parameter set that produced it. Infra settings come from environment variables (HF Space Secrets/Variables); strategy thresholds are code-defined and version-bumped deliberately. """ from __future__ import annotations import os # ── Version ────────────────────────────────────────────────────────────────── APP_VERSION = "1.0" CONFIG_VERSION = 3 # bumped: engine thresholds + conviction ranking (no active cap) # ── Exchange / data source (spec §2, §12 geo-fallback) ─────────────────────── # OKX is the data source: the only free, geo-reachable exchange that preserves ALL # four layers — funding, OI, klines, liquidations (L1) and the taker buy/sell split # (L3). Binance/Bybit are geo-blocked on free hosts (451/403) and were removed in v1.0. EXCHANGE = os.getenv("EXCHANGE", "okx").lower().strip() # okx (only supported source) # ── Universe: dynamic whole-market scan with a quality funnel (D5) ──────────── # Mode "dynamic" = scan all USDT perps, keep the liquid ones. Mode "fixed" = # only the symbols in WATCHLIST. Setting WATCHLIST forces fixed mode. _WATCHLIST_ENV = os.getenv("WATCHLIST", "").strip() UNIVERSE_MODE = "fixed" if _WATCHLIST_ENV else os.getenv("UNIVERSE_MODE", "dynamic").lower() WATCHLIST = [s.strip().upper() for s in _WATCHLIST_ENV.split(",") if s.strip()] # Funnel parameters (the "remove the junk" filter). Tunable via env. UNIVERSE_MAX = int(os.getenv("UNIVERSE_MAX", "80")) # cap on coins scanned UNIVERSE_MIN_TURNOVER_USD = float(os.getenv("UNIVERSE_MIN_TURNOVER_USD", "20000000")) # min 24h USD turnover UNIVERSE_REFRESH_SEC = int(os.getenv("UNIVERSE_REFRESH_SEC", "3600")) # rebuild hourly # Bases excluded outright (stables / wrapped / non-tradeable noise). UNIVERSE_EXCLUDE_BASES = { "USDC", "USDT", "DAI", "TUSD", "FDUSD", "USDD", "USDE", "PYUSD", "EUR", "GUSD", "USTC", } # ── Per-pair links (D7) ────────────────────────────────────────────────────── # Where the "TV" link points. You trade on Bybit → default BYBIT. Switch freely. TV_EXCHANGE = os.getenv("TV_EXCHANGE", "BYBIT").upper().strip() # BYBIT|BINANCE|MEXC|OKX CHART_ENABLED = os.getenv("CHART_ENABLED", "1") == "1" # annotated screenshot on/off # ── Storage (spec §12 ephemeral-storage warning) ───────────────────────────── DB_PATH = os.getenv("DB_PATH", "./cre.db") # HF persistent storage → /data/cre.db # ── Polling cadence ────────────────────────────────────────────────────────── POLL_INTERVAL_SEC = int(os.getenv("POLL_INTERVAL_SEC", "60")) HTTP_TIMEOUT_SEC = float(os.getenv("HTTP_TIMEOUT_SEC", "15")) WS_BACKOFF_START = 1.0 WS_BACKOFF_CAP = 60.0 # ── Telegram alerts (spec §10) — SECRETS, never hard-code (D8) ──────────────── TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN", "").strip() TELEGRAM_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID", "").strip() ALERTS_ENABLED = bool(TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID) # ── Optional Coinglass enrichment (spec §2.2) ──────────────────────────────── COINGLASS_API_KEY = os.getenv("COINGLASS_API_KEY", "").strip() COINGLASS_ENABLED = bool(COINGLASS_API_KEY) # ── Liquidation baseline (spec §2.1, §15.3) ────────────────────────────────── LIQ_BASELINE_DAYS_REQUIRED = 7 # cold-start: WATCH-only until this many days collected # ── Strategy thresholds (version-controlled, spec §3–§6) ───────────────────── # Layer/scoring/risk thresholds (§3–§6) are appended in Step 2 alongside the # engine code that consumes them; CONFIG_VERSION bumps then. THRESHOLDS: dict = { "funding_history_limit": 100, # OKX caps funding history at 100/call "oi_history_period": "1H", # OKX rubik period format "oi_history_limit": 200, "kline_intervals": ["1m", "15m", "1H"], "kline_limit": 300, "taker_period": "1H", "poll_interval_sec": POLL_INTERVAL_SEC, "liq_baseline_days_required": LIQ_BASELINE_DAYS_REQUIRED, "universe_max": UNIVERSE_MAX, "universe_min_turnover_usd": UNIVERSE_MIN_TURNOVER_USD, # ── Engine: layer weights (sum=1.0) — confluence score (spec §3/§4) ────── "layer_weights": {"L1": 0.30, "L2": 0.25, "L3": 0.25, "L4": 0.20}, "liq_flush_cap_mult": 5.0, # flush / rolling baseline; cap_mult× => full L1 "funding_z_ref": 2.0, # |funding_z| saturating the funding sub-score "oi_drop_ref_pct": 5.0, # % OI drop giving full OI sub-score "funding_sub_w": 0.6, "oi_sub_w": 0.4, "taker_delta_z_ref": 2.0, # |taker delta z| saturating L3 "struct_w": {"fvg": 0.40, "swing": 0.35, "bos": 0.25}, "swing_lookback": 3, "atr_period": 14, # ── Levels (spec §4) ───────────────────────────────────────────────────── "stop_atr_mult": 1.5, "target_r_multiples": [1.0, 2.0], "entry_buffer_atr": 0.10, # ── Tiers (confluence 0..100) ──────────────────────────────────────────── "tiers": {"sniper": 75, "setup": 55, "watch": 35}, # ── Conviction (0..100): ranks ALL qualifying setups (no active cap) ────── "conviction_w": { "confluence": 0.45, "liquidity": 0.15, "reversal": 0.20, "trend": 0.10, "baseline": 0.10, }, "conviction_tags": {"elite": 85, "strong": 70, "moderate": 55}, "liq_turnover_floor_usd": 2.0e7, "liq_turnover_ref_usd": 2.0e9, "btc_trend_atr_ref": 2.0, # ── Risk (spec §6): cooldown kept; hard active/direction caps REMOVED ───── "cooldown_hours": 4, "size_by_tag": {"elite": 1.0, "strong": 0.7, "moderate": 0.4, "watch": 0.0}, } def snapshot() -> dict: """Full config snapshot persisted to config_versions at boot (spec §7).""" return { "config_version": CONFIG_VERSION, "exchange": EXCHANGE, "universe_mode": UNIVERSE_MODE, "watchlist": WATCHLIST, "tv_exchange": TV_EXCHANGE, "thresholds": THRESHOLDS, }