"""Check what OI data HL exposes.""" import urllib.request, json, time, pandas as pd URL = "https://api.hyperliquid.xyz/info" def post(body): req = urllib.request.Request(URL, data=json.dumps(body).encode(), headers={"Content-Type":"application/json"}) with urllib.request.urlopen(req, timeout=30) as r: return json.loads(r.read().decode()) # 1) Current OI print("=== metaAndAssetCtxs (current OI snapshot) ===") r = post({"type":"metaAndAssetCtxs"}) meta, ctxs = r[0], r[1] btc_idx = next(i for i,c in enumerate(meta["universe"]) if c["name"]=="BTC") print(f"BTC ctx keys: {list(ctxs[btc_idx].keys())}") print(f"BTC current ctx: {ctxs[btc_idx]}") # 2) Try candleSnapshot — does it expose OI per bar? print() print("=== candleSnapshot BTC 1h ===") start_ms = int(pd.Timestamp("2026-04-01", tz="UTC").timestamp()*1000) end_ms = int(pd.Timestamp("2026-04-02", tz="UTC").timestamp()*1000) r = post({"type":"candleSnapshot","req":{"coin":"BTC","interval":"1h", "startTime":start_ms,"endTime":end_ms}}) print(f"rows: {len(r)}") if r: print(f"first bar keys: {list(r[0].keys())}") print(f"sample: {r[0]}") # 3) Try historicalState (sometimes used for asset ctxs) print() print("=== try historicalAssetCtxs (BTC, 4-hour ago + now) ===") try: now_ms = int(time.time()*1000) r = post({"type":"historicalAssetCtxs","coin":"BTC","startTime":now_ms-4*3600*1000,"endTime":now_ms}) print(f"type ok, rows: {len(r) if isinstance(r,list) else 'n/a'}") if isinstance(r,list) and r: print(f"sample: {r[0]}") else: print(f"resp: {str(r)[:300]}") except Exception as e: print(f"error: {e}") # 4) Try the funding-style approach for OI print() print("=== try 'openInterest' as info type ===") try: r = post({"type":"openInterest","coin":"BTC"}) print(f"resp: {str(r)[:400]}") except Exception as e: print(f"error: {e}")