File size: 2,087 Bytes
c6262df | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | """
Risk gates (spec §6, revised per user design).
DESIGN CHANGE (user decision): the spec's hard caps (max 3 active, max 2 per
direction) are REMOVED. They throw away genuine opportunity when many A+ setups
appear at once. Instead:
• Every setup that clears the WATCH tier is kept and RANKED by conviction
(scoring.rank) — the user scans the strongest first and decides what to take.
• The only structural gate retained is the per-coin COOLDOWN: no new signal on
a coin that already has a live (non-terminal) signal within `cooldown_hours`.
This prevents the same flush re-firing as dozens of duplicates; it does NOT
limit how many DIFFERENT coins can signal at once.
Position sizing is advisory only (scoring.size_by_tag): the user sizes their own
Bybit trade. CRE never executes.
"""
from __future__ import annotations
from config import THRESHOLDS as T
from . import lifecycle
def cooldown_ok(symbol: str, now_ts: int, active_signals: list[dict]) -> bool:
"""True if no live signal on this coin is within the cooldown window.
active_signals: rows with keys {symbol, state, created_ts}."""
window = T["cooldown_hours"] * 3600
for s in active_signals:
if s["symbol"] != symbol:
continue
if s.get("state") in lifecycle.TERMINAL:
continue
if now_ts - int(s["created_ts"]) < window:
return False
return True
def is_alertable(tier: str) -> bool:
"""SETUP and SNIPER push alerts; WATCH is logged silently (spec §4)."""
return tier in ("setup", "sniper")
def admit(setup, now_ts: int, active_signals: list[dict]) -> tuple[bool, str]:
"""Decide whether a freshly-scored setup is admitted (logged/ranked).
Returns (admit?, reason). Cooldown is the only hard block; everything else
that clears WATCH is admitted and ranked by conviction."""
if setup.tier == "none":
return False, "below WATCH threshold"
if not cooldown_ok(setup.symbol, now_ts, active_signals):
return False, "cooldown active on symbol"
return True, "admitted"
|