Use lightweight ticker APIs for liquidity rank to cut memory.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+11
-57
@@ -178,6 +178,7 @@ from order_monitor_display_lib import (
|
||||
)
|
||||
from wechat_notify_lib import build_wechat_rs_level_message, send_wechat_webhook
|
||||
from hub_auth import request_allowed as hub_request_allowed
|
||||
from hub_volume_rank_lib import resolve_daily_volume_rank
|
||||
from history_window_lib import (
|
||||
PRESET_CUSTOM,
|
||||
PRESET_UTC_LAST24H,
|
||||
@@ -402,6 +403,7 @@ ACCOUNT_BALANCE_CACHE = {
|
||||
}
|
||||
LIQUIDITY_RANK_CACHE = {
|
||||
"updated_at": 0.0,
|
||||
"version": 0,
|
||||
"ranks": {},
|
||||
"total": 0,
|
||||
}
|
||||
@@ -4284,67 +4286,19 @@ def _status_by_ema55(symbol, timeframe):
|
||||
|
||||
def _daily_volume_rank(symbol):
|
||||
"""
|
||||
返回(symbol_rank, total_count),按 quoteVolume 降序,缺失时 fallback 到 baseVolume*last。
|
||||
返回(symbol_rank, total_count),按 USDT 永续 24h 成交额降序。
|
||||
走 hub_volume_rank_lib 轻量 ticker API,避免 fetch_tickers() 全市场拉取。
|
||||
"""
|
||||
sym_norm = normalize_symbol_input(symbol)
|
||||
target_base = journal_coin_from_symbol(sym_norm)
|
||||
|
||||
def _ticker_base(sym_text):
|
||||
s = str(sym_text or "").upper().strip()
|
||||
if ":" in s:
|
||||
s = s.split(":", 1)[0]
|
||||
if "/" in s:
|
||||
return s.split("/", 1)[0].strip()
|
||||
if "-" in s:
|
||||
return s.split("-", 1)[0].strip()
|
||||
if s.endswith("USDT"):
|
||||
return s[:-4].strip()
|
||||
return s
|
||||
now_ts = time.time()
|
||||
cached_ok = (
|
||||
LIQUIDITY_RANK_CACHE["updated_at"]
|
||||
and now_ts - float(LIQUIDITY_RANK_CACHE["updated_at"]) < max(30, BALANCE_REFRESH_SECONDS)
|
||||
return resolve_daily_volume_rank(
|
||||
target_base,
|
||||
LIQUIDITY_RANK_CACHE,
|
||||
now_ts=time.time(),
|
||||
ttl_sec=max(30, BALANCE_REFRESH_SECONDS),
|
||||
exchange=exchange,
|
||||
ensure_markets_loaded=ensure_markets_loaded,
|
||||
)
|
||||
if not cached_ok:
|
||||
try:
|
||||
ensure_markets_loaded()
|
||||
tickers = exchange.fetch_tickers()
|
||||
scored = []
|
||||
for s, t in (tickers or {}).items():
|
||||
try:
|
||||
mk = exchange.markets.get(s)
|
||||
if not mk or not mk.get("swap"):
|
||||
continue
|
||||
su = str(s).upper()
|
||||
if "USDT" not in su:
|
||||
continue
|
||||
qv = _safe_float((t or {}).get("quoteVolume"))
|
||||
if qv is None:
|
||||
info = (t or {}).get("info") if isinstance((t or {}).get("info"), dict) else {}
|
||||
qv = _safe_float(info.get("volCcy24h") or info.get("vol24h"))
|
||||
if qv is None:
|
||||
bv = _safe_float((t or {}).get("baseVolume"))
|
||||
lp = _safe_float((t or {}).get("last"))
|
||||
if bv is not None and lp is not None:
|
||||
qv = bv * lp
|
||||
if qv is None or qv <= 0:
|
||||
continue
|
||||
scored.append((_ticker_base(s), float(qv)))
|
||||
except Exception:
|
||||
continue
|
||||
scored.sort(key=lambda x: x[1], reverse=True)
|
||||
ranks = {}
|
||||
for idx, (base, _) in enumerate(scored, 1):
|
||||
if base and base not in ranks:
|
||||
ranks[base] = idx
|
||||
LIQUIDITY_RANK_CACHE["ranks"] = ranks
|
||||
LIQUIDITY_RANK_CACHE["total"] = len(scored)
|
||||
LIQUIDITY_RANK_CACHE["updated_at"] = now_ts
|
||||
except Exception:
|
||||
pass
|
||||
ranks = LIQUIDITY_RANK_CACHE.get("ranks") or {}
|
||||
total = int(LIQUIDITY_RANK_CACHE.get("total") or 0)
|
||||
return ranks.get(target_base), total
|
||||
|
||||
|
||||
def _key_hard_checks(symbol, direction, upper, lower, monitor_type):
|
||||
|
||||
Reference in New Issue
Block a user