Survive Binance eapi 418/429 with cooldown, soft start, and no ticker raise.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-25 12:49:14 +08:00
parent 867deba1bb
commit 21ca5cbfe0
3 changed files with 115 additions and 53 deletions
+17 -3
View File
@@ -112,7 +112,11 @@ class StrategySession:
return
self._started = True
await self.ex.start()
await asyncio.to_thread(self.align_instruments)
try:
await asyncio.to_thread(self.align_instruments)
except Exception as e:
# eapi 418/429 时允许先起会话,后续 refresh 再对齐
logger.warning("initial ATM align failed (will retry): %s", e)
await self.ex.resubscribe(
[
self.settings.perp_inst_id,
@@ -205,6 +209,13 @@ class StrategySession:
put_bids, put_asks, _ = self.ex.fetch_book(pair.put_inst_id, depth=5)
call_ask = call_asks[0].px if call_asks else None
put_ask = put_asks[0].px if put_asks else None
# REST 被限流时回退 WS/缓存盘口
if call_ask is None:
cq = self.ex.quote(pair.call_inst_id)
call_ask = cq.ask if cq else None
if put_ask is None:
pq = self.ex.quote(pair.put_inst_id)
put_ask = pq.ask if pq else None
sig = decide(
call_ask,
put_ask,
@@ -335,7 +346,7 @@ class StrategySession:
async def _refresh_loop(self) -> None:
while True:
await asyncio.sleep(30)
await asyncio.sleep(30 if self._pair is not None else 10)
try:
idx = await asyncio.to_thread(
self.ex.fetch_index, self.settings.index_inst_id
@@ -346,7 +357,10 @@ class StrategySession:
)
if mark:
self.ex.set_mark_px(self.settings.perp_inst_id, mark)
await self.ensure_atm_async(force=False)
if self._pair is None:
await self.ensure_atm_async(force=True)
else:
await self.ensure_atm_async(force=False)
except asyncio.CancelledError:
raise
except Exception as e: