OKX CEX Market Data CLI
Compliance notice: This skill provides raw market data only. No strategy, recommendation, or optimization logic is embedded. All indicator outputs are objective numerical values; interpretation and trading decisions remain solely with the user.
Public market data for OKX: prices, order books, candles, funding rates, open interest, instrument info, and technical indicators. All commands are read-only and require no API credentials.
Skill routing
- - Market data / indicators →
okx-cex-market (this skill) - Account balance / positions → INLINECODE1
- Place / cancel orders → INLINECODE2
- Grid / DCA bots → INLINECODE3
Preflight
Before running any command, follow ../_shared/preflight.md.
Use metadata.version from this file's frontmatter as the reference for Step 2.
Install
CODEBLOCK0
Market data commands return the same public data regardless of demo/live mode — no API credentials required. If the user's profile has demo=true set and they want live data context, they can use --live to confirm they are in live mode (it has no effect on public market data but clarifies environment). Always inform the user which environment is active (demo or live) when it is relevant to their query. No confirmation needed before running any market command. Add --json to any command for raw OKX API v5 response. Add --env to wrap the output as {"env", "profile", "data"}.
Command Index
| # | Command | Description |
|---|
| 1 | INLINECODE11 | Last price, 24h high/low/vol/change% |
| 2 |
okx market tickers <instType> | All tickers for SPOT / SWAP / FUTURES / OPTION |
| 3 |
okx market instruments --instType <type> [--instId <id>] | List instruments (instId, ctVal, lotSz, minSz, tickSz, state) |
| 4 |
okx market orderbook <instId> [--sz <n>] | Order book asks/bids (default top 5 per side, max 400) |
| 5 |
okx market candles <instId> [--bar <bar>] [--limit <n>] [--after <ts>] [--before <ts>] | OHLCV candles (default
--bar 1m); auto-routes to historical endpoint for data back to 2021;
--after paginates back in time,
--before paginates forward |
| 6 |
okx market index-candles <instId> [--bar <bar>] [--limit <n>] [--history] | Index OHLCV (use
BTC-USD not
BTC-USDT) |
| 7 |
okx market funding-rate <instId> [--history] [--limit <n>] | Current or historical funding rate (SWAP only) |
| 8 |
okx market trades <instId> [--limit <n>] | Recent public trades |
| 9 |
okx market mark-price --instType <type> [--instId <id>] | Mark price (SWAP / FUTURES / OPTION) |
| 10 |
okx market index-ticker [--instId <id>] [--quoteCcy <ccy>] | Index price (e.g., BTC-USD) |
| 11 |
okx market price-limit <instId> | Upper/lower price limits (SWAP / FUTURES only) |
| 12 |
okx market open-interest --instType <type> [--instId <id>] | Open interest in contracts and base currency |
| 13 |
okx market instruments-by-category --instCategory <3\|4\|5\|6\|7> | Discover instruments by asset category: 3=Stock tokens (AAPL/TSLA), 4=Metals (gold/silver), 5=Commodities (oil/gas), 6=Forex (EUR/USD), 7=Bonds |
| 13† |
okx market stock-tokens |
Deprecated — use
instruments-by-category --instCategory 3 instead |
| 15 |
okx market indicator list | List all supported indicator names and descriptions |
| 16 |
okx market indicator <indicator> <instId> [--bar] [--params] [--list] [--limit] [--backtest-time] | Technical indicator values |
Operation Flow
Step 1 — Identify data type and load reference
| User intent | Reference to load |
|---|
| Price, candles, order book, recent trades | INLINECODE33 |
| Technical indicators (RSI, MACD, EMA, BB, KDJ, SuperTrend, AHR999, Rainbow, etc.) |
{baseDir}/references/indicator-commands.md |
| Funding rate, mark price, open interest, price limit, index ticker |
{baseDir}/references/derivatives-commands.md |
| List instruments, discover stock tokens, metals/commodities/forex/bonds, find option instIds |
{baseDir}/references/instrument-commands.md |
| Multi-step or cross-skill workflows; MCP tool names |
{baseDir}/references/workflows.md |
Step 2 — Run commands immediately
All market data commands are read-only — no confirmation needed.
Step 3 — No writes, no verification needed
All commands in this skill are read-only.
Edge Cases
- - instId format: SPOT
BTC-USDT · SWAP BTC-USDT-SWAP · FUTURES BTC-USDT-250328 · OPTION BTC-USD-250328-95000-C · Index BTC-USD · Stock token TSLA-USDT-SWAP · Metals/Commodities/Forex/Bonds: use instruments-by-category to discover valid instIds first - OPTION listing:
instruments --instType OPTION requires --uly BTC-USD; if unknown, run open-interest --instType OPTION first to discover active instIds - funding-rate / price-limit: SWAP only · mark-price: SWAP / FUTURES / OPTION only
- candles
--bar: uppercase — 1H not 1h; use --after <ts> to paginate back into historical data (back to 2021); index-candles supports --history for extended history - ⚠️ Large historical range: before fetching with
--after/--before, estimate candle count = time_range_ms / bar_interval_ms. If estimate > 500, tell the user the estimated count and ask for confirmation before proceeding. This prevents silently filling the context window. - indicator
--bar: uses 1Dutc not 1D, 1Wutc not 1W — different from candle bar values - indicator arg order: indicator name before instId — INLINECODE61
- indicator
--params: comma-separated, no spaces — INLINECODE63 - BTC-only indicators:
ahr999, rainbow — BTC-USDT only - Unknown indicator name: the API returns empty data silently — run
okx market indicator list to confirm a name is supported before use - Stock token hours: US stocks trade Mon–Fri ~09:30–16:00 ET; verify live price before acting
- No data returned: instrument may be delisted — verify with INLINECODE67
boll is an alias for INLINECODE69
Global Notes
- - No API key required for any command in this skill
- Rate limit: 20 req / 2 s per IP
- Candle data is sorted newest-first
- INLINECODE70 is in base currency (e.g., BTC for BTC-USDT)
- INLINECODE71 and
--demo/--live do not affect market data results via CLI (public endpoints); they only determine the active trading environment context - When calling market MCP tools directly, pass
demo: true to explicitly query simulated trading market data; the default is always live market data regardless of server demo mode
OKX CEX 市场数据 CLI
合规声明:本技能仅提供原始市场数据。不嵌入任何策略、建议或优化逻辑。所有指标输出均为客观数值;解读和交易决策完全由用户自行负责。
OKX 公开市场数据:价格、订单簿、K线、资金费率、持仓量、合约信息和技术指标。所有命令均为只读,且无需 API 凭证。
技能路由
- - 市场数据/指标 → okx-cex-market(本技能)
- 账户余额/持仓 → okx-cex-portfolio
- 下单/撤单 → okx-cex-trade
- 网格/定投机器人 → okx-cex-bot
前置检查
在执行任何命令之前,请遵循 ../_shared/preflight.md。
使用本文档前置元数据中的 metadata.version 作为步骤 2 的参考。
安装
bash
npm install -g @okx_ai/okx-trade-cli
okx market ticker BTC-USDT # 验证
市场数据命令无论演示/实盘模式均返回相同的公开数据——无需 API 凭证。如果用户配置文件设置了 demo=true 且希望获取实盘数据上下文,可使用 --live 确认处于实盘模式(对公开市场数据无影响,但可明确环境)。当与用户查询相关时,始终告知用户当前处于哪个环境(演示或实盘)。运行任何市场命令前无需确认。在任何命令后添加 --json 可获取原始 OKX API v5 响应。添加 --env 可将输出包装为 {env, profile, data} 格式。
命令索引
| # | 命令 | 描述 |
|---|
| 1 | okx market ticker <instId> | 最新价格、24小时最高/最低/成交量/涨跌幅% |
| 2 |
okx market tickers
| 获取 SPOT / SWAP / FUTURES / OPTION 的所有行情 |
| 3 | okx market instruments --instType [--instId ] | 列出合约信息(instId、ctVal、lotSz、minSz、tickSz、state) |
| 4 | okx market orderbook [--sz ] | 订单簿卖盘/买盘(默认每边前5档,最多400档) |
| 5 | okx market candles [--bar ] [--limit ] [--after ] [--before ] | OHLCV K线(默认 --bar 1m);自动路由至历史数据端点获取2021年以来的数据;--after 向后翻页,--before 向前翻页 |
| 6 | okx market index-candles [--bar ] [--limit ] [--history] | 指数 OHLCV(使用 BTC-USD 而非 BTC-USDT) |
| 7 | okx market funding-rate [--history] [--limit ] | 当前或历史资金费率(仅限 SWAP) |
| 8 | okx market trades [--limit ] | 近期公开成交记录 |
| 9 | okx market mark-price --instType [--instId ] | 标记价格(SWAP / FUTURES / OPTION) |
| 10 | okx market index-ticker [--instId ] [--quoteCcy ] | 指数价格(例如 BTC-USD) |
| 11 | okx market price-limit | 价格涨跌停限制(仅限 SWAP / FUTURES) |
| 12 | okx market open-interest --instType [--instId ] | 以合约数和基础币种计量的持仓量 |
| 13 | okx market instruments-by-category --instCategory <3\|4\|5\|6\|7> | 按资产类别发现合约:3=股票代币(AAPL/TSLA)、4=金属(黄金/白银)、5=大宗商品(石油/天然气)、6=外汇(EUR/USD)、7=债券 |
| 13† | okx market stock-tokens | 已弃用——请改用 instruments-by-category --instCategory 3 |
| 15 | okx market indicator list | 列出所有支持的指标名称和描述 |
| 16 | okx market indicator [--bar] [--params] [--list] [--limit] [--backtest-time] | 技术指标数值 |
操作流程
步骤 1 — 识别数据类型并加载参考
| 用户意图 | 需加载的参考 |
|---|
| 价格、K线、订单簿、近期成交 | {baseDir}/references/price-data-commands.md |
| 技术指标(RSI、MACD、EMA、BB、KDJ、SuperTrend、AHR999、Rainbow 等) |
{baseDir}/references/indicator-commands.md |
| 资金费率、标记价格、持仓量、价格限制、指数行情 | {baseDir}/references/derivatives-commands.md |
| 列出合约、发现股票代币、金属/大宗商品/外汇/债券、查找期权 instId | {baseDir}/references/instrument-commands.md |
| 多步骤或跨技能工作流;MCP 工具名称 | {baseDir}/references/workflows.md |
步骤 2 — 立即运行命令
所有市场数据命令均为只读——无需确认。
步骤 3 — 无需写入,无需验证
本技能中的所有命令均为只读。
边界情况
- - instId 格式:SPOT BTC-USDT · SWAP BTC-USDT-SWAP · FUTURES BTC-USDT-250328 · OPTION BTC-USD-250328-95000-C · 指数 BTC-USD · 股票代币 TSLA-USDT-SWAP · 金属/大宗商品/外汇/债券:先使用 instruments-by-category 发现有效的 instId
- OPTION 列表:instruments --instType OPTION 需要 --uly BTC-USD;如未知,先运行 open-interest --instType OPTION 发现活跃的 instId
- funding-rate / price-limit:仅限 SWAP · mark-price:仅限 SWAP / FUTURES / OPTION
- candles --bar:大写——1H 而非 1h;使用 --after 向后翻页获取历史数据(可回溯至2021年);index-candles 支持 --history 获取更长的历史数据
- ⚠️ 大范围历史数据:在使用 --after/--before 获取数据前,估算 K线数量 = 时间范围毫秒数 / K线间隔毫秒数。如果估算值超过 500,告知用户估算数量并请求确认后再继续。这可以防止静默填满上下文窗口。
- indicator --bar:使用 1Dutc 而非 1D、1Wutc 而非 1W——与 K线 bar 值不同
- indicator 参数顺序:指标名称在 instId 之前——okx market indicator rsi BTC-USDT
- indicator --params:逗号分隔,无空格——--params 5,20
- 仅限 BTC 的指标:ahr999、rainbow——仅限 BTC-USDT
- 未知指标名称:API 静默返回空数据——使用前运行 okx market indicator list 确认名称是否受支持
- 股票代币交易时间:美股交易时间为周一至周五约美东时间 09:30–16:00;操作前请验证实时价格
- 无数据返回:合约可能已下架——使用 okx market instruments 验证
- boll 是 bb 的别名
全局说明
- - 本技能中所有命令均无需 API 密钥
- 速率限制:每个 IP 每 2 秒 20 次请求
- K线数据按最新优先排序
- vol24h 以基础币种计(例如 BTC-USDT 中的 BTC)
- 通过 CLI 时,--profile 和 --demo/--live 不影响市场数据结果(公开端点);它们仅决定活跃交易环境上下文
- 直接调用市场 M