"""真实 Bitget 盘口在 BOOK_DEPTH 档内能不能吃下各个名义额档位。 shadow_hb 把吃单换成了框架的 get_vwap_for_volume,深度不足时它返回 nan、 整行标 depth_ok=0。所以「档数够不够」直接决定某个仓位档会不会整段丢失, 不是个可以事后补救的参数——先量出来再定 BOOK_DEPTH。 """ from __future__ import annotations import asyncio import sys import numpy as np sys.path.insert(0, "/repo/research/live") from shadow_hb import BOOK_DEPTH, NOTIONALS, SYMS, book_from async def run() -> None: from hummingbot.connector.derivative.bitget_perpetual.bitget_perpetual_derivative import ( BitgetPerpetualDerivative, ) conn = BitgetPerpetualDerivative( bitget_perpetual_api_key="", bitget_perpetual_secret_key="", bitget_perpetual_passphrase="", trading_pairs=[f"{s}-USDT" for s in SYMS], trading_required=False) await conn.start_network() print(f"连接器已启动,等盘口(档数上限 {BOOK_DEPTH})") for _ in range(60): await asyncio.sleep(1) try: if all(conn.get_order_book(f"{s}-USDT") is not None for s in SYMS): break except Exception: continue for s in SYMS: ob = conn.get_order_book(f"{s}-USDT") bids = np.array([(float(r.price), float(r.amount), i) for i, (r, _) in enumerate( zip(ob.bid_entries(), range(BOOK_DEPTH)))]) asks = np.array([(float(r.price), float(r.amount), i) for i, (r, _) in enumerate( zip(ob.ask_entries(), range(BOOK_DEPTH)))]) mid = (bids[0][0] + asks[0][0]) / 2.0 snap = book_from(bids, asks) ask_notional = float((asks[:, 0] * asks[:, 1]).sum()) print(f"\n{s} 中价 {mid:.2f} · 取到 {len(asks)} 档 · " f"卖盘 {len(asks)} 档合计 {ask_notional:,.0f} USDT") print(f" 最深一档距中价 " f"{(asks[-1][0] / mid - 1) * 1e4:.1f}bp") for notional in NOTIONALS: base = notional / mid r = snap.get_vwap_for_volume(True, base) px = float(r.result_price) ok = float(r.result_volume) >= base * 0.999 if ok: print(f" 名义 {notional:>7,.0f} → {base:.6f} 币 · " f"冲击 {(px / mid - 1) * 1e4:6.2f}bp · 吃得下") else: print(f" 名义 {notional:>7,.0f} → {base:.6f} 币 · " f"深度不足,仅 {r.result_volume:.6f} 币 · " f"这一档会整段丢失") await conn.stop_network() if __name__ == "__main__": asyncio.run(run())