Add default USD-M perpetual BTC/ETH/BNB and fix futures WS stream
Seed um BTCUSDT/ETHUSDT/BNBUSDT as default symbols. The legacy futures route fstream.binance.com/stream accepts connections but no longer pushes data, so switch to /market/stream. Receive with a timeout so symbol changes are picked up and silent connections are reconnected.
This commit is contained in:
1 parent
554d224be2
commit
0831971e83
3 files changed
+52
-3
No files matched your search
@@ -15,7 +15,8 @@ REST = {
|
||||
"um": {"base": "https://fapi.binance.com", "klines": "/fapi/v1/klines", "exchange_info": "/fapi/v1/exchangeInfo",
|
||||
"ticker": "/fapi/v1/ticker/24hr", "weight_limit": 2400, "kline_limit": 1500},
|
||||
}
|
||||
WS = {"spot": "wss://stream.binance.com:9443/stream", "um": "wss://fstream.binance.com/stream"}
|
||||
# 合约旧路由 fstream.binance.com/stream 能连上但不推送数据,K 线/行情流在 /market 路由下
|
||||
WS = {"spot": "wss://stream.binance.com:9443/stream", "um": "wss://fstream.binance.com/market/stream"}
|
||||
|
||||
# 权重用量超过上限的这个比例就等到下一分钟
|
||||
WEIGHT_RATIO = 0.5
|
||||
|
||||
@@ -26,6 +26,8 @@ logger = logging.getLogger("alphapulse.market.worker")
|
||||
PAGES_PER_TURN = 20
|
||||
CATCHUP_SECONDS = 3600
|
||||
SYMBOL_CHECK_SECONDS = 10
|
||||
# miniTicker 约每秒推送,这么久没消息视为连接卡死
|
||||
STALL_SECONDS = 60
|
||||
ACTIVE_STATUSES = ("pending", "backfilling", "ready")
|
||||
|
||||
client = BinanceClient()
|
||||
@@ -209,8 +211,19 @@ async def stream_loop(market: str) -> None:
|
||||
logger.info("%s WS 已连接:%d 个交易对,%d 个流", market, len(symbols), len(streams))
|
||||
catchup_needed.set()
|
||||
next_check = time.monotonic() + SYMBOL_CHECK_SECONDS
|
||||
async for raw in ws:
|
||||
await handle_message(market, raw)
|
||||
last_message = time.monotonic()
|
||||
while True:
|
||||
# 带超时接收:没有消息时也要按时检查交易对变化和连接是否卡死
|
||||
try:
|
||||
raw = await asyncio.wait_for(ws.recv(), timeout=SYMBOL_CHECK_SECONDS)
|
||||
except TimeoutError:
|
||||
pass
|
||||
else:
|
||||
last_message = time.monotonic()
|
||||
await handle_message(market, raw)
|
||||
if time.monotonic() - last_message >= STALL_SECONDS:
|
||||
logger.warning("%s WS %ds 未收到消息,重连", market, STALL_SECONDS)
|
||||
break
|
||||
if time.monotonic() >= next_check:
|
||||
next_check = time.monotonic() + SYMBOL_CHECK_SECONDS
|
||||
if await active_symbols(market) != symbols:
|
||||
|
||||
Reference in new issue
Block a user