okx-cex-trade

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OKX CEX Trading CLI

OKX CEX 交易CLI

Spot, perpetual swap, delivery futures, and options order management on OKX exchange. Place, cancel, amend, and monitor orders; query option chains and Greeks; set take-profit/stop-loss and trailing stops; manage leverage and positions. Requires API credentials.
用于在OKX交易所进行现货、永续掉期、交割期货和期权订单管理。支持下单、撤单、改单、订单监控;查询期权链和Greeks;设置止盈/止损和移动止损;管理杠杆和持仓。需要API凭证。

Prerequisites

前置要求

  1. Install
    okx
    CLI:
    bash
    npm install -g @okx_ai/okx-trade-cli
  2. Configure credentials:
    bash
    okx config init
    Or set environment variables:
    bash
    export OKX_API_KEY=your_key
    export OKX_SECRET_KEY=your_secret
    export OKX_PASSPHRASE=your_passphrase
  3. Test with demo mode (simulated trading, no real funds):
    bash
    okx --demo spot orders
  1. 安装
    okx
    CLI:
    bash
    npm install -g @okx_ai/okx-trade-cli
  2. 配置凭证:
    bash
    okx config init
    或设置环境变量:
    bash
    export OKX_API_KEY=your_key
    export OKX_SECRET_KEY=your_secret
    export OKX_PASSPHRASE=your_passphrase
  3. 使用演示模式测试(模拟交易,不涉及真实资金):
    bash
    okx --demo spot orders

Demo vs Live Mode

演示模式 vs 实盘模式

CRITICAL: Always confirm demo vs live before any write command (place, cancel, amend, close, leverage, algo).
重要提示:执行任何写入命令(下单、撤单、改单、平仓、调整杠杆、算法订单)前,务必确认当前是演示模式还是实盘模式。

How to check current mode

如何查看当前模式

bash
okx config show       # shows current profile settings
bash
okx config show       # 显示当前配置文件设置

How to switch mode per command

如何按命令切换模式

Prepend
--demo
to run in simulated trading mode (no real funds affected):
bash
okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
okx --demo swap close --instId BTC-USDT-SWAP --mgnMode cross
Omit
--demo
to execute on the live account (real funds).
命令前添加
--demo
即可在模拟交易模式下运行(不影响真实资金):
bash
okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
okx --demo swap close --instId BTC-USDT-SWAP --mgnMode cross
省略
--demo
则会在实盘账户执行(涉及真实资金)。

Rules for this skill

本skill使用规则

  1. Before every write command, explicitly ask or confirm: "Execute on live account or demo (simulated)?" — do not assume.
  2. Read commands (orders, positions, fills, get, algo orders): run immediately; note which mode was used.
  3. When executing demo, prefix the response summary with
    [DEMO]
    and state no real funds were affected.
  4. When executing live, prefix the response summary with
    [LIVE]
    and flag that real funds are involved.
  5. If the user says "try it" / "test it" / "simulate" / "paper trade" → use
    --demo
    .
  6. If the user says "real" / "actual" / "go live" / "execute" → confirm once more before running without
    --demo
    .
  1. 执行每条写入命令前,需要明确询问或确认:"在实盘账户执行还是演示(模拟)账户执行?" 不要自行假设。
  2. 读取类命令(订单、持仓、成交、查询、算法订单):可直接运行,注明使用的模式即可。
  3. 执行演示模式命令后,回复摘要前添加
    [DEMO]
    ,并说明未涉及真实资金。
  4. 执行实盘模式命令后,回复摘要前添加
    [LIVE]
    ,并提示涉及真实资金。
  5. 如果用户说“试试”/“测试”/“模拟”/“仿真交易” → 使用
    --demo
  6. 如果用户说“实盘”/“真实交易”/“上线”/“执行” → 再次确认后再不带
    --demo
    运行。

Example

示例

User: "Buy 0.01 BTC"
Agent: "Execute on live account (real funds) or demo (simulated)?"
User: "Demo"
Agent runs: okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
Agent replies: "[DEMO] Order placed: 7890123456 (OK) — simulated, no real funds used."
用户: "买入0.01 BTC"
Agent: "在实盘账户(真实资金)执行还是演示(模拟)账户执行?"
用户: "演示"
Agent运行: okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
Agent回复: "[DEMO] 订单已提交:7890123456(成功) — 模拟交易,未使用真实资金。"

Skill Routing

Skill路由规则

  • For market data (prices, charts, depth, funding rates) → use
    okx-cex-market
  • For account balance, P&L, positions, fees, transfers → use
    okx-cex-portfolio
  • For regular spot/swap/futures/options/algo orders → use
    okx-cex-trade
    (this skill)
  • For grid and DCA trading bots → use
    okx-cex-bot
  • 行情数据(价格、K线、深度、资金费率)→ 使用
    okx-cex-market
  • 账户余额、盈亏、持仓、手续费、转账 → 使用
    okx-cex-portfolio
  • 常规现货/掉期/期货/期权/算法订单 → 使用
    okx-cex-trade
    (本skill)
  • 网格和DCA交易机器人 → 使用
    okx-cex-bot

Quickstart

快速开始

bash
undefined
bash
undefined

Market buy 0.01 BTC (spot)

市价买入0.01 BTC(现货)

okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.01

Limit sell 0.01 BTC at $100,000 (spot)

限价100,000美元卖出0.01 BTC(现货)

okx spot place --instId BTC-USDT --side sell --ordType limit --sz 0.01 --px 100000
okx spot place --instId BTC-USDT --side sell --ordType limit --sz 0.01 --px 100000

Long 1 contract BTC perp (cross margin)

做多1张BTC永续合约(全仓保证金)

okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1
--tdMode cross --posSide long
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1
--tdMode cross --posSide long

Close BTC perp long position entirely at market

市价全平BTC永续合约多单

okx swap close --instId BTC-USDT-SWAP --mgnMode cross --posSide long
okx swap close --instId BTC-USDT-SWAP --mgnMode cross --posSide long

Set 10x leverage on BTC perp (cross)

设置BTC永续合约(全仓)杠杆为10倍

okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross
okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross

Set TP/SL on a spot BTC position (sell when price hits $105k, SL at $88k)

为BTC现货持仓设置止盈止损(价格到10.5万美元卖出,止损设为8.8万美元)

okx spot algo place --instId BTC-USDT --side sell --ordType oco --sz 0.01
--tpTriggerPx 105000 --tpOrdPx -1
--slTriggerPx 88000 --slOrdPx -1
okx spot algo place --instId BTC-USDT --side sell --ordType oco --sz 0.01
--tpTriggerPx 105000 --tpOrdPx -1
--slTriggerPx 88000 --slOrdPx -1

Place trailing stop on BTC perp long (callback 2%)

为BTC永续合约多单设置移动止损(回调比例2%)

okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 1
--tdMode cross --posSide long --callbackRatio 0.02
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 1
--tdMode cross --posSide long --callbackRatio 0.02

View open spot orders

查看未成交现货订单

okx spot orders
okx spot orders

View open swap positions

查看未平掉期持仓

okx swap positions
okx swap positions

Cancel a spot order

取消一笔现货订单

okx spot cancel --instId BTC-USDT --ordId <ordId>
undefined
okx spot cancel --instId BTC-USDT --ordId <ordId>
undefined

Command Index

命令索引

Spot Orders

现货订单

#CommandTypeDescription
1
okx spot place
WRITEPlace spot order (market/limit/post_only/fok/ioc)
2
okx spot cancel
WRITECancel spot order
3
okx spot amend
WRITEAmend spot order price or size
4
okx spot algo place
WRITEPlace spot TP/SL algo order
5
okx spot algo amend
WRITEAmend spot TP/SL levels
6
okx spot algo cancel
WRITECancel spot algo order
7
okx spot orders
READList open or historical spot orders
8
okx spot get
READSingle spot order details
9
okx spot fills
READSpot trade fill history
10
okx spot algo orders
READList spot TP/SL algo orders
#CommandType说明
1
okx spot place
WRITE下现货订单(市价/限价/post_only/fok/ioc)
2
okx spot cancel
WRITE取消现货订单
3
okx spot amend
WRITE修改现货订单的价格或数量
4
okx spot algo place
WRITE下现货止盈止损算法订单
5
okx spot algo amend
WRITE修改现货止盈止损档位
6
okx spot algo cancel
WRITE取消现货算法订单
7
okx spot orders
READ列出未成交或历史现货订单
8
okx spot get
READ单个现货订单详情
9
okx spot fills
READ现货成交历史
10
okx spot algo orders
READ列出现货止盈止损算法订单

