Bug Description
The testnet API (api.hyperliquid-testnet.xyz) returns spotMeta data with invalid token indices that cause an IndexError when initializing the Info class.
Error
IndexError: list index out of range
At hyperliquid/info.py:48:
base_info = spot_meta["tokens"][base] # IndexError when base >= len(tokens)
Root Cause
The testnet spotMeta endpoint returns 1575 tokens but 19 universe entries have token indices >= 1575 (e.g., base: 1576, 1577, 1583).
Evidence
# API response analysis
tokens = 1575 elements (indices 0-1574)
bad_entries = [
{'name': '@1441', 'base': 1576, 'quote': 0},
{'name': '@1453', 'base': 1577, 'quote': 0},
{'name': '@1455', 'base': 1583, 'quote': 0},
# ... 16 more
]
Suggested Fix
Add bounds checking in info.py before accessing token indices:
tokens = spot_meta["tokens"]
tokens_len = len(tokens)
for spot_info in spot_meta["universe"]:
base, quote = spot_info["tokens"]
if base >= tokens_len or quote >= tokens_len:
continue # Skip invalid entries
# ... rest of code
Workaround
I've implemented a local workaround that skips invalid entries, but a proper fix in the SDK would help all users.
Environment
- SDK version: latest (from pypi)
- Python 3.10
- Testnet only (mainnet works fine)
Bug Description
The testnet API (
api.hyperliquid-testnet.xyz) returnsspotMetadata with invalid token indices that cause anIndexErrorwhen initializing theInfoclass.Error
At
hyperliquid/info.py:48:Root Cause
The testnet
spotMetaendpoint returns 1575 tokens but 19 universe entries have token indices >= 1575 (e.g., base: 1576, 1577, 1583).Evidence
Suggested Fix
Add bounds checking in
info.pybefore accessing token indices:Workaround
I've implemented a local workaround that skips invalid entries, but a proper fix in the SDK would help all users.
Environment