hl-api-samples

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hyperliquid API Sample Data Fetcher

Hyperliquid API 样本数据获取命令集

Generate ready-to-run bash/curl commands for fetching data from the Hyperliquid mainnet API.
生成可直接运行的bash/curl命令,用于从Hyperliquid主网API获取数据。

Base URL

基础URL

https://api.hyperliquid.xyz/info
All requests are POST with
Content-Type: application/json
.

https://api.hyperliquid.xyz/info
所有请求均为POST方法,且
Content-Type
application/json

Public Data Commands

公开数据命令

Get Exchange Metadata (assets, leverage, decimals)

获取交易所元数据(资产、杠杆、小数位数)

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "meta"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "meta"}' | jq

Get All Mid Prices

获取所有中间价

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "allMids"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "allMids"}' | jq

Get Meta + Asset Contexts (combined metadata)

获取元数据+资产上下文(合并元数据)

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "metaAndAssetCtxs"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "metaAndAssetCtxs"}' | jq

Get Order Book (L2)

获取订单簿(L2)

bash
undefined
bash
undefined

BTC order book

BTC订单簿

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "l2Book", "coin": "BTC"}' | jq
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "l2Book", "coin": "BTC"}' | jq

ETH order book

ETH订单簿

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "l2Book", "coin": "ETH"}' | jq
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "l2Book", "coin": "ETH"}' | jq

SOL order book

SOL订单簿

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "l2Book", "coin": "SOL"}' | jq
undefined
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "l2Book", "coin": "SOL"}' | jq
undefined

Get Recent Trades

获取近期交易记录

bash
undefined
bash
undefined

BTC recent trades

BTC近期交易记录

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "recentTrades", "coin": "BTC"}' | jq
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "recentTrades", "coin": "BTC"}' | jq

ETH recent trades

ETH近期交易记录

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "recentTrades", "coin": "ETH"}' | jq
undefined
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "recentTrades", "coin": "ETH"}' | jq
undefined

Get Candle Data (OHLCV)

获取K线数据(OHLCV)

bash
undefined
bash
undefined

BTC 1-hour candles (last 24 hours)

BTC 1小时K线(最近24小时)

Replace START_TIME and END_TIME with millisecond timestamps

替换START_TIME和END_TIME为毫秒级时间戳

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "candleSnapshot", "req": {"coin": "BTC", "interval": "1h", "startTime": 1704067200000, "endTime": 1704153600000}}' | jq
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "candleSnapshot", "req": {"coin": "BTC", "interval": "1h", "startTime": 1704067200000, "endTime": 1704153600000}}' | jq

ETH 15-minute candles

ETH 15分钟K线

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "candleSnapshot", "req": {"coin": "ETH", "interval": "15m", "startTime": 1704067200000, "endTime": 1704153600000}}' | jq

**Candle Intervals**: `1m`, `5m`, `15m`, `1h`, `4h`, `1d`

---
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "candleSnapshot", "req": {"coin": "ETH", "interval": "15m", "startTime": 1704067200000, "endTime": 1704153600000}}' | jq

**K线时间间隔**:`1m`、`5m`、`15m`、`1h`、`4h`、`1d`

---

User-Specific Commands

用户专属命令

Replace
0xYOUR_ADDRESS
with your actual wallet address.
0xYOUR_ADDRESS
替换为您实际的钱包地址。

Get Account State (positions, margin, balance)

获取账户状态(持仓、保证金、余额)

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "clearinghouseState", "user": "0xYOUR_ADDRESS"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "clearinghouseState", "user": "0xYOUR_ADDRESS"}' | jq

Get Open Orders

获取挂单

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "openOrders", "user": "0xYOUR_ADDRESS"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "openOrders", "user": "0xYOUR_ADDRESS"}' | jq

Get Frontend Open Orders (includes TP/SL info)