Swap / Perpetual Orders

掉期/永续合约订单

#CommandTypeDescription
11
okx swap place
WRITEPlace perpetual swap order
12
okx swap cancel
WRITECancel swap order
13
okx swap amend
WRITEAmend swap order price or size
14
okx swap close
WRITEClose entire position at market
15
okx swap leverage
WRITESet leverage for an instrument
16
okx swap algo place
WRITEPlace swap TP/SL algo order
17
okx swap algo trail
WRITEPlace swap trailing stop order
18
okx swap algo amend
WRITEAmend swap algo order
19
okx swap algo cancel
WRITECancel swap algo order
20
okx swap positions
READOpen perpetual swap positions
21
okx swap orders
READList open or historical swap orders
22
okx swap get
READSingle swap order details
23
okx swap fills
READSwap trade fill history
24
okx swap get-leverage
READCurrent leverage settings
25
okx swap algo orders
READList swap algo orders
#CommandType说明
11
okx swap place
WRITE下永续掉期订单
12
okx swap cancel
WRITE取消掉期订单
13
okx swap amend
WRITE修改掉期订单的价格或数量
14
okx swap close
WRITE市价全平持仓
15
okx swap leverage
WRITE设置交易对杠杆
16
okx swap algo place
WRITE下掉期止盈止损算法订单
17
okx swap algo trail
WRITE下掉期移动止损订单
18
okx swap algo amend
WRITE修改掉期算法订单
19
okx swap algo cancel
WRITE取消掉期算法订单
20
okx swap positions
READ未平永续掉期持仓
21
okx swap orders
READ列出未成交或历史掉期订单
22
okx swap get
READ单个掉期订单详情
23
okx swap fills
READ掉期成交历史
24
okx swap get-leverage
READ当前杠杆设置
25
okx swap algo orders
READ列出掉期算法订单

Futures / Delivery Orders

期货/交割合约订单

#CommandTypeDescription
26
okx futures place
WRITEPlace delivery futures order
27
okx futures cancel
WRITECancel delivery futures order
28
okx futures orders
READList delivery futures orders
29
okx futures positions
READOpen delivery futures positions
30
okx futures fills
READDelivery futures fill history
31
okx futures get
READSingle delivery futures order details
#CommandType说明
26
okx futures place
WRITE下交割期货订单
27
okx futures cancel
WRITE取消交割期货订单
28
okx futures orders
READ列出交割期货订单
29
okx futures positions
READ未平交割期货持仓
30
okx futures fills
READ交割期货成交历史
31
okx futures get
READ单个交割期货订单详情

Options Orders

期权订单

#CommandTypeDescription
32
okx option instruments
READOption chain: list available contracts for an underlying
33
okx option greeks
READImplied volatility + Greeks (delta/gamma/theta/vega) by underlying
34
okx option place
WRITEPlace option order (call or put, buyer or seller)
35
okx option cancel
WRITECancel unfilled option order
36
okx option amend
WRITEAmend option order price or size
37
okx option batch-cancel
WRITEBatch cancel up to 20 option orders
38
okx option orders
READList option orders (live / history / archive)
39
okx option get
READSingle option order details
40
okx option positions
READOpen option positions with live Greeks
41
okx option fills
READOption trade fill history
#CommandType说明
32
okx option instruments
READ期权链:列出标的的可用合约
33
okx option greeks
READ标的的隐含波动率 + Greeks(delta/gamma/theta/vega)
34
okx option place
WRITE下期权订单(看涨/看跌,买方/卖方)
35
okx option cancel
WRITE取消未成交期权订单
36
okx option amend
WRITE修改期权订单的价格或数量
37
okx option batch-cancel
WRITE批量取消最多20笔期权订单
38
okx option orders
READ列出期权订单(未成交/历史/归档)
39
okx option get
READ单个期权订单详情
40
okx option positions
READ带实时Greeks的未平期权持仓
41
okx option fills
READ期权成交历史

Cross-Skill Workflows

跨Skill工作流

Spot market buy

现货市价买入

User: "Buy $500 worth of ETH at market"
1. okx-cex-market    okx market ticker ETH-USDT             → get current price to estimate sz
2. okx-cex-portfolio okx account balance USDT               → confirm available funds ≥ $500
        ↓ user approves
3. okx-cex-trade     okx spot place --instId ETH-USDT --side buy --ordType market --sz <sz>
4. okx-cex-trade     okx spot fills --instId ETH-USDT        → confirm fill price and size
用户: "市价买入价值500美元的ETH"
1. okx-cex-market    okx market ticker ETH-USDT             → 获取当前价格估算下单数量
2. okx-cex-portfolio okx account balance USDT               → 确认可用资金≥500美元
        ↓ 用户确认同意
3. okx-cex-trade     okx spot place --instId ETH-USDT --side buy --ordType market --sz <sz>
4. okx-cex-trade     okx spot fills --instId ETH-USDT        → 确认成交价格和数量

Open long BTC perp with TP/SL

开BTC永续合约多单并设置止盈止损

User: "Long 5 contracts BTC perp at market, TP at $105k, SL at $88k"
1. okx-cex-portfolio okx account balance USDT               → confirm margin available
2. okx-cex-portfolio okx account max-size --instId BTC-USDT-SWAP --tdMode cross → confirm size ok
        ↓ user approves
3. okx-cex-trade     okx swap place --instId BTC-USDT-SWAP --side buy \
                       --ordType market --sz 5 --tdMode cross --posSide long
4. okx-cex-trade     okx swap algo place --instId BTC-USDT-SWAP --side sell \
                       --ordType oco --sz 5 --tdMode cross --posSide long \
                       --tpTriggerPx 105000 --tpOrdPx -1 \
                       --slTriggerPx 88000 --slOrdPx -1
5. okx-cex-trade     okx swap positions                     → confirm position opened
用户: "市价做多5张BTC永续合约,止盈10.5万美元,止损8.8万美元"
1. okx-cex-portfolio okx account balance USDT               → 确认可用保证金充足
2. okx-cex-portfolio okx account max-size --instId BTC-USDT-SWAP --tdMode cross → 确认下单数量合规
        ↓ 用户确认同意
3. okx-cex-trade     okx swap place --instId BTC-USDT-SWAP --side buy \
                       --ordType market --sz 5 --tdMode cross --posSide long
4. okx-cex-trade     okx swap algo place --instId BTC-USDT-SWAP --side sell \
                       --ordType oco --sz 5 --tdMode cross --posSide long \
                       --tpTriggerPx 105000 --tpOrdPx -1 \
                       --slTriggerPx 88000 --slOrdPx -1
5. okx-cex-trade     okx swap positions                     → 确认持仓已开

Adjust leverage then place order

调整杠杆后下单

User: "Set BTC perp to 5x leverage then go long 10 contracts"
1. okx-cex-trade     okx swap get-leverage --instId BTC-USDT-SWAP --mgnMode cross → check current lever
        ↓ user approves change
2. okx-cex-trade     okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross
3. okx-cex-trade     okx swap place --instId BTC-USDT-SWAP --side buy \
                       --ordType market --sz 10 --tdMode cross --posSide long
4. okx-cex-trade     okx swap positions                     → confirm position + leverage
用户: "把BTC永续合约杠杆设为5倍,然后做多10张"
1. okx-cex-trade     okx swap get-leverage --instId BTC-USDT-SWAP --mgnMode cross → 查看当前杠杆
        ↓ 用户确认同意修改
2. okx-cex-trade     okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross
3. okx-cex-trade     okx swap place --instId BTC-USDT-SWAP --side buy \
                       --ordType market --sz 10 --tdMode cross --posSide long
