修复 load_markets 超时后狂打交易所:失败退避 90 秒,避免反复请求导致封 IP。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-13 00:47:47 +08:00
parent 39878de7fc
commit 702d9d3be8
5 changed files with 138 additions and 6 deletions
+20 -2
View File
@@ -478,6 +478,18 @@ if GATE_API_KEY and GATE_API_SECRET:
exchange.apiKey = GATE_API_KEY
exchange.secret = GATE_API_SECRET
MARKETS_LOADED = False
_MARKETS_GUARD = None
def _get_markets_guard():
global _MARKETS_GUARD
if _MARKETS_GUARD is None:
from lib.trade.markets_load_guard_lib import MarketsLoadGuard
_MARKETS_GUARD = MarketsLoadGuard(backoff_sec=90.0, label="gate markets")
return _MARKETS_GUARD
ACCOUNT_BALANCE_CACHE = {
"updated_at": 0.0,
"funding_usdt": None,
@@ -3376,10 +3388,16 @@ def calc_trend_manual_breakeven_stop(direction, entry_price, offset_pct=None):
def ensure_markets_loaded(force=False):
"""加载 Gate markets;失败后退避,避免超时循环狂打 API 导致封 IP."""
global MARKETS_LOADED
if force or not MARKETS_LOADED:
exchange.load_markets(reload=force)
guard = _get_markets_guard()
guard.loaded = bool(MARKETS_LOADED)
try:
guard.ensure(lambda: exchange.load_markets(reload=force), force=force)
MARKETS_LOADED = True
except Exception:
MARKETS_LOADED = False
raise
def _abort_market_open_after_tpsl_failure(exchange_symbol, direction, order, planned_amount):