获取前端挂单(包含止盈/止损信息)

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "frontendOpenOrders", "user": "0xYOUR_ADDRESS"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "frontendOpenOrders", "user": "0xYOUR_ADDRESS"}' | jq

Get Trade Fills (history)

获取成交记录(历史)

bash
undefined
bash
undefined

Get fills from a start time (milliseconds)

从指定时间(毫秒)开始获取成交记录

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "userFills", "user": "0xYOUR_ADDRESS", "startTime": 1704067200000}' | jq
undefined
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "userFills", "user": "0xYOUR_ADDRESS", "startTime": 1704067200000}' | jq
undefined

Get Funding Payments

获取资金费用记录

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "userFunding", "user": "0xYOUR_ADDRESS", "startTime": 1704067200000}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "userFunding", "user": "0xYOUR_ADDRESS", "startTime": 1704067200000}' | jq

Get Spot Balances

获取现货余额

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "spotClearinghouseState", "user": "0xYOUR_ADDRESS"}' | jq

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "spotClearinghouseState", "user": "0xYOUR_ADDRESS"}' | jq

HIP-3 Builder-Deployed Markets

HIP-3 开发者部署市场

For HIP-3 markets, add the
dex
parameter:
对于HIP-3市场,需添加
dex
参数:

Get HIP-3 Market Metadata

获取HIP-3市场元数据

bash
undefined
bash
undefined

xyz dex metadata

xyz dex元数据

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "meta", "dex": "xyz"}' | jq
undefined
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "meta", "dex": "xyz"}' | jq
undefined

Get HIP-3 Positions

获取HIP-3持仓

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "clearinghouseState", "user": "0xYOUR_ADDRESS", "dex": "xyz"}' | jq
Available HIP-3 dexes:
xyz
,
flx
,
vntl
,
hyna
,
km

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "clearinghouseState", "user": "0xYOUR_ADDRESS", "dex": "xyz"}' | jq
可用的HIP-3 dex
xyz
flx
vntl
hyna
km

Spot Market Commands

现货市场命令

For spot markets, use
@{index}
format for candles:
对于现货市场,K线需使用
@{index}
格式:

Get Spot Market Metadata

获取现货市场元数据

bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "spotMeta"}' | jq
bash
curl -X POST https://api.hyperliquid.xyz/info \
  -H "Content-Type: application/json" \
  -d '{"type": "spotMeta"}' | jq

Get Spot Candles (use @index format)

获取现货K线(使用@index格式)

bash
undefined
bash
undefined

HYPE/USDC candles (index 107)

HYPE/USDC K线(索引107)

curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "candleSnapshot", "req": {"coin": "@107", "interval": "1h", "startTime": 1704067200000, "endTime": 1704153600000}}' | jq

---
curl -X POST https://api.hyperliquid.xyz/info
-H "Content-Type: application/json"
-d '{"type": "candleSnapshot", "req": {"coin": "@107", "interval": "1h", "startTime": 1704067200000, "endTime": 1704153600000}}' | jq

---

Tips

小贴士

  • Formatting: Pipe output to
    jq
    for pretty-printed JSON
  • Timestamps: All times are in milliseconds (e.g.,
    Date.now()
    in JS,
    date +%s000
    in bash)
  • Get current timestamp:
    date +%s000
  • Get timestamp from 24h ago:
    echo $(($(date +%s) - 86400))000
  • Asset names: Use symbols like
    BTC
    ,
    ETH
    ,
    SOL
    ,
    HYPE
    (see
    meta
    endpoint for full list)
  • 格式化:将输出通过管道传递给
    jq
    以获得格式化的JSON
  • 时间戳:所有时间均为毫秒级(例如JS中的
    Date.now()
    ,bash中的
    date +%s000
  • 获取当前时间戳
    date +%s000
  • 获取24小时前的时间戳
    echo $(($(date +%s) - 86400))000
  • 资产名称:使用
    BTC
    ETH
    SOL
    HYPE
    等符号(完整列表请查看
    meta
    接口)