取引 API と SDK · SDK の準備と認証 · 2/8
市場データを読む
Info クラス
読み取りの操作は、すべて Info クラスを通します。認証は要りません。公開の市場データは誰でも読めます。
from hyperliquid.info import Info
from hyperliquid.utils import constants
info = Info(base_url=constants.MAINNET_API_URL, skip_ws=True)
市場のメタデータを取る
# Get all available markets
meta = info.meta()
# meta["universe"] contains all perp markets
for asset in meta["universe"]:
print(f"{asset['name']}: max leverage {asset['maxLeverage']}x")
# As of October 2026: BTC 40x, ETH 25x, SOL 20x (these change; always read them live)
メタデータに入っているものは次のとおりです。
- 銘柄の名前(
universeの中の位置が、注文に署名するときの asset index になります) - 最大レバレッジ
szDecimals: 注文の数量に使える小数の桁数- 価格の刻みを示す項目はありません。無期限先物の価格は、有効数字5桁まで、小数は
6 - szDecimals桁までです(価格と数量の刻み)
板(L2 データ)
# Get the order book for BTC
book = info.l2_snapshot("BTC")
# book has "levels" with bids and asks (up to 20 levels per side)
bids = book["levels"][0] # [{"px": "...", "sz": "...", "n": orders}, ...]
asks = book["levels"][1]
best_bid = float(bids[0]["px"])
best_ask = float(asks[0]["px"])
spread = best_ask - best_bid
print(f"BTC: {best_bid} / {best_ask} (spread: {spread:.2f})")
口座の状態
# Get account state (positions, margin, equity) for your main account address
state = info.user_state("0xYourAddress") # numbers come back as strings
# Account value
print(f"Account Value: ${state['marginSummary']['accountValue']}")
print(f"Total Margin: ${state['marginSummary']['totalMarginUsed']}")
# Open positions
for pos in state["assetPositions"]:
p = pos["position"]
print(f"{p['coin']}: {p['szi']} contracts @ {p['entryPx']}")
print(f" PnL: ${p['unrealizedPnl']}")
資金調達率
# Current funding rates: metaAndAssetCtxs returns [meta, asset_contexts]
meta, ctxs = info.meta_and_asset_ctxs()
for asset, ctx in zip(meta["universe"], ctxs):
hourly = float(ctx["funding"]) * 100 # funding is paid every hour
annual = hourly * 24 * 365
print(f"{asset['name']}: {hourly:.4f}%/hr ({annual:.1f}% APR)")
各コンテキストには、ほかに markPx、oraclePx、openInterest、premium、dayNtlVlm も入っています。
資金調達率は、デルタニュートラルの取引や、資金調達率の裁定といった戦略で欠かせません。
過去のデータ
import time
# Get candle data (OHLCV); only the most recent 5000 candles are available
end_time = int(time.time() * 1000)
start_time = end_time - (24 * 60 * 60 * 1000) # 24 hours ago
candles = info.candles_snapshot("BTC", "1h", start_time, end_time)
for c in candles:
print(f"Open: {c['o']}, High: {c['h']}, Low: {c['l']}, Close: {c['c']}") # strings
HIP-3 の市場(builder が開いた無期限先物)
Hyperliquid には、標準の無期限先物の dex のほかに、builder が開いた無期限先物の dex(HIP-3)があります。それぞれを別の運営者が動かしています。銘柄の名前には dex の接頭辞が付きます。たとえば xyz:TSLA です。SDK が知っているのは perp_dexs に並べた dex だけです("" は標準の dex)。そのため、Info(と Exchange)を作るときに渡します。
info = Info(constants.MAINNET_API_URL, skip_ws=True, perp_dexs=["", "xyz"])
print(info.perp_dexs()) # [None, {"name": "xyz", ...}, ...]; None is the default dex
xyz_meta = info.meta(dex="xyz") # universe names look like "xyz:TSLA"
book = info.l2_snapshot("xyz:TSLA") # KeyError if "xyz" was not in perp_dexs
state = info.user_state("0xYourAddress", dex="xyz") # positions and margin are per dex
注文にも同じ名前を使います。SDK はそれを asset ID 100000 + perp_dex_index * 10000 + index_in_meta に変換します(2026年10月時点で xyz:TSLA は 110001 です。Asset IDs を参照)。