4. okx-cex-trade     okx swap positions                     → 确认持仓和杠杆设置

Place trailing stop on open position

为已开持仓设置移动止损

User: "Set a 3% trailing stop on my BTC perp long"
1. okx-cex-trade     okx swap positions                     → confirm size of open long
2. okx-cex-market    okx market ticker BTC-USDT-SWAP        → current price reference
        ↓ user approves
3. okx-cex-trade     okx swap algo trail --instId BTC-USDT-SWAP --side sell \
                       --sz <pos_size> --tdMode cross --posSide long --callbackRatio 0.03
4. okx-cex-trade     okx swap algo orders --instId BTC-USDT-SWAP → confirm trail order placed
用户: "为我的BTC永续合约多单设置3%的移动止损"
1. okx-cex-trade     okx swap positions                     → 确认未平多单的数量
2. okx-cex-market    okx market ticker BTC-USDT-SWAP        → 当前价格参考
        ↓ 用户确认同意
3. okx-cex-trade     okx swap algo trail --instId BTC-USDT-SWAP --side sell \
                       --sz <pos_size> --tdMode cross --posSide long --callbackRatio 0.03
4. okx-cex-trade     okx swap algo orders --instId BTC-USDT-SWAP → 确认移动止损订单已提交

Cancel all open spot orders

取消所有未成交现货订单

User: "Cancel all my open BTC spot orders"
1. okx-cex-trade     okx spot orders                        → list open orders
2. okx-cex-trade     (for each ordId) okx spot cancel --instId BTC-USDT --ordId <id>
3. okx-cex-trade     okx spot orders                        → confirm all cancelled
用户: "取消我所有未成交的BTC现货订单"
1. okx-cex-trade     okx spot orders                        → 列出未成交订单
2. okx-cex-trade     (遍历每个ordId) okx spot cancel --instId BTC-USDT --ordId <id>
3. okx-cex-trade     okx spot orders                        → 确认所有订单已取消

Buy a BTC call option

买入BTC看涨期权

User: "Buy 2 BTC call options at strike 95000 expiring end of March"
1. okx-cex-trade     okx option instruments --uly BTC-USD --expTime 250328
                     → find exact instId (e.g. BTC-USD-250328-95000-C)
2. okx-cex-trade     okx option greeks --uly BTC-USD --expTime 250328
                     → check IV, delta, and markPx to assess fair value
3. okx-cex-portfolio okx account balance                    → confirm enough USDT/BTC for premium
        ↓ user approves
4. okx-cex-trade     okx option place --instId BTC-USD-250328-95000-C \
                       --side buy --ordType limit --tdMode cash --sz 2 --px 0.005
5. okx-cex-trade     okx option orders                      → confirm order is live
用户: "买入2张行权价95000、3月底到期的BTC看涨期权"
1. okx-cex-trade     okx option instruments --uly BTC-USD --expTime 250328
                     → 找到准确的instId(例如BTC-USD-250328-95000-C)
2. okx-cex-trade     okx option greeks --uly BTC-USD --expTime 250328
                     → 查看IV、delta和标记价格评估合理价值
3. okx-cex-portfolio okx account balance                    → 确认有足够的USDT/BTC支付权利金
        ↓ 用户确认同意
4. okx-cex-trade     okx option place --instId BTC-USD-250328-95000-C \
                       --side buy --ordType limit --tdMode cash --sz 2 --px 0.005
5. okx-cex-trade     okx option orders                      → 确认订单已生效

Check option portfolio Greeks

查看期权组合Greeks

User: "What's my total delta exposure from options?"
1. okx-cex-trade     okx option positions                   → live positions with per-contract Greeks
2. okx-cex-market    okx market ticker BTC-USD              → current spot price for context
用户: "我的期权持仓总delta敞口是多少?"
1. okx-cex-trade     okx option positions                   → 带单合约Greeks的实时持仓
2. okx-cex-market    okx market ticker BTC-USD              → 当前现货价格作为参考

Operation Flow

操作流程

Step 1: Identify instrument type and action

步骤1:识别交易对类型和操作

Spot (instId format:
BTC-USDT
):
  • Place/cancel/amend order →
    okx spot place/cancel/amend
  • TP/SL conditional →
    okx spot algo place/amend/cancel
  • Query →
    okx spot orders/get/fills/algo orders
Swap/Perpetual (instId format:
BTC-USDT-SWAP
):
  • Place/cancel/amend order →
    okx swap place/cancel/amend
  • Close position →
    okx swap close
  • Leverage →
    okx swap leverage
    /
    okx swap get-leverage
  • TP/SL conditional →
    okx swap algo place/amend/cancel
  • Trailing stop →
    okx swap algo trail
  • Query →
    okx swap positions/orders/get/fills/get-leverage/algo orders
Futures/Delivery (instId format:
BTC-USDT-250328
):
  • Place/cancel order →
    okx futures place/cancel
  • Query →
    okx futures orders/positions/fills/get
Options (instId format:
BTC-USD-250328-95000-C
or
...-P
):
  • Step 1 (required): find valid instId →
    okx option instruments --uly BTC-USD
  • Step 2 (recommended): check IV and Greeks →
    okx option greeks --uly BTC-USD
  • Place/cancel/amend order →
    okx option place/cancel/amend
  • Batch cancel →
    okx option batch-cancel --orders '[...]'
  • Query →
    okx option orders/get/positions/fills
  • tdMode:
    cash
    for buyers (full premium upfront, no liquidation risk);
    cross
    or
    isolated
    for sellers (margin required)
现货(instId格式:
BTC-USDT
):
  • 下/撤/改订单 →
    okx spot place/cancel/amend
  • 止盈止损条件单 →
    okx spot algo place/amend/cancel
  • 查询 →
    okx spot orders/get/fills/algo orders
掉期/永续合约(instId格式:
BTC-USDT-SWAP
):
  • 下/撤/改订单 →
    okx swap place/cancel/amend
  • 平仓 →
    okx swap close
  • 杠杆设置 →
    okx swap leverage
    /
    okx swap get-leverage
  • 止盈止损条件单 →
    okx swap algo place/amend/cancel
  • 移动止损 →
    okx swap algo trail
  • 查询 →
    okx swap positions/orders/get/fills/get-leverage/algo orders
期货/交割合约(instId格式:
BTC-USDT-250328
):
  • 下/撤订单 →
    okx futures place/cancel
  • 查询 →
    okx futures orders/positions/fills/get
期权(instId格式:
BTC-USD-250328-95000-C
...-P
):
  • 步骤1(必填):找到有效的instId →
    okx option instruments --uly BTC-USD
  • 步骤2(推荐):查看IV和Greeks →
    okx option greeks --uly BTC-USD
  • 下/撤/改订单 →
    okx option place/cancel/amend
  • 批量取消 →
    okx option batch-cancel --orders '[...]'
  • 查询 →
    okx option orders/get/positions/fills
  • tdMode: 买方用
    cash
    (全额预付权利金,无爆仓风险);卖方用
    cross
    isolated
    (需要保证金)

Step 2: Confirm demo vs live, then confirm write parameters

步骤2:确认演示/实盘模式,再确认写入参数

Read commands (orders, positions, fills, get, get-leverage, algo orders): run immediately; note the mode used.
  • --history
    flag: defaults to active/open; use
    --history
    only if user explicitly asks for history
  • --ordType
    for algo:
    conditional
    = single TP or SL;
    oco
    = both TP and SL together
  • --tdMode
    for swap/futures:
    cross
    or
    isolated
    ; spot always uses
    cash
    (set automatically)
  • --posSide
    for hedge mode:
    long
    or
    short
    ; omit in net mode
