Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions hyperliquid/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def __init__(
self.coin_to_asset[spot_info["name"]] = asset
self.name_to_coin[spot_info["name"]] = spot_info["name"]
base, quote = spot_info["tokens"]
base_info = token_by_index[base]
quote_info = token_by_index[quote]
base_info = token_by_index.get(base)
quote_info = token_by_index.get(quote)
if base_info is None or quote_info is None:
continue
self.asset_to_sz_decimals[asset] = base_info["szDecimals"]
name = f'{base_info["name"]}/{quote_info["name"]}'
if name not in self.name_to_coin:
Expand Down
35 changes: 35 additions & 0 deletions tests/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,38 @@ def test_extra_agents():
assert "name" in agent, "Each agent should have a 'name' field"
assert "address" in agent, "Each agent should have an 'address' field"
assert "validUntil" in agent, "Each agent should have a 'validUntil' field"


def test_spot_universe_with_out_of_range_token_index_is_skipped():
spot_meta: SpotMeta = {
"universe": [
{"index": 0, "name": "PURR/USDC", "tokens": [1, 0], "isCanonical": True},
{"index": 1, "name": "@999", "tokens": [479, 0], "isCanonical": False},
],
"tokens": [
{
"name": "USDC",
"szDecimals": 8,
"weiDecimals": 8,
"index": 0,
"tokenId": "0x" + "0" * 64,
"isCanonical": True,
"evmContract": None,
"fullName": None,
},
{
"name": "PURR",
"szDecimals": 0,
"weiDecimals": 5,
"index": 1,
"tokenId": "0x" + "1" * 64,
"isCanonical": True,
"evmContract": None,
"fullName": None,
},
],
}
info = Info(skip_ws=True, meta=TEST_META, spot_meta=spot_meta)
assert info.coin_to_asset["PURR/USDC"] == 10000
assert "PURR/USDC" in info.name_to_coin
assert "@999" in info.coin_to_asset