okx-cex-market
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOKX CEX Market Data CLI
OKX CEX 市场数据CLI
Public market data for OKX exchange: prices, order books, candles, funding rates, open interest, and instrument info. All commands are read-only and do not require API credentials.
OKX交易所公开市场数据查询工具,支持查询价格、订单簿、K线、资金费率、持仓量和交易品种信息。所有命令都是只读的,不需要API凭证。
Prerequisites
前置要求
- Install CLI:
okxbashnpm install -g @okx_ai/okx-trade-cli - No credentials needed for market data — all commands are public.
- Verify install:
bash
okx market ticker BTC-USDT
- 安装CLI:
okxbashnpm install -g @okx_ai/okx-trade-cli - 查询市场数据不需要凭证——所有命令都是公开的。
- 验证安装:
bash
okx market ticker BTC-USDT
Demo vs Live Mode
演示模式 vs 线上模式
Market data commands are public and read-only — demo mode has no effect. The same data is returned with or without . No confirmation needed before running any market command.
--demo市场数据命令是公开且只读的——演示模式不会产生任何影响。无论是否添加参数,返回的数据都相同。运行任何市场数据命令前都不需要确认。
--demoSkill Routing
技能路由
- For market data (prices, charts, depth, funding rates) → use (this skill)
okx-cex-market - For account balance, P&L, positions, fees, transfers → use
okx-cex-portfolio - For regular spot/swap/futures/algo orders → use
okx-cex-trade - For grid and DCA trading bots → use
okx-cex-bot
- 查询市场数据(价格、图表、深度、资金费率)→ 使用(本技能)
okx-cex-market - 查询账户余额、盈亏、持仓、手续费、转账 → 使用
okx-cex-portfolio - 普通现货/永续/合约/算法订单操作 → 使用
okx-cex-trade - 网格和DCA交易机器人操作 → 使用
okx-cex-bot
Quickstart
快速开始
bash
undefinedbash
undefinedCurrent BTC spot price
BTC现货当前价格
okx market ticker BTC-USDT
okx market ticker BTC-USDT
All SWAP (perp) tickers
所有SWAP(永续合约)行情
okx market tickers SWAP
okx market tickers SWAP
BTC perp order book (top 5 levels each side)
BTC永续合约订单簿(买卖各5档)
okx market orderbook BTC-USDT-SWAP
okx market orderbook BTC-USDT-SWAP
BTC hourly candles (last 20)
BTC小时级K线(最近20根)
okx market candles BTC-USDT --bar 1H --limit 20
okx market candles BTC-USDT --bar 1H --limit 20
BTC perp current funding rate
BTC永续合约当前资金费率
okx market funding-rate BTC-USDT-SWAP
okx market funding-rate BTC-USDT-SWAP
BTC perp funding rate history
BTC永续合约历史资金费率
okx market funding-rate BTC-USDT-SWAP --history
okx market funding-rate BTC-USDT-SWAP --history
Open interest for all SWAP instruments
所有SWAP品种的持仓量
okx market open-interest --instType SWAP
okx market open-interest --instType SWAP
List all active SPOT instruments
列出所有活跃现货交易对
okx market instruments --instType SPOT
undefinedokx market instruments --instType SPOT
undefinedCommand Index
命令索引
| # | Command | Type | Description |
|---|---|---|---|
| 1 | | READ | Single instrument: last price, 24h high/low/vol |
| 2 | | READ | All tickers for an instrument type |
| 3 | | READ | List tradeable instruments |
| 4 | | READ | Order book top asks/bids |
| 5 | | READ | OHLCV candlestick data |
| 6 | | READ | Index OHLCV candles |
| 7 | | READ | Current or historical funding rate |
| 8 | | READ | Recent public trades |
| 9 | | READ | Mark price for contracts |
| 10 | | READ | Index price (e.g., BTC-USD) |
| 11 | | READ | Upper/lower price limits for contracts |
| 12 | | READ | Open interest in contracts and coins |
| # | Command | Type | 描述 |
|---|---|---|---|
| 1 | | READ | 单个交易对:最新价格、24小时高低价/成交量 |
| 2 | | READ | 某类交易对的全部行情 |
| 3 | | READ | 列出可交易的品种 |
| 4 | | READ | 订单簿买卖盘档位 |
| 5 | | READ | OHLCV K线数据 |
| 6 | | READ | 指数OHLCV K线 |
| 7 | | READ | 当前或历史资金费率 |
| 8 | | READ | 最近公开成交记录 |
| 9 | | READ | 合约标记价格 |
| 10 | | READ | 指数价格(例如BTC-USD) |
| 11 | | READ | 合约涨跌停价格限制 |
| 12 | | READ | 合约持仓量(张和币本位) |
Cross-Skill Workflows
跨技能工作流
Check price before placing an order
下单前查询价格
User: "What's the current BTC price? I want to place a limit buy."
1. okx-cex-market okx market ticker BTC-USDT → check last price and 24h range
↓ user decides price
2. okx-cex-portfolio okx account balance USDT → confirm available funds
↓ user approves
3. okx-cex-trade okx spot place --instId BTC-USDT --side buy --ordType limit --px <px> --sz <sz>用户:"当前BTC价格是多少?我想挂一个限价买单。"
1. okx-cex-market okx market ticker BTC-USDT → 查看最新价格和24小时波动区间
↓ 用户确定下单价格
2. okx-cex-portfolio okx account balance USDT → 确认可用资金
↓ 用户确认操作
3. okx-cex-trade okx spot place --instId BTC-USDT --side buy --ordType limit --px <px> --sz <sz>Check funding rate before holding a perp position
持有永续合约前查询资金费率
User: "Is the BTC perp funding rate high right now?"
1. okx-cex-market okx market funding-rate BTC-USDT-SWAP → current rate + next funding time
2. okx-cex-market okx market funding-rate BTC-USDT-SWAP --history → trend over recent periods
↓ decide whether to hold position
3. okx-cex-portfolio okx account positions → check existing exposure用户:"现在BTC永续合约的资金费率高吗?"
1. okx-cex-market okx market funding-rate BTC-USDT-SWAP → 当前费率 + 下一次资金费结算时间
2. okx-cex-market okx market funding-rate BTC-USDT-SWAP --history → 最近几期的费率走势
↓ 决定是否持有仓位
3. okx-cex-portfolio okx account positions → 查看现有持仓敞口Research market before creating a grid bot
创建网格机器人前调研市场
User: "I want to set up a BTC grid bot — what's the recent range?"
1. okx-cex-market okx market candles BTC-USDT --bar 4H --limit 50 → recent OHLCV for range
2. okx-cex-market okx market ticker BTC-USDT → current price
3. okx-cex-market okx market orderbook BTC-USDT --sz 20 → liquidity check
↓ decide minPx / maxPx
4. okx-cex-bot okx bot grid create --instId BTC-USDT ...用户:"我想搭建一个BTC网格机器人,最近的价格区间是多少?"
1. okx-cex-market okx market candles BTC-USDT --bar 4H --limit 50 → 查看最近OHLCV确定价格区间
2. okx-cex-market okx market ticker BTC-USDT → 当前价格
3. okx-cex-market okx market orderbook BTC-USDT --sz 20 → 流动性检查
↓ 确定最低/最高价格
4. okx-cex-bot okx bot grid create --instId BTC-USDT ...Compare perp vs spot premium
对比永续合约和现货的溢价
User: "Is there a premium between BTC spot and BTC perp?"
1. okx-cex-market okx market ticker BTC-USDT → spot last price
2. okx-cex-market okx market ticker BTC-USDT-SWAP → perp last price
3. okx-cex-market okx market mark-price --instType SWAP --instId BTC-USDT-SWAP → mark price用户:"BTC现货和BTC永续合约之间有没有溢价?"
1. okx-cex-market okx market ticker BTC-USDT → 现货最新价格
2. okx-cex-market okx market ticker BTC-USDT-SWAP → 永续合约最新价格
3. okx-cex-market okx market mark-price --instType SWAP --instId BTC-USDT-SWAP → 标记价格Discover and price an option
查询期权品种和价格
User: "What's the price of a BTC call option expiring this week?"
1. okx-cex-market okx market open-interest --instType OPTION --instId BTC-USD → list active option instIds
↓ pick target instId from the list (e.g., BTC-USD-250328-95000-C)
2. okx-cex-market okx market ticker BTC-USD-250328-95000-C → option last price and stats
3. okx-cex-market okx market orderbook BTC-USD-250328-95000-C → bid/ask spreadNote:requiresokx market instruments --instType OPTION(e.g.,--uly <underlying>). If the underlying is unknown, use--uly BTC-USDfirst to discover active option instIds.open-interest
用户:"本周到期的BTC看涨期权价格是多少?"
1. okx-cex-market okx market open-interest --instType OPTION --instId BTC-USD → 列出活跃的期权品种ID
↓ 从列表中选择目标品种ID(例如BTC-USD-250328-95000-C)
2. okx-cex-market okx market ticker BTC-USD-250328-95000-C → 期权最新价格和统计数据
3. okx-cex-market okx market orderbook BTC-USD-250328-95000-C → 买卖价差注意:需要指定okx market instruments --instType OPTION(例如--uly <underlying>)。如果不知道标的资产,可以先使用--uly BTC-USD查询活跃的期权ID,再用这些ID调用open-interest。okx market ticker <instId>
Operation Flow
操作流程
Step 1: Identify the data needed
步骤1:确定所需数据
- Current price →
okx market ticker - All prices for a category →
okx market tickers - Order book depth →
okx market orderbook - Price history/chart →
okx market candles - Funding cost →
okx market funding-rate - Contract valuation → or
okx market mark-priceokx market price-limit - Market volume/OI →
okx market open-interest - What instruments exist →
okx market instruments
- 当前价格 →
okx market ticker - 某类品种的全部价格 →
okx market tickers - 订单簿深度 →
okx market orderbook - 价格历史/图表 →
okx market candles - 资金成本 →
okx market funding-rate - 合约估值 → 或
okx market mark-priceokx market price-limit - 市场成交量/持仓量 →
okx market open-interest - 可用交易品种查询 →
okx market instruments
Step 2: Run commands immediately
步骤2:直接运行命令
All market data commands are read-only — no confirmation needed.
- values:
--instType,SPOT,SWAP,FUTURESOPTION - values:
--bar,1m,3m,5m,15m,30m,1H,2H,4H,6H,12H,1D,1W1M - : number of results (default varies per endpoint, typically 100)
--limit - : for
--history, returns historical records instead of current ratefunding-rate
所有市场数据命令都是只读的——不需要确认。
- 可选值:
--instType,SPOT,SWAP,FUTURESOPTION - 可选值:
--bar,1m,3m,5m,15m,30m,1H,2H,4H,6H,12H,1D,1W1M - :返回结果数量(不同接口默认值不同,通常为100)
--limit - :用于
--history命令时,返回历史记录而非当前费率funding-rate
Step 3: No writes — no verification needed
步骤3:无写入操作——无需验证
All commands in this skill are read-only. No post-execution verification required.
本技能的所有命令都是只读的,执行后不需要做验证。
CLI Command Reference
CLI命令参考
Ticker — Single Instrument
行情查询——单个交易对
bash
okx market ticker <instId> [--json]Returns: , , , (24h change %).
last24h high/low24h volumesodUtc8bash
okx market ticker <instId> [--json]返回:(最新价)、(24小时高低价)、(24小时成交量)、(24小时涨跌幅%)。
last24h high/low24h volumesodUtc8Tickers — All Instruments of a Type
行情查询——某类全部交易对
bash
okx market tickers <instType> [--json]| Param | Required | Values | Description |
|---|---|---|---|
| Yes | | Instrument type |
Returns table: , , , , .
instIdlasthigh24hlow24hvol24hbash
okx market tickers <instType> [--json]| 参数 | 必填 | 可选值 | 描述 |
|---|---|---|---|
| 是 | | 交易品种类型 |
返回表格:、、、、。
instIdlasthigh24hlow24hvol24hInstruments — List Tradeable Instruments
交易品种——列出可交易标的
bash
okx market instruments --instType <type> [--instId <id>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | |
| No | - | Filter to a single instrument |
Returns: , , , , , . Displays up to 50 rows.
instIdctVallotSzminSztickSzstatebash
okx market instruments --instType <type> [--instId <id>] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | |
| 否 | - | 过滤单个交易对 |
返回:、、、、、。最多展示50行。
instIdctVallotSzminSztickSzstateOrder Book
订单簿
bash
okx market orderbook <instId> [--sz <n>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Instrument ID (e.g., |
| No | 5 | Depth levels per side (1–400) |
Displays top 5 asks (ascending) and bids (descending) with price and size.
bash
okx market orderbook <instId> [--sz <n>] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 交易对ID(例如 |
| 否 | 5 | 每边展示的档位数量(1–400) |
展示买盘(降序)和卖盘(升序)的前5档价格和数量。
Candles — OHLCV
K线——OHLCV
bash
okx market candles <instId> [--bar <bar>] [--limit <n>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Instrument ID |
| No | | Time granularity ( |
| No | 100 | Number of candles to return |
Returns columns: , , , , , .
timeopenhighlowclosevolbash
okx market candles <instId> [--bar <bar>] [--limit <n>] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 交易对ID |
| 否 | | 时间粒度( |
| 否 | 100 | 返回的K线数量 |
返回列:、、、、、。
timeopenhighlowclosevolIndex Candles
指数K线
bash
okx market index-candles <instId> [--bar <bar>] [--limit <n>] [--history] [--json]Same params as . Use index instrument IDs like (not ).
candlesBTC-USDBTC-USDTbash
okx market index-candles <instId> [--bar <bar>] [--limit <n>] [--history] [--json]参数和相同。使用指数ID例如(不是)。
candlesBTC-USDBTC-USDTFunding Rate
资金费率
bash
okx market funding-rate <instId> [--history] [--limit <n>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | SWAP instrument (e.g., |
| No | false | Return historical funding rates |
| No | - | Number of historical records |
Current (no ): returns , , , .
Historical (): table with , , .
--historyfundingRatenextFundingRatefundingTimenextFundingTime--historyfundingRaterealizedRatefundingTimebash
okx market funding-rate <instId> [--history] [--limit <n>] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | SWAP交易对(例如 |
| 否 | false | 返回历史资金费率 |
| 否 | - | 历史记录数量 |
当前费率(无参数):返回、、、。
历史费率(带参数):返回表格包含、、。
--historyfundingRatenextFundingRatefundingTimenextFundingTime--historyfundingRaterealizedRatefundingTimeRecent Trades
最近成交
bash
okx market trades <instId> [--limit <n>] [--json]Returns: , , , , .
tradeIdpxszsidetsbash
okx market trades <instId> [--limit <n>] [--json]返回:、、、、。
tradeIdpxszsidetsMark Price
标记价格
bash
okx market mark-price --instType <type> [--instId <id>] [--json]Returns: , , , . Used for liquidation price calculation and contract valuation.
instIdinstTypemarkPxtsbash
okx market mark-price --instType <type> [--instId <id>] [--json]返回:、、、。用于计算爆仓价格和合约估值。
instIdinstTypemarkPxtsIndex Ticker
指数行情
bash
okx market index-ticker [--instId <id>] [--quoteCcy <ccy>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Cond. | - | Index ID (e.g., |
| Cond. | - | Filter by quote currency (e.g., |
Returns: , , .
idxPxhigh24hlow24hbash
okx market index-ticker [--instId <id>] [--quoteCcy <ccy>] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 条件必填 | - | 指数ID(例如 |
| 条件必填 | - | 按计价货币过滤(例如 |
返回:、、。
idxPxhigh24hlow24hPrice Limit
涨跌停限制
bash
okx market price-limit <instId> [--json]Returns: (max buy price), (min sell price). Applies to SWAP and FUTURES only.
buyLmtsellLmtbash
okx market price-limit <instId> [--json]返回:(最高买价)、(最低卖价)。仅适用于SWAP和FUTURES品种。
buyLmtsellLmtOpen Interest
持仓量
bash
okx market open-interest --instType <type> [--instId <id>] [--json]Returns: (contracts), (base currency amount), .
oioiCcytsbash
okx market open-interest --instType <type> [--instId <id>] [--json]返回:(合约张数)、(标的货币数量)、。
oioiCcytsMCP Tool Reference
MCP工具参考
| Tool | Description |
|---|---|
| Single instrument ticker |
| All tickers for instType |
| List instruments |
| Order book depth |
| OHLCV candles |
| Index OHLCV candles |
| Funding rate (current or history) |
| Recent public trades |
| Mark price for contracts |
| Index price ticker |
| Price limits for contracts |
| Open interest |
| 工具 | 描述 |
|---|---|
| 单个交易对行情 |
| 某类交易对全部行情 |
| 交易品种列表 |
| 订单簿深度 |
| OHLCV K线 |
| 指数OHLCV K线 |
| 资金费率(当前或历史) |
| 最近公开成交记录 |
| 合约标记价格 |
| 指数价格行情 |
| 合约涨跌停限制 |
| 持仓量 |
Input / Output Examples
输入/输出示例
"What's the price of BTC?"
bash
okx market ticker BTC-USDT"BTC价格是多少?"
bash
okx market ticker BTC-USDT→ instId: BTC-USDT | last: 95000.5 | 24h change %: +1.2% | 24h high: 96000 | 24h low: 93000
→ instId: BTC-USDT | last: 95000.5 | 24h change %: +1.2% | 24h high: 96000 | 24h low: 93000
**"Show me all SWAP tickers"**
```bash
okx market tickers SWAP
**"给我看所有SWAP行情"**
```bash
okx market tickers SWAP→ table of all perpetual contracts with last price, 24h high/low/vol
→ 所有永续合约的表格,包含最新价格、24小时高低价/成交量
**"What's the BTC/USDT order book look like?"**
```bash
okx market orderbook BTC-USDT
**"BTC/USDT的订单簿是什么样的?"**
```bash
okx market orderbook BTC-USDTAsks (price / size):
卖盘(价格 / 数量):
95100.0 2.5
95100.0 2.5
95050.0 1.2
95050.0 1.2
Bids (price / size):
买盘(价格 / 数量):
95000.0 3.1
95000.0 3.1
94950.0 0.8
94950.0 0.8
**"Show me BTC 4H candles for the last 30 periods"**
```bash
okx market candles BTC-USDT --bar 4H --limit 30
**"给我看最近30根BTC 4小时K线"**
```bash
okx market candles BTC-USDT --bar 4H --limit 30→ table: time, open, high, low, close, vol
→ 表格:时间, 开盘价, 最高价, 最低价, 收盘价, 成交量
**"What's the current funding rate for BTC perp?"**
```bash
okx market funding-rate BTC-USDT-SWAP
**"BTC永续合约当前的资金费率是多少?"**
```bash
okx market funding-rate BTC-USDT-SWAP→ fundingRate: 0.0001 | nextFundingRate: 0.00012 | fundingTime: ... | nextFundingTime: ...
→ fundingRate: 0.0001 | nextFundingRate: 0.00012 | fundingTime: ... | nextFundingTime: ...
**"Show historical funding rates for ETH perp"**
```bash
okx market funding-rate ETH-USDT-SWAP --history --limit 20
**"给我看ETH永续合约的历史资金费率"**
```bash
okx market funding-rate ETH-USDT-SWAP --history --limit 20→ table: fundingRate, realizedRate, fundingTime
→ 表格:fundingRate, realizedRate, fundingTime
**"What's the open interest on BTC perp?"**
```bash
okx market open-interest --instType SWAP --instId BTC-USDT-SWAP
**"BTC永续合约的持仓量是多少?"**
```bash
okx market open-interest --instType SWAP --instId BTC-USDT-SWAP→ oi: 125000 | oiCcy: 125000 | ts: ...
→ oi: 125000 | oiCcy: 125000 | ts: ...
**"List all available SPOT instruments"**
```bash
okx market instruments --instType SPOT
**"列出所有可用的现货交易对"**
```bash
okx market instruments --instType SPOT→ table: instId, ctVal, lotSz, minSz, tickSz, state (up to 50 rows)
→ 表格:instId, ctVal, lotSz, minSz, tickSz, state(最多50行)
undefinedundefinedEdge Cases
边界情况
- instId format: SPOT uses ; SWAP uses
BTC-USDT; FUTURES usesBTC-USDT-SWAP; OPTION usesBTC-USDT-250328; Index usesBTC-USD-250328-95000-CBTC-USD - OPTION instruments — cannot list directly: requires
okx market instruments --instType OPTION(underlying). If the underlying is unknown, run--uly BTC-USDfirst to discover active option instIds from the results, then use those instIds withokx market open-interest --instType OPTIONokx market ticker <instId> - No data returned: instrument may be delisted or instId is wrong — verify with
okx market instruments - funding-rate: only applies to SWAP instruments; returns error for SPOT/FUTURES
- price-limit: only applies to SWAP and FUTURES instruments
- mark-price: available for SWAP, FUTURES, OPTION; not applicable to SPOT
- candles --bar: use uppercase ,
H,D,Wfor hour/day/week/month (e.g.,Mnot1H)1h - index-ticker: use format (not
BTC-USD) for index IDsBTC-USDT - orderbook --sz: max depth is 400; default display shows top 5 per side regardless of
--sz
- instId格式:现货用;永续合约用
BTC-USDT;交割合约用BTC-USDT-SWAP;期权用BTC-USDT-250328;指数用BTC-USD-250328-95000-CBTC-USD - 期权品种——无法直接列出:需要指定
okx market instruments --instType OPTION(标的资产)。如果不知道标的资产,先运行--uly BTC-USD从结果中找到活跃的期权ID,再用这些ID调用okx market open-interest --instType OPTIONokx market ticker <instId> - 无数据返回:交易对可能已退市或者instId错误——可以用验证
okx market instruments - funding-rate:仅适用于SWAP品种;现货/交割合约调用会返回错误
- price-limit:仅适用于SWAP和FUTURES品种
- mark-price:支持SWAP、FUTURES、OPTION;不适用于现货
- candles --bar:小时/天/周/月粒度要使用大写的、
H、D、W(例如M不是1H)1h - index-ticker:指数ID使用格式(不是
BTC-USD)BTC-USDT - orderbook --sz:最大深度是400;无论设置为多少,默认只展示每边前5档
--sz
Global Notes
全局说明
- All market data commands are public — no API key required
- returns raw OKX API v5 response for programmatic use
--json - has no effect on market commands (no auth needed)
--profile <name> - Rate limit: 20 requests per 2 seconds per IP for market data endpoints
- Candle data is sorted newest-first by default
- in tickers is in base currency (e.g., BTC for BTC-USDT)
vol24h
- 所有市场数据命令都是公开的——不需要API密钥
- 参数返回原始OKX API v5响应,适合程序调用
--json - 参数对市场命令无效(不需要鉴权)
--profile <name> - 接口限流:每个IP每2秒最多请求20次市场数据接口
- K线数据默认按时间倒序排列,最新的在前
- 行情中的是标的货币计价的成交量(例如BTC-USDT的成交量单位是BTC)
vol24h