Write commands (place, cancel, amend, close, leverage, algo): two confirmations required:
  1. Demo or live? — Ask the user before the first write in any session. If unclear, default to asking.
    • Demo → prepend
      --demo
      to every write command; label result
      [DEMO]
    • Live → execute without
      --demo
      ; label result
      [LIVE]
  2. Confirm parameters — confirm the key order details once before executing:
    • Spot place: confirm
      --instId
      ,
      --side
      ,
      --ordType
      ,
      --sz
      ; price (
      --px
      ) required for limit orders
    • Swap place: confirm
      --instId
      ,
      --side
      ,
      --sz
      ,
      --tdMode
      ; confirm
      --posSide
      if in hedge mode
    • Swap close: confirm
      --instId
      ,
      --mgnMode
      ,
      --posSide
      ; closes the entire position at market
    • Swap leverage: confirm new leverage and impact on existing positions; cannot exceed exchange max
    • Algo place (TP/SL): confirm trigger prices; use
      --tpOrdPx -1
      for market execution at trigger
    • Algo trail: confirm
      --callbackRatio
      (e.g.,
      0.02
      = 2%) or
      --callbackSpread
      (fixed price spread)
读取类命令(订单、持仓、成交、查询、获取杠杆、算法订单):可直接运行,注明使用的模式即可。
  • --history
    标志:默认返回活跃/未成交订单;仅当用户明确要求查历史时才使用
    --history
  • 算法单的
    --ordType
    conditional
    = 单一止盈或止损;
    oco
    = 止盈止损二合一
  • 掉期/期货的
    --tdMode
    cross
    (全仓)或
    isolated
    (逐仓);现货默认使用
    cash
    (自动设置)
  • 对冲模式下的
    --posSide
    long
    (多)或
    short
    (空);净持仓模式下可省略
写入类命令(下单、撤单、改单、平仓、调整杠杆、算法单):需要两次确认:
  1. 演示还是实盘? — 每个会话第一次执行写入命令前询问用户。如果不明确,默认询问。
    • 演示 → 每条写入命令前添加
      --demo
      ;结果标注
      [DEMO]
    • 实盘 → 不带
      --demo
      执行;结果标注
      [LIVE]
  2. 确认参数 — 执行前再次确认核心订单细节:
    • 现货下单:确认
      --instId
      --side
      --ordType
      --sz
      ;限价单需要确认价格
      --px
    • 掉期下单:确认
      --instId
      --side
      --sz
      --tdMode
      ;对冲模式下确认
      --posSide
    • 掉期平仓:确认
      --instId
      --mgnMode
      --posSide
      ;将市价全平对应持仓
    • 掉期杠杆调整:确认新杠杆值以及对现有持仓的影响;不能超过交易所最大限制
    • 算法单(止盈止损):确认触发价格;
      --tpOrdPx -1
      表示触发后市价执行
    • 移动止损:确认
      --callbackRatio
      (例如
      0.02
      =2%)或
      --callbackSpread
      (固定价差)

Step 3: Verify after writes

步骤3:写入操作后验证

  • After
    spot place
    : run
    okx spot orders
    to confirm order is live or
    okx spot fills
    if market order
  • After
    swap place
    : run
    okx swap orders
    or
    okx swap positions
    to confirm
  • After
    swap close
    : run
    okx swap positions
    to confirm position size is 0
  • After algo place: run
    okx spot algo orders
    or
    okx swap algo orders
    to confirm algo is active
  • After cancel: run
    okx spot orders
    /
    okx swap orders
    to confirm order is gone
  • 现货下单后:运行
    okx spot orders
    确认订单已生效,市价单可运行
    okx spot fills
    查看成交
  • 掉期下单后:运行
    okx swap orders
    okx swap positions
    确认
  • 掉期平仓后:运行
    okx swap positions
    确认持仓数量为0
  • 算法单提交后:运行
    okx spot algo orders
    okx swap algo orders
    确认算法单已激活
  • 撤单后:运行
    okx spot orders
    /
    okx swap orders
    确认订单已消失

CLI Command Reference

CLI命令参考

Order Type Reference

订单类型参考

--ordType
DescriptionRequires
--px
market
Fill immediately at best priceNo
limit
Fill at specified price or betterYes
post_only
Limit order; cancelled if it would be a takerYes
fok
Fill entire order immediately or cancelYes
ioc
Fill what's available immediately, cancel restYes
conditional
Algo: single TP or SL triggerNo (set trigger px)
oco
Algo: TP + SL together (one cancels other)No (set both trigger px)
move_order_stop
Trailing stop (swap only)No (set callback)

--ordType
说明需要
--px
market
以最优价格立即成交
limit
以指定价格或更优价格成交
post_only
限价单;如果会成为吃单方则自动取消
fok
立即全部成交否则取消
ioc
立即成交可成交部分,剩余部分取消
conditional
算法单:单一止盈或止损触发否(设置触发价即可)
oco
算法单:止盈止损二合一(一个触发另一个自动取消)否(设置两个触发价即可)
move_order_stop
移动止损(仅掉期支持)否(设置回调参数即可)

Spot — Place Order

现货 — 下单

bash
okx spot place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
  [--px <price>] [--json]
ParamRequiredDefaultDescription
--instId
Yes-Spot instrument (e.g.,
BTC-USDT
)
--side
Yes-
buy
or
sell
--ordType
Yes-
market
,
limit
,
post_only
,
fok
,
ioc
--sz
Yes-Order size in base currency (e.g., BTC amount)
--px
Cond.-Price — required for
limit
,
post_only
,
fok
,
ioc

bash
okx spot place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
  [--px <price>] [--json]
