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
+43
View File
@@ -84,6 +84,15 @@ def test_scores_from_binance_uses_fapi_lightweight_api():
ex.fetch_tickers.assert_not_called()
def test_scores_from_binance_skips_fetch_tickers_on_api_error():
ex = MagicMock()
ex.id = "binance"
ex.fapiPublicGetTicker24hr.side_effect = RuntimeError("network")
scored = _scores_from_binance(ex)
assert scored == []
ex.fetch_tickers.assert_not_called()
def test_scores_from_gate_uses_futures_tickers_api():
ex = MagicMock()
ex.id = "gateio"
@@ -96,6 +105,15 @@ def test_scores_from_gate_uses_futures_tickers_api():
ex.fetch_tickers.assert_not_called()
def test_scores_from_gate_skips_fetch_tickers_on_api_error():
ex = MagicMock()
ex.id = "gateio"
ex.publicFuturesGetSettleTickers.side_effect = RuntimeError("network")
scored = _scores_from_gate(ex)
assert scored == []
ex.fetch_tickers.assert_not_called()
def test_resolve_daily_volume_rank_caches_result():
cache = {"version": 0, "updated_at": 0.0, "ranks": {}, "total": 0}
ex = MagicMock()
@@ -130,6 +148,31 @@ def test_resolve_daily_volume_rank_caches_result():
assert ex.fapiPublicGetTicker24hr.call_count == calls
def test_resolve_daily_volume_rank_keeps_stale_cache_when_refresh_empty():
cache = {
"version": LIQUIDITY_RANK_CACHE_VERSION,
"updated_at": 900.0,
"ranks": {"BTC": 1},
"total": 100,
}
ex = MagicMock()
ex.id = "binance"
ex.fapiPublicGetTicker24hr.return_value = []
rank, total = resolve_daily_volume_rank(
"BTC",
cache,
now_ts=2000.0,
ttl_sec=60.0,
exchange=ex,
ensure_markets_loaded=lambda: None,
)
assert rank == 1
assert total == 100
assert cache["updated_at"] == 900.0
ex.fetch_tickers.assert_not_called()
def test_build_usdt_swap_volume_ranks():
ex = MagicMock()
ex.id = "binance"