bsp_monitor: fetcher limit=1000, engine/main tweaks
This commit is contained in:
@@ -127,7 +127,7 @@ class ChanEngine:
|
|||||||
cst = dt.astimezone(timezone(timedelta(hours=8)))
|
cst = dt.astimezone(timezone(timedelta(hours=8)))
|
||||||
return cst.strftime("%Y-%m-%d %H:%M:%S CST")
|
return cst.strftime("%Y-%m-%d %H:%M:%S CST")
|
||||||
|
|
||||||
def format_bsp_detail(self, bsp: ChanBSP, symbol: str = "BTC/USDT:USDT") -> str:
|
def format_bsp_detail(self, bsp: ChanBSP, symbol: str = "BTC/USDT:USDT", tf: str = "1m") -> str:
|
||||||
bi = bsp.bi
|
bi = bsp.bi
|
||||||
klc = bsp.klc
|
klc = bsp.klc
|
||||||
bsp_type = bsp.type
|
bsp_type = bsp.type
|
||||||
@@ -138,7 +138,7 @@ class ChanEngine:
|
|||||||
|
|
||||||
symbol_short = symbol.split(":")[0].replace("/", "")
|
symbol_short = symbol.split(":")[0].replace("/", "")
|
||||||
lines = [
|
lines = [
|
||||||
f"{emoji} [{dir_label}] {self._bsp_type_name(bsp_type)} — <b>{symbol_short} 1m</b>",
|
f"{emoji} [{dir_label}] {self._bsp_type_name(bsp_type)} — <b>{symbol_short} {tf}</b>",
|
||||||
"",
|
"",
|
||||||
f"⏰ 确认: <code>{self._utc_to_cst(klc.end_time)}</code>",
|
f"⏰ 确认: <code>{self._utc_to_cst(klc.end_time)}</code>",
|
||||||
f"💰 价格: <b>{klc.close:.2f}</b>",
|
f"💰 价格: <b>{klc.close:.2f}</b>",
|
||||||
|
|||||||
@@ -17,16 +17,21 @@ FETCH_LIMIT = 1000
|
|||||||
_symbols_cache: Optional[List[str]] = None
|
_symbols_cache: Optional[List[str]] = None
|
||||||
|
|
||||||
|
|
||||||
|
# 只推送 BTC,其他币对暂不监控
|
||||||
|
_SYMBOL_WHITELIST = {"BTC/USDT:USDT", "ETH/USDT:USDT", "SOL/USDT:USDT"}
|
||||||
|
|
||||||
|
|
||||||
def get_symbols() -> list[str]:
|
def get_symbols() -> list[str]:
|
||||||
"""从 data_provider /health 获取所有可用币对(缓存)。"""
|
"""获取要监控的币对列表(目前只监控 BTC)。"""
|
||||||
global _symbols_cache
|
global _symbols_cache
|
||||||
if _symbols_cache is not None:
|
if _symbols_cache is not None:
|
||||||
return _symbols_cache
|
return _symbols_cache
|
||||||
try:
|
try:
|
||||||
resp = requests.get(f"{PROVIDER_URL}/health", timeout=10)
|
resp = requests.get(f"{PROVIDER_URL}/health", timeout=10)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
_symbols_cache = resp.json().get("symbols", [])
|
all_symbols = resp.json().get("symbols", [])
|
||||||
logger.info(f"获取到 {len(_symbols_cache)} 个币对")
|
_symbols_cache = [s for s in all_symbols if s in _SYMBOL_WHITELIST]
|
||||||
|
logger.info(f"获取到 {len(all_symbols)} 个币对,过滤后监控 {len(_symbols_cache)} 个: {_symbols_cache}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取币对列表失败: {e}")
|
logger.error(f"获取币对列表失败: {e}")
|
||||||
_symbols_cache = ["BTC/USDT:USDT"]
|
_symbols_cache = ["BTC/USDT:USDT"]
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ def _push_bsp(engine: ChanEngine, bsp, symbol: str, tf: str) -> bool:
|
|||||||
if bsp.klc is None:
|
if bsp.klc is None:
|
||||||
return False
|
return False
|
||||||
key = f"{symbol}_{bsp.type}_{bsp.klc.end_time}_{tf}"
|
key = f"{symbol}_{bsp.type}_{bsp.klc.end_time}_{tf}"
|
||||||
msg = engine.format_bsp_detail(bsp, symbol)
|
msg = engine.format_bsp_detail(bsp, symbol, tf)
|
||||||
msg = _escape_html(msg)
|
msg = _escape_html(msg)
|
||||||
if send_bsp_alert(msg, bsp_key=key):
|
if send_bsp_alert(msg, bsp_key=key):
|
||||||
logger.info(f"[{_short(symbol)} {tf}] ✅ BSP: {key}")
|
logger.info(f"[{_short(symbol)} {tf}] ✅ BSP: {key}")
|
||||||
|
|||||||
Reference in New Issue
Block a user