参数必填默认值说明
--instId
-现货交易对(例如
BTC-USDT
--side
-
buy
(买)或
sell
(卖)
--ordType
-
market
,
limit
,
post_only
,
fok
,
ioc
--sz
-以计价货币为单位的订单数量(例如BTC数量)
--px
条件必填-价格 —
limit
post_only
fok
ioc
类型必填

Spot — Cancel Order

现货 — 撤单

bash
okx spot cancel --instId <id> --ordId <id> [--json]

bash
okx spot cancel --instId <id> --ordId <id> [--json]

Spot — Amend Order

现货 — 改单

bash
okx spot amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
  [--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of
--newSz
or
--newPx
.

bash
okx spot amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
  [--newSz <n>] [--newPx <p>] [--json]
必须至少提供
--newSz
--newPx
中的一个。

Spot — Place Algo (TP/SL)

现货 — 下算法单(止盈止损)

bash
okx spot algo place --instId <id> --side <buy|sell> --ordType <oco|conditional> --sz <n> \
  [--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
  [--slTriggerPx <p>] [--slOrdPx <p|-1>] \
  [--json]
ParamRequiredDefaultDescription
--tpTriggerPx
Cond.-Take-profit trigger price
--tpOrdPx
Cond.-TP order price; use
-1
for market execution
--slTriggerPx
Cond.-Stop-loss trigger price
--slOrdPx
Cond.-SL order price; use
-1
for market execution
For
oco
: provide both TP and SL params. For
conditional
: provide only TP or only SL.

bash
okx spot algo place --instId <id> --side <buy|sell> --ordType <oco|conditional> --sz <n> \
  [--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
  [--slTriggerPx <p>] [--slOrdPx <p|-1>] \
  [--json]
参数必填默认值说明
--tpTriggerPx
条件必填-止盈触发价格
--tpOrdPx
条件必填-止盈订单价格;
-1
表示市价执行
--slTriggerPx
条件必填-止损触发价格
--slOrdPx
条件必填-止损订单价格;
-1
表示市价执行
oco
类型需要同时提供止盈和止损参数。
conditional
类型仅需提供止盈或仅提供止损。

Spot — Amend Algo

现货 — 修改算法单

bash
okx spot algo amend --instId <id> --algoId <id> \
  [--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
  [--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]

bash
okx spot algo amend --instId <id> --algoId <id> \
  [--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
  [--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]

Spot — Cancel Algo

现货 — 取消算法单

bash
okx spot algo cancel --instId <id> --algoId <id> [--json]

bash
okx spot algo cancel --instId <id> --algoId <id> [--json]

Spot — List Orders

现货 — 订单列表

bash
okx spot orders [--instId <id>] [--history] [--json]
FlagEffect
(default)Open/pending orders
--history
Historical (filled, cancelled) orders

bash
okx spot orders [--instId <id>] [--history] [--json]
标志效果
(默认)未成交/待处理订单
--history
历史订单(已成交、已取消)

Spot — Get Order

现货 — 获取订单详情

bash
okx spot get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns:
ordId
,
instId
,
side
,
ordType
,
px
,
sz
,
fillSz
,
avgPx
,
state
,
cTime
.

bash
okx spot get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
返回:
ordId
,
instId
,
side
,
ordType
,
px
,
sz
,
fillSz
,
avgPx
,
state
,
cTime
.

Spot — Fills

现货 — 成交记录

bash
okx spot fills [--instId <id>] [--ordId <id>] [--json]
Returns:
instId
,
side
,
fillPx
,
fillSz
,
fee
,
ts
.

bash
okx spot fills [--instId <id>] [--ordId <id>] [--json]
返回:
instId
,
side
,
fillPx
,
fillSz
,
fee
,
ts
.

Spot — Algo Orders

现货 — 算法单列表

bash
okx spot algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
Returns:
algoId
,
instId
, type,
side
,
sz
,
tpTrigger
,
slTrigger
,
state
.

bash
okx spot algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
返回:
algoId
,
instId
, type,
side
,
sz
,
tpTrigger
,
slTrigger
,
state
.

Swap — Place Order

掉期 — 下单

bash
okx swap place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--px <price>] [--json]
ParamRequiredDefaultDescription
--instId
Yes-Swap instrument (e.g.,
BTC-USDT-SWAP
)
--side
Yes-
buy
or
sell
--ordType
Yes-
market
,
limit
,
post_only
,
fok
,
ioc
--sz
Yes-Number of contracts
--tdMode
Yes-
cross
or
isolated
--posSide
Cond.-
long
or
short
— required in hedge mode
--px
Cond.-Price — required for limit orders

bash
okx swap place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--px <price>] [--json]
参数必填默认值说明
--instId
-掉期交易对(例如
BTC-USDT-SWAP
--side
-
buy
(买)或
sell
(卖)
--ordType
-
market
,
limit
,
post_only
,
fok
,
ioc
--sz
-合约张数
--tdMode
-
cross
(全仓)或
isolated
(逐仓)
--posSide
条件必填-
long
(多)或
short
(空) — 对冲模式下必填
--px
条件必填-价格 — 限价单必填

Swap — Cancel Order

掉期 — 撤单

bash
okx swap cancel --instId <id> --ordId <id> [--json]

bash
okx swap cancel --instId <id> --ordId <id> [--json]

Swap — Amend Order

掉期 — 改单

bash
okx swap amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
  [--newSz <n>] [--newPx <p>] [--json]

bash
okx swap amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
  [--newSz <n>] [--newPx <p>] [--json]

Swap — Close Position

掉期 — 平仓

bash
okx swap close --instId <id> --mgnMode <cross|isolated> \
  [--posSide <long|short>] [--autoCxl] [--json]
ParamRequiredDefaultDescription
--instId
Yes-Swap instrument
--mgnMode
Yes-
cross
or
isolated
--posSide
Cond.-
long
or
short
— required in hedge mode
--autoCxl
NofalseAuto-cancel pending orders before closing
Closes the entire position at market price.

bash
okx swap close --instId <id> --mgnMode <cross|isolated> \
  [--posSide <long|short>] [--autoCxl] [--json]
参数必填默认值说明
--instId
-掉期交易对
--mgnMode
-
cross
(全仓)或
isolated
(逐仓)
--posSide
条件必填-
long
(多)或
short
(空) — 对冲模式下必填
--autoCxl
false平仓前自动取消未成交订单
将以市价全平对应持仓。

Swap — Set Leverage

掉期 — 设置杠杆

bash
okx swap leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
  [--posSide <long|short>] [--json]
ParamRequiredDefaultDescription
--instId
Yes-Swap instrument
--lever
Yes-Leverage multiplier (e.g.,
10
)
--mgnMode
Yes-
cross
or
isolated
--posSide
Cond.-
long
or
short
— required for isolated mode in hedge mode

bash
okx swap leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
  [--posSide <long|short>] [--json]
参数必填默认值说明
--instId
-掉期交易对
--lever
-杠杆倍数(例如
10
--mgnMode
-
cross
(全仓)或
isolated
(逐仓)
--posSide
条件必填-
long
(多)或
short
(空) — 对冲模式下逐仓必填

Swap — Get Leverage

掉期 — 获取杠杆

bash
okx swap get-leverage --instId <id> --mgnMode <cross|isolated> [--json]
Returns table:
instId
,
mgnMode
,
posSide
,
lever
.

bash
okx swap get-leverage --instId <id> --mgnMode <cross|isolated> [--json]
返回表格:
instId
,
mgnMode
,
posSide
,
lever
.

Swap — Place Algo (TP/SL)

掉期 — 下算法单(止盈止损)

bash
okx swap algo place --instId <id> --side <buy|sell> --ordType <oco|conditional> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--reduceOnly] \
  [--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
  [--slTriggerPx <p>] [--slOrdPx <p|-1>] \
  [--json]
--reduceOnly
: close-only; will not open a new position if one doesn't exist.

bash
okx swap algo place --instId <id> --side <buy|sell> --ordType <oco|conditional> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--reduceOnly] \
  [--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
  [--slTriggerPx <p>] [--slOrdPx <p|-1>] \
  [--json]
--reduceOnly
:仅减仓;如果没有对应持仓则不会开新仓。

Swap — Place Trailing Stop

掉期 — 下移动止损单

bash
okx swap algo trail --instId <id> --side <buy|sell> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--reduceOnly] \
  [--callbackRatio <ratio>] [--callbackSpread <spread>] \
  [--activePx <price>] \
  [--json]
ParamRequiredDefaultDescription
--callbackRatio
Cond.-Trailing callback as a ratio (e.g.,
0.02
= 2%); use this or
--callbackSpread
--callbackSpread
Cond.-Trailing callback as fixed price distance
--activePx
No-Price at which trailing stop becomes active

bash
okx swap algo trail --instId <id> --side <buy|sell> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--reduceOnly] \
  [--callbackRatio <ratio>] [--callbackSpread <spread>] \
  [--activePx <price>] \
  [--json]
参数必填默认值说明
--callbackRatio
条件必填-回调比例(例如
0.02
=2%);二选一,和
--callbackSpread
互斥
--callbackSpread
条件必填-固定回调价差
--activePx
-移动止损生效的触发价格

Swap — Amend Algo

掉期 — 修改算法单

bash
okx swap algo amend --instId <id> --algoId <id> \
  [--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
  [--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]

bash
okx swap algo amend --instId <id> --algoId <id> \
  [--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
  [--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]

Swap — Cancel Algo

掉期 — 取消算法单

bash
okx swap algo cancel --instId <id> --algoId <id> [--json]

bash
okx swap algo cancel --instId <id> --algoId <id> [--json]

Swap — List Orders

掉期 — 订单列表

bash
okx swap orders [--instId <id>] [--history] [--json]

bash
okx swap orders [--instId <id>] [--history] [--json]

Swap — Get Order

掉期 — 获取订单详情

bash
okx swap get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns:
ordId
,
instId
,
side
,
posSide
,
ordType
,
px
,
sz
,
fillSz
,
avgPx
,
state
,
cTime
.

bash
okx swap get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
返回:
ordId
,
instId
,
side
,
posSide
,
ordType
,
px
,
sz
,
fillSz
,
avgPx
,
state
,
cTime
.

Swap — Positions

掉期 — 持仓列表

bash
okx swap positions [<instId>] [--json]
Returns:
instId
,
side
,
size
,
avgPx
,
upl
,
uplRatio
,
lever
. Only non-zero positions.

bash
okx swap positions [<instId>] [--json]
返回:
instId
,
side
,
size
,
avgPx
,
upl
,
uplRatio
,
lever
。仅返回非零持仓。

Swap — Fills

掉期 — 成交记录

bash
okx swap fills [--instId <id>] [--ordId <id>] [--archive] [--json]
--archive
: access older fills beyond the default window.

bash
okx swap fills [--instId <id>] [--ordId <id>] [--archive] [--json]
--archive
:访问默认时间窗口外的更早成交记录。

Swap — Algo Orders

掉期 — 算法单列表

bash
okx swap algo orders [--instId <id>] [--history] [--ordType <type>] [--json]

bash
okx swap algo orders [--instId <id>] [--history] [--ordType <type>] [--json]

Futures — Place Order

期货 — 下单

bash
okx futures place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--px <price>] [--reduceOnly] [--json]
--instId
format:
BTC-USDT-250328
(delivery date suffix).

bash
okx futures place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
  --tdMode <cross|isolated> \
  [--posSide <long|short>] [--px <price>] [--reduceOnly] [--json]
--instId
格式:
BTC-USDT-250328
(带交割日期后缀)。

Futures — Cancel Order

期货 — 撤单

bash
okx futures cancel --instId <id> --ordId <id> [--json]

bash
okx futures cancel --instId <id> --ordId <id> [--json]

Futures — List Orders

期货 — 订单列表

bash
okx futures orders [--instId <id>] [--status <open|history|archive>] [--json]
--status
Effect
open
Active/pending orders (default)
history
Recent completed/cancelled
archive
Older history

bash
okx futures orders [--instId <id>] [--status <open|history|archive>] [--json]
--status
效果
open
活跃/待处理订单(默认)
history
近期已完成/已取消订单
archive
更早的历史订单

Futures — Positions

期货 — 持仓列表

bash
okx futures positions [<instId>] [--json]
Returns:
instId
,
side
,
pos
,
avgPx
,
upl
,
lever
.

bash
okx futures positions [<instId>] [--json]
返回:
instId
,
side
,
pos
,
avgPx
,
upl
,
lever
.

Futures — Fills

期货 — 成交记录

bash
okx futures fills [--instId <id>] [--ordId <id>] [--archive] [--json]

bash
okx futures fills [--instId <id>] [--ordId <id>] [--archive] [--json]

Futures — Get Order

期货 — 获取订单详情

bash
okx futures get --instId <id> [--ordId <id>] [--json]

bash
okx futures get --instId <id> [--ordId <id>] [--json]

Option — Get Instruments (Option Chain)

期权 — 获取合约列表(期权链)

bash
okx option instruments --uly <underlying> [--expTime <YYMMDD>] [--json]
ParamRequiredDescription
--uly
YesUnderlying, e.g.
BTC-USD
or
ETH-USD
--expTime
NoFilter by expiry date, e.g.
250328
Returns:
instId
,
uly
,
expTime
,
stk
(strike),
optType
(C/P),
state
.
Run this before placing any option order to get the exact
instId
.

bash
okx option instruments --uly <underlying> [--expTime <YYMMDD>] [--json]
参数必填说明
--uly
标的资产,例如
BTC-USD
ETH-USD
--expTime
按到期日过滤,例如
250328
返回:
instId
,
uly
,
expTime
,
stk
(行权价),
optType
(C/P),
state
.
下任何期权订单前必须运行此命令获取准确的
instId

Option — Get Greeks

期权 — 获取Greeks

bash
okx option greeks --uly <underlying> [--expTime <YYMMDD>] [--json]
Returns IV (
markVol
) and BS Greeks (
deltaBS
,
gammaBS
,
thetaBS
,
vegaBS
) plus
markPx
for each contract.

bash
okx option greeks --uly <underlying> [--expTime <YYMMDD>] [--json]
返回每个合约的IV(
markVol
)和BS模型Greeks(
deltaBS
,
gammaBS
,
thetaBS
,
vegaBS
)以及
markPx
(标记价格)。

Option — Place Order

期权 — 下单

bash
okx option place --instId <id> --side <buy|sell> --ordType <type> \
  --tdMode <cash|cross|isolated> --sz <n> \
  [--px <price>] [--reduceOnly] [--clOrdId <id>] [--json]
ParamRequiredDefaultDescription
--instId
Yes-e.g.
BTC-USD-250328-95000-C
(call) or
...-P
(put)
--side
Yes-
buy
or
sell
--ordType
Yes-
market
,
limit
,
post_only
,
fok
,
ioc
--tdMode
Yes-
cash
= buyer (full premium);
cross
/
isolated
= seller (margin)
--sz
Yes-Number of contracts
--px
Cond.-Required for
limit
,
post_only
,
fok
,
ioc
--reduceOnly
NofalseClose-only; do not open a new position
tdMode rules:
  • Buyer (
    side=buy
    ): always use
    cash
    — pay full premium, no margin call risk
  • Seller (
    side=sell
    ): use
    cross
    or
    isolated
    — margin required, liquidation risk

bash
okx option place --instId <id> --side <buy|sell> --ordType <type> \
  --tdMode <cash|cross|isolated> --sz <n> \
  [--px <price>] [--reduceOnly] [--clOrdId <id>] [--json]
参数必填默认值说明
--instId
-例如
BTC-USD-250328-95000-C
(看涨)或
...-P
(看跌)
--side
-
buy
(买)或
sell
(卖)
--ordType
-
market
,
limit
,
post_only
,
fok
,
ioc
--tdMode
-
cash
= 买方(全额付权利金);
cross
/
isolated
= 卖方(需要保证金)
--sz
-合约张数
--px
条件必填-
limit
post_only
fok
ioc
类型必填
--reduceOnly
false仅减仓;不会开新仓
tdMode规则:
  • 买方(
    side=buy
    ):始终使用
    cash
    — 全额支付权利金,无爆仓风险
  • 卖方(
    side=sell
    ):使用
    cross
    isolated
    — 需要保证金,有爆仓风险

Option — Cancel Order

期权 — 撤单

bash
okx option cancel --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]

bash
okx option cancel --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]

Option — Amend Order

期权 — 改单

bash
okx option amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
  [--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of
--newSz
or
--newPx
.

bash
okx option amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
  [--newSz <n>] [--newPx <p>] [--json]
必须至少提供
--newSz
--newPx
中的一个。

Option — Batch Cancel

期权 — 批量撤单

bash
okx option batch-cancel --orders '<JSON>' [--json]
--orders
is a JSON array of up to 20 objects, each
{"instId":"...","ordId":"..."}
:
bash
okx option batch-cancel --orders '[{"instId":"BTC-USD-250328-95000-C","ordId":"123"},{"instId":"BTC-USD-250328-90000-P","ordId":"456"}]'

bash
okx option batch-cancel --orders '<JSON>' [--json]
--orders
是最多包含20个对象的JSON数组,每个对象格式为
{"instId":"...","ordId":"..."}
bash
okx option batch-cancel --orders '[{"instId":"BTC-USD-250328-95000-C","ordId":"123"},{"instId":"BTC-USD-250328-90000-P","ordId":"456"}]'

Option — List Orders

期权 — 订单列表

bash
okx option orders [--instId <id>] [--uly <underlying>] [--history] [--archive] [--json]
FlagEffect
(default)Live/pending orders
--history
Historical (7d)
--archive
Older archive (3mo)

bash
okx option orders [--instId <id>] [--uly <underlying>] [--history] [--archive] [--json]
标志效果
(默认)活跃/待处理订单
--history
历史订单(7天内)
--archive
归档历史订单(3个月内)

Option — Get Order

期权 — 获取订单详情

bash
okx option get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns:
ordId
,
instId
,
side
,
ordType
,
px
,
sz
,
fillSz
,
avgPx
,
state
,
cTime
.

bash
okx option get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
返回:
ordId
,
instId
,
side
,
ordType
,
px
,
sz
,
fillSz
,
avgPx
,
state
,
cTime
.

Option — Positions

期权 — 持仓列表

bash
okx option positions [--instId <id>] [--uly <underlying>] [--json]
Returns:
instId
,
posSide
,
pos
,
avgPx
,
upl
,
deltaPA
,
gammaPA
,
thetaPA
,
vegaPA
. Only non-zero positions shown.

bash
okx option positions [--instId <id>] [--uly <underlying>] [--json]
返回:
instId
,
posSide
,
pos
,
avgPx
,
upl
,
deltaPA
,
gammaPA
,
thetaPA
,
vegaPA
。仅返回非零持仓。

Option — Fills

期权 — 成交记录

bash
okx option fills [--instId <id>] [--ordId <id>] [--archive] [--json]
--archive
: access fills beyond the default 3-day window (up to 3 months).

bash
okx option fills [--instId <id>] [--ordId <id>] [--archive] [--json]
--archive
:访问默认3天窗口外的更早成交记录(最多3个月)。

MCP Tool Reference

MCP工具参考

ToolDescription
spot_place_order
Place spot order
spot_cancel_order
Cancel spot order
spot_amend_order
Amend spot order
spot_place_algo_order
Place spot TP/SL algo
spot_amend_algo_order
Amend spot algo
spot_cancel_algo_order
Cancel spot algo
spot_get_orders
List spot orders
spot_get_order
Get single spot order
spot_get_fills
Spot fill history
spot_get_algo_orders
List spot algo orders
swap_place_order
Place swap order
swap_cancel_order
Cancel swap order
swap_amend_order
Amend swap order
swap_close_position
Close swap position
swap_set_leverage
Set swap leverage
swap_place_algo_order
Place swap TP/SL algo
swap_place_move_stop_order
Place swap trailing stop
swap_amend_algo_order
Amend swap algo
swap_cancel_algo_orders
Cancel swap algo
swap_get_positions
Swap positions
swap_get_orders
List swap orders
swap_get_order
Get single swap order
swap_get_fills
Swap fill history
swap_get_leverage
Get swap leverage
swap_get_algo_orders
List swap algo orders
futures_place_order
Place futures order
futures_cancel_order
Cancel futures order
futures_get_orders
List futures orders
futures_get_positions
Futures positions
futures_get_fills
Futures fill history
futures_get_order
Get single futures order
option_get_instruments
Option chain (list available contracts)
option_get_greeks
IV and Greeks by underlying
option_place_order
Place option order
option_cancel_order
Cancel option order
option_amend_order
Amend option order
option_batch_cancel
Batch cancel up to 20 option orders
option_get_orders
List option orders
option_get_order
Get single option order
option_get_positions
Option positions with live Greeks
option_get_fills
Option fill history

工具说明
spot_place_order
下现货订单
spot_cancel_order
取消现货订单
spot_amend_order
修改现货订单
spot_place_algo_order
下现货止盈止损算法单
spot_amend_algo_order
修改现货算法单
spot_cancel_algo_order
取消现货算法单
spot_get_orders
列出现货订单
spot_get_order
获取单个现货订单详情
spot_get_fills
现货成交历史
spot_get_algo_orders
列出现货算法订单
swap_place_order
下掉期订单
swap_cancel_order
取消掉期订单
swap_amend_order
修改掉期订单
swap_close_position
平掉期持仓
swap_set_leverage
设置掉期杠杆
swap_place_algo_order
下掉期止盈止损算法单
swap_place_move_stop_order
下掉期移动止损单
swap_amend_algo_order
修改掉期算法单
swap_cancel_algo_orders
取消掉期算法单
swap_get_positions
掉期持仓列表
swap_get_orders
列出掉期订单
swap_get_order
获取单个掉期订单详情
swap_get_fills
掉期成交历史
swap_get_leverage
获取掉期杠杆
swap_get_algo_orders
列出掉期算法订单
futures_place_order
下期货订单
futures_cancel_order
取消期货订单
futures_get_orders
列出期货订单
futures_get_positions
期货持仓列表
futures_get_fills
期货成交历史
futures_get_order
获取单个期货订单详情
option_get_instruments
期权链(列出可用合约)
option_get_greeks
标的的IV和Greeks
option_place_order
下期权订单
option_cancel_order
取消期权订单
option_amend_order
修改期权订单
option_batch_cancel
批量取消最多20笔期权订单
option_get_orders
列出期权订单
option_get_order
获取单个期权订单详情
option_get_positions
带实时Greeks的期权持仓
option_get_fills
期权成交历史

Input / Output Examples

输入输出示例

"Buy 0.05 BTC at market"
bash
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.05
"市价买入0.05 BTC"
bash
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.05

→ Order placed: 7890123456 (OK)

→ 订单已提交:7890123456(成功)


**"Set a limit sell for 0.1 ETH at $3500"**
```bash
okx spot place --instId ETH-USDT --side sell --ordType limit --sz 0.1 --px 3500

**"设置限价3500美元卖出0.1 ETH"**
```bash
okx spot place --instId ETH-USDT --side sell --ordType limit --sz 0.1 --px 3500

→ Order placed: 7890123457 (OK)

→ 订单已提交:7890123457(成功)


**"Show my open spot orders"**
```bash
okx spot orders

**"查看我未成交的现货订单"**
```bash
okx spot orders

→ table: ordId, instId, side, type, price, size, filled, state

→ 返回表格:ordId, instId, side, type, price, size, filled, state


**"Long 10 contracts BTC perp at market (cross margin)"**
```bash
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 10 \
  --tdMode cross --posSide long

**"市价做多10张BTC永续合约(全仓保证金)"**
```bash
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 10 \
  --tdMode cross --posSide long

→ Order placed: 7890123458 (OK)

→ 订单已提交:7890123458(成功)


**"Set take profit at $105k and stop loss at $88k on BTC perp long"**
```bash
okx swap algo place --instId BTC-USDT-SWAP --side sell --ordType oco --sz 10 \
  --tdMode cross --posSide long \
  --tpTriggerPx 105000 --tpOrdPx -1 \
  --slTriggerPx 88000 --slOrdPx -1

**"为BTC永续合约多单设置止盈10.5万美元,止损8.8万美元"**
```bash
okx swap algo place --instId BTC-USDT-SWAP --side sell --ordType oco --sz 10 \
  --tdMode cross --posSide long \
  --tpTriggerPx 105000 --tpOrdPx -1 \
  --slTriggerPx 88000 --slOrdPx -1

→ Algo order placed: ALGO456789 (OK)

→ 算法订单已提交:ALGO456789(成功)


**"Close my ETH perp position"**
```bash
okx swap close --instId ETH-USDT-SWAP --mgnMode cross --posSide long

**"平掉我的ETH永续合约持仓"**
```bash
okx swap close --instId ETH-USDT-SWAP --mgnMode cross --posSide long

→ Position closed: ETH-USDT-SWAP long

→ 持仓已平仓:ETH-USDT-SWAP 多单


**"Set BTC perp leverage to 5x (cross)"**
```bash
okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross

**"把BTC永续合约(全仓)杠杆设为5倍"**
```bash
okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross

→ Leverage set: 5x BTC-USDT-SWAP

→ 杠杆已设置:BTC-USDT-SWAP 5倍


**"Place a 2% trailing stop on my BTC perp long"**
```bash
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 10 \
  --tdMode cross --posSide long --callbackRatio 0.02

**"为我的BTC永续合约多单设置2%的移动止损"**
```bash
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 10 \
  --tdMode cross --posSide long --callbackRatio 0.02

→ Trailing stop placed: TRAIL123 (OK)

→ 移动止损已提交:TRAIL123(成功)


**"Show my open swap positions"**
```bash
okx swap positions

**"查看我未平的掉期持仓"**
```bash
okx swap positions

→ table: instId, side, size, avgPx, upl, uplRatio, lever

→ 返回表格:instId, side, size, avgPx, upl, uplRatio, lever


**"What are my recent fill trades for BTC spot?"**
```bash
okx spot fills --instId BTC-USDT

**"我BTC现货的近期成交记录是什么?"**
```bash
okx spot fills --instId BTC-USDT

→ table: instId, side, fillPx, fillSz, fee, ts

→ 返回表格:instId, side, fillPx, fillSz, fee, ts


**"Show me the BTC option chain expiring March 28"**
```bash
okx option instruments --uly BTC-USD --expTime 250328

**"查看3月28日到期的BTC期权链"**
```bash
okx option instruments --uly BTC-USD --expTime 250328

→ table: instId, expTime, stk, optType (C/P), state

→ 返回表格:instId, expTime, stk, optType (C/P), state


**"What's the IV and delta for BTC options expiring March 28?"**
```bash
okx option greeks --uly BTC-USD --expTime 250328

**"3月28日到期的BTC期权的IV和delta是多少?"**
```bash
okx option greeks --uly BTC-USD --expTime 250328

→ table: instId, delta, gamma, theta, vega, iv (markVol), markPx

→ 返回表格:instId, delta, gamma, theta, vega, iv (markVol), markPx


**"Buy 1 BTC call at strike 95000 expiring March 28, limit at 0.005 BTC"**
```bash
okx option place --instId BTC-USD-250328-95000-C \
  --side buy --ordType limit --tdMode cash --sz 1 --px 0.005

**"买入1张行权价95000、3月28日到期的BTC看涨期权,限价0.005 BTC"**
```bash
okx option place --instId BTC-USD-250328-95000-C \
  --side buy --ordType limit --tdMode cash --sz 1 --px 0.005

→ Order placed: 7890123460 (OK)

→ 订单已提交:7890123460(成功)


**"Show my open option positions"**
```bash
okx option positions

**"查看我未平的期权持仓"**
```bash
okx option positions

→ table: instId, posSide, pos, avgPx, upl, delta, gamma, theta, vega

→ 返回表格:instId, posSide, pos, avgPx, upl, delta, gamma, theta, vega

undefined
undefined

Edge Cases

边缘情况

Spot

现货

  • Market order size:
    --sz
    is in base currency (e.g., BTC amount), not USDT
  • Insufficient balance: check
    okx-cex-portfolio account balance
    before placing
  • Price not required:
    market
    orders don't need
    --px
    ;
    limit
    /
    post_only
    /
    fok
    /
    ioc
    do
  • Algo oco: provide both
    tpTriggerPx
    and
    slTriggerPx
    ; price
    -1
    means market execution at trigger
  • Fills vs orders:
    fills
    shows executed trades;
    orders --history
    shows all orders including cancelled
  • 市价单数量
    --sz
    是计价货币数量(例如BTC数量),不是USDT数量
  • 余额不足:下单前先通过
    okx-cex-portfolio account balance
    查询确认
  • 价格要求
    market
    订单不需要
    --px
    limit
    /
    post_only
    /
    fok
    /
    ioc
    订单需要
  • OCO算法单:需要同时提供
    tpTriggerPx
    slTriggerPx
    ;价格
    -1
    表示触发后市价执行
  • 成交记录 vs 订单
    fills
    显示已成交的交易;
    orders --history
    显示所有订单包括已取消的

Swap / Perpetual

掉期/永续合约

  • posSide: required in hedge mode (
    long_short_mode
    ); omit in net mode. Check
    okx account config
    for
    posMode
  • tdMode: use
    cross
    for cross-margin,
    isolated
    for isolated margin
  • Close position:
    swap close
    closes the entire position; to partial close, use
    swap place
    with a reduce-only algo
  • Leverage: max leverage varies by instrument and account level; exchange rejects if exceeded
  • Trailing stop: use either
    --callbackRatio
    (relative, e.g.,
    0.02
    ) or
    --callbackSpread
    (absolute price), not both
  • Algo on close side: always set
    --side
    opposite to position (e.g., long position → sell algo)
  • posSide:对冲模式(
    long_short_mode
    )下必填;净持仓模式下可省略。可通过
    okx account config
    查看
    posMode
  • tdMode
    cross
    表示全仓保证金,
    isolated
    表示逐仓保证金
  • 平仓
    swap close
    会全平对应持仓;如果要部分平仓,使用
    swap place
    加仅减仓参数
  • 杠杆:最大杠杆随交易对和账户等级不同而变化;如果超出限制交易所会拒绝请求
  • 移动止损:二选一使用
    --callbackRatio
    (相对比例,例如
    0.02
    )或
    --callbackSpread
    (绝对价差),不可同时使用
  • 平仓侧算法单
    --side
    必须和持仓方向相反(例如多持仓 → 卖算法单)

Futures / Delivery

期货/交割合约

  • instId format: delivery futures use date suffix:
    BTC-USDT-250328
    for March 28, 2025 expiry
  • Expiry: futures expire on the delivery date — all positions auto-settle; do not hold through expiry unless intended
  • No swap-specific features: futures don't have trailing stops or
    swap close
    — use
    futures cancel
    +
    futures place
    for adjustments
  • instId格式:交割期货带日期后缀:例如
    BTC-USDT-250328
    表示2025年3月28日到期
  • 到期规则:期货在交割日到期 — 所有持仓会自动结算;除非有意持有,否则不要持仓到到期日
  • 无掉期专属功能:期货不支持移动止损和
    swap close
    ;调整操作使用
    futures cancel
    +
    futures place
    即可

Options

期权

  • instId format:
    {uly}-{YYMMDD}-{strike}-{C|P}
    — e.g.
    BTC-USD-250328-95000-C
    ; always run
    okx option instruments --uly BTC-USD
    first to confirm the exact contract exists
  • tdMode: buyers always use
    cash
    (full premium paid upfront, no liquidation); sellers use
    cross
    or
    isolated
    (margin required, liquidation risk)
  • sz unit: number of contracts (1 BTC option contract = 0.1 BTC on OKX);
    --px
    is quoted in BTC (e.g.
    0.005
    = 0.005 BTC premium per contract)
  • Expiry: options expire at 08:00 UTC on the expiry date; in-the-money options are auto-exercised; do not hold through expiry unless intended
  • No TP/SL algo on options: the
    swap algo
    /
    spot algo
    commands do not apply to option positions; manage risk by cancelling/amending option orders directly
  • Greeks in positions:
    okx option positions
    returns live portfolio Greeks (
    deltaPA
    ,
    gammaPA
    , etc.) from the account's position-level calculation, while
    okx option greeks
    returns BS model Greeks per contract
  • instId格式
    {uly}-{YYMMDD}-{strike}-{C|P}
    — 例如
    BTC-USD-250328-95000-C
    ;下期权单前务必先运行
    okx option instruments --uly BTC-USD
    确认合约存在
  • tdMode:买方始终用
    cash
    (全额预付权利金,无爆仓风险);卖方用
    cross
    isolated
    (需要保证金,有爆仓风险)
  • 数量单位:合约张数(OKX上1张BTC期权合约=0.1 BTC);
    --px
    以BTC计价(例如
    0.005
    =每张合约0.005 BTC权利金)
  • 到期规则:期权在到期日UTC时间08:00到期;实值期权会自动行权;除非有意持有,否则不要持仓到到期日
  • 期权无TP/SL算法单
    swap algo
    /
    spot algo
    命令不适用于期权持仓;直接通过取消/修改期权订单管理风险
  • 持仓Greeks
    okx option positions
    返回账户持仓层面计算的实时组合Greeks(
    deltaPA
    gammaPA
    等),而
    okx option greeks
    返回单合约的BS模型Greeks

Global Notes

全局注意事项

  • All write commands require valid credentials in
    ~/.okx/config.toml
    or env vars
  • --profile <name>
    switches between multiple account configurations
  • --json
    returns raw OKX API v5 response
  • --demo
    flag enables simulated trading with paper funds
  • Rate limit: 60 order operations per 2 seconds per UID
  • Batch operations (batch cancel, batch amend) are available via MCP tools directly if needed
  • Position mode (
    net
    vs
    long_short_mode
    ) affects whether
    --posSide
    is required
  • Spot
    --sz
    is base currency; swap/futures
    --sz
    is number of contracts
  • 所有写入命令需要
    ~/.okx/config.toml
    或环境变量中配置有效的凭证
  • --profile <name>
    可切换多个账户配置
  • --json
    返回原生OKX API v5响应
  • --demo
    标志启用模拟交易,使用虚拟资金
  • 频率限制:每个UID每2秒最多60次订单操作
  • 批量操作(批量撤单、批量改单)可直接通过MCP工具调用
  • 持仓模式(
    net
    净持仓 vs
    long_short_mode
    对冲模式)决定是否需要
    --posSide
    参数
  • 现货
    --sz
    是计价货币数量;掉期/期货
    --sz
    是合约张数