Fix Gate/Binance memory regression and roll stop offset from avg.

Stop fetch_tickers fallback for volume rank and keep stale cache on failed refresh. Compute roll unified stop as merge-average plus offset percent instead of break-even.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 00:21:07 +08:00
parent 7f8ae97a98
commit f63f8810e6
9 changed files with 343 additions and 37 deletions
+14 -9
View File
@@ -292,8 +292,7 @@ def _scores_from_binance(exchange) -> list[tuple[str, str, float]]:
return _merge_scores(by_base)
except Exception:
pass
tickers = exchange.fetch_tickers()
return _scores_from_markets(exchange, tickers or {}, "binance")
return []
def _scores_from_gate(exchange) -> list[tuple[str, str, float]]:
@@ -330,8 +329,7 @@ def _scores_from_gate(exchange) -> list[tuple[str, str, float]]:
return _merge_scores(by_base)
except Exception:
continue
tickers = exchange.fetch_tickers()
return _scores_from_markets(exchange, tickers or {}, "gateio")
return []
def _scores_from_markets(
@@ -373,6 +371,11 @@ def _collect_scores(exchange, exchange_id: str) -> list[tuple[str, str, float]]:
return _scores_from_markets(exchange, tickers or {}, ex_id)
def _uses_lightweight_volume_scores(exchange_id: str) -> bool:
ex_id = str(exchange_id or "").lower()
return ex_id in ("okx", "binance", "gateio", "gate", "gate_bot")
def build_usdt_swap_volume_ranks(
exchange,
ensure_markets_loaded: Callable[[], None],
@@ -383,8 +386,9 @@ def build_usdt_swap_volume_ranks(
全市场 USDT 永续 24h 成交额排名(base -> rank)。
优先各所轻量 ticker API,避免 fetch_tickers() 拉全市场(Gate/Binance 内存优化)。
"""
ensure_markets_loaded()
ex_id = str(exchange_id or getattr(exchange, "id", "") or "").lower()
if not _uses_lightweight_volume_scores(ex_id):
ensure_markets_loaded()
scored = _collect_scores(exchange, ex_id)
ranks: dict[str, int] = {}
for idx, (_sym, base, _qv) in enumerate(scored, 1):
@@ -417,10 +421,11 @@ def resolve_daily_volume_rank(
ensure_markets_loaded,
exchange_id=exchange_id,
)
cache["ranks"] = ranks
cache["total"] = total
cache["version"] = cache_version
cache["updated_at"] = now_ts
if total > 0 and ranks:
cache["ranks"] = ranks
cache["total"] = total
cache["version"] = cache_version
cache["updated_at"] = now_ts
except Exception:
pass
ranks = cache.get("ranks") or {}