okx-cex-trade
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOKX 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
前置要求
- Install CLI:
okxbashnpm install -g @okx_ai/okx-trade-cli - Configure credentials:
Or set environment variables:bash
okx config initbashexport OKX_API_KEY=your_key export OKX_SECRET_KEY=your_secret export OKX_PASSPHRASE=your_passphrase - Test with demo mode (simulated trading, no real funds):
bash
okx --demo spot orders
- 安装 CLI:
okxbashnpm install -g @okx_ai/okx-trade-cli - 配置凭证:
或设置环境变量:bash
okx config initbashexport OKX_API_KEY=your_key export OKX_SECRET_KEY=your_secret export OKX_PASSPHRASE=your_passphrase - 使用演示模式测试(模拟交易,不涉及真实资金):
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 settingsbash
okx config show # 显示当前配置文件设置How to switch mode per command
如何按命令切换模式
Prepend to run in simulated trading mode (no real funds affected):
--demobash
okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
okx --demo swap close --instId BTC-USDT-SWAP --mgnMode crossOmit to execute on the live account (real funds).
--demo命令前添加 即可在模拟交易模式下运行(不影响真实资金):
--demobash
okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
okx --demo swap close --instId BTC-USDT-SWAP --mgnMode cross省略 则会在实盘账户执行(涉及真实资金)。
--demoRules for this skill
本skill使用规则
- Before every write command, explicitly ask or confirm: "Execute on live account or demo (simulated)?" — do not assume.
- Read commands (orders, positions, fills, get, algo orders): run immediately; note which mode was used.
- When executing demo, prefix the response summary with and state no real funds were affected.
[DEMO] - When executing live, prefix the response summary with and flag that real funds are involved.
[LIVE] - If the user says "try it" / "test it" / "simulate" / "paper trade" → use .
--demo - If the user says "real" / "actual" / "go live" / "execute" → confirm once more before running without .
--demo
- 执行每条写入命令前,需要明确询问或确认:"在实盘账户执行还是演示(模拟)账户执行?" 不要自行假设。
- 读取类命令(订单、持仓、成交、查询、算法订单):可直接运行,注明使用的模式即可。
- 执行演示模式命令后,回复摘要前添加 ,并说明未涉及真实资金。
[DEMO] - 执行实盘模式命令后,回复摘要前添加 ,并提示涉及真实资金。
[LIVE] - 如果用户说“试试”/“测试”/“模拟”/“仿真交易” → 使用 。
--demo - 如果用户说“实盘”/“真实交易”/“上线”/“执行” → 再次确认后再不带 运行。
--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 (this skill)
okx-cex-trade - For grid and DCA trading bots → use
okx-cex-bot
- 行情数据(价格、K线、深度、资金费率)→ 使用
okx-cex-market - 账户余额、盈亏、持仓、手续费、转账 → 使用
okx-cex-portfolio - 常规现货/掉期/期货/期权/算法订单 → 使用 (本skill)
okx-cex-trade - 网格和DCA交易机器人 → 使用
okx-cex-bot
Quickstart
快速开始
bash
undefinedbash
undefinedMarket 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
--tdMode cross --posSide long
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1
--tdMode cross --posSide long
--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
--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
--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
--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
--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>
undefinedokx spot cancel --instId BTC-USDT --ordId <ordId>
undefinedCommand Index
命令索引
Spot Orders
现货订单
| # | Command | Type | Description |
|---|---|---|---|
| 1 | | WRITE | Place spot order (market/limit/post_only/fok/ioc) |
| 2 | | WRITE | Cancel spot order |
| 3 | | WRITE | Amend spot order price or size |
| 4 | | WRITE | Place spot TP/SL algo order |
| 5 | | WRITE | Amend spot TP/SL levels |
| 6 | | WRITE | Cancel spot algo order |
| 7 | | READ | List open or historical spot orders |
| 8 | | READ | Single spot order details |
| 9 | | READ | Spot trade fill history |
| 10 | | READ | List spot TP/SL algo orders |
| # | Command | Type | 说明 |
|---|---|---|---|
| 1 | | WRITE | 下现货订单(市价/限价/post_only/fok/ioc) |
| 2 | | WRITE | 取消现货订单 |
| 3 | | WRITE | 修改现货订单的价格或数量 |
| 4 | | WRITE | 下现货止盈止损算法订单 |
| 5 | | WRITE | 修改现货止盈止损档位 |
| 6 | | WRITE | 取消现货算法订单 |
| 7 | | READ | 列出未成交或历史现货订单 |
| 8 | | READ | 单个现货订单详情 |
| 9 | | READ | 现货成交历史 |
| 10 | | READ | 列出现货止盈止损算法订单 |
Swap / Perpetual Orders
掉期/永续合约订单
| # | Command | Type | Description |
|---|---|---|---|
| 11 | | WRITE | Place perpetual swap order |
| 12 | | WRITE | Cancel swap order |
| 13 | | WRITE | Amend swap order price or size |
| 14 | | WRITE | Close entire position at market |
| 15 | | WRITE | Set leverage for an instrument |
| 16 | | WRITE | Place swap TP/SL algo order |
| 17 | | WRITE | Place swap trailing stop order |
| 18 | | WRITE | Amend swap algo order |
| 19 | | WRITE | Cancel swap algo order |
| 20 | | READ | Open perpetual swap positions |
| 21 | | READ | List open or historical swap orders |
| 22 | | READ | Single swap order details |
| 23 | | READ | Swap trade fill history |
| 24 | | READ | Current leverage settings |
| 25 | | READ | List swap algo orders |
| # | Command | Type | 说明 |
|---|---|---|---|
| 11 | | WRITE | 下永续掉期订单 |
| 12 | | WRITE | 取消掉期订单 |
| 13 | | WRITE | 修改掉期订单的价格或数量 |
| 14 | | WRITE | 市价全平持仓 |
| 15 | | WRITE | 设置交易对杠杆 |
| 16 | | WRITE | 下掉期止盈止损算法订单 |
| 17 | | WRITE | 下掉期移动止损订单 |
| 18 | | WRITE | 修改掉期算法订单 |
| 19 | | WRITE | 取消掉期算法订单 |
| 20 | | READ | 未平永续掉期持仓 |
| 21 | | READ | 列出未成交或历史掉期订单 |
| 22 | | READ | 单个掉期订单详情 |
| 23 | | READ | 掉期成交历史 |
| 24 | | READ | 当前杠杆设置 |
| 25 | | READ | 列出掉期算法订单 |
Futures / Delivery Orders
期货/交割合约订单
| # | Command | Type | Description |
|---|---|---|---|
| 26 | | WRITE | Place delivery futures order |
| 27 | | WRITE | Cancel delivery futures order |
| 28 | | READ | List delivery futures orders |
| 29 | | READ | Open delivery futures positions |
| 30 | | READ | Delivery futures fill history |
| 31 | | READ | Single delivery futures order details |
| # | Command | Type | 说明 |
|---|---|---|---|
| 26 | | WRITE | 下交割期货订单 |
| 27 | | WRITE | 取消交割期货订单 |
| 28 | | READ | 列出交割期货订单 |
| 29 | | READ | 未平交割期货持仓 |
| 30 | | READ | 交割期货成交历史 |
| 31 | | READ | 单个交割期货订单详情 |
Options Orders
期权订单
| # | Command | Type | Description |
|---|---|---|---|
| 32 | | READ | Option chain: list available contracts for an underlying |
| 33 | | READ | Implied volatility + Greeks (delta/gamma/theta/vega) by underlying |
| 34 | | WRITE | Place option order (call or put, buyer or seller) |
| 35 | | WRITE | Cancel unfilled option order |
| 36 | | WRITE | Amend option order price or size |
| 37 | | WRITE | Batch cancel up to 20 option orders |
| 38 | | READ | List option orders (live / history / archive) |
| 39 | | READ | Single option order details |
| 40 | | READ | Open option positions with live Greeks |
| 41 | | READ | Option trade fill history |
| # | Command | Type | 说明 |
|---|---|---|---|
| 32 | | READ | 期权链:列出标的的可用合约 |
| 33 | | READ | 标的的隐含波动率 + Greeks(delta/gamma/theta/vega) |
| 34 | | WRITE | 下期权订单(看涨/看跌,买方/卖方) |
| 35 | | WRITE | 取消未成交期权订单 |
| 36 | | WRITE | 修改期权订单的价格或数量 |
| 37 | | WRITE | 批量取消最多20笔期权订单 |
| 38 | | READ | 列出期权订单(未成交/历史/归档) |
| 39 | | READ | 单个期权订单详情 |
| 40 | | READ | 带实时Greeks的未平期权持仓 |
| 41 | | 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 leverageokx 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: or ):
BTC-USD-250328-95000-C...-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: for buyers (full premium upfront, no liquidation risk);
cashorcrossfor sellers (margin required)isolated
现货(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 leverageokx 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.
- flag: defaults to active/open; use
--historyonly if user explicitly asks for history--history - for algo:
--ordType= single TP or SL;conditional= both TP and SL togetheroco - for swap/futures:
--tdModeorcross; spot always usesisolated(set automatically)cash - for hedge mode:
--posSideorlong; omit in net modeshort
Write commands (place, cancel, amend, close, leverage, algo): two confirmations required:
- Demo or live? — Ask the user before the first write in any session. If unclear, default to asking.
- Demo → prepend to every write command; label result
--demo[DEMO] - Live → execute without ; label result
--demo[LIVE]
- Demo → prepend
- Confirm parameters — confirm the key order details once before executing:
- Spot place: confirm ,
--instId,--side,--ordType; price (--sz) required for limit orders--px - Swap place: confirm ,
--instId,--side,--sz; confirm--tdModeif in hedge mode--posSide - Swap close: confirm ,
--instId,--mgnMode; closes the entire position at market--posSide - Swap leverage: confirm new leverage and impact on existing positions; cannot exceed exchange max
- Algo place (TP/SL): confirm trigger prices; use for market execution at trigger
--tpOrdPx -1 - Algo trail: confirm (e.g.,
--callbackRatio= 2%) or0.02(fixed price spread)--callbackSpread
- Spot place: confirm
读取类命令(订单、持仓、成交、查询、获取杠杆、算法订单):可直接运行,注明使用的模式即可。
- 标志:默认返回活跃/未成交订单;仅当用户明确要求查历史时才使用
--history--history - 算法单的:
--ordType= 单一止盈或止损;conditional= 止盈止损二合一oco - 掉期/期货的:
--tdMode(全仓)或cross(逐仓);现货默认使用isolated(自动设置)cash - 对冲模式下的:
--posSide(多)或long(空);净持仓模式下可省略short
写入类命令(下单、撤单、改单、平仓、调整杠杆、算法单):需要两次确认:
- 演示还是实盘? — 每个会话第一次执行写入命令前询问用户。如果不明确,默认询问。
- 演示 → 每条写入命令前添加;结果标注
--demo[DEMO] - 实盘 → 不带执行;结果标注
--demo[LIVE]
- 演示 → 每条写入命令前添加
- 确认参数 — 执行前再次确认核心订单细节:
- 现货下单:确认、
--instId、--side、--ordType;限价单需要确认价格--sz--px - 掉期下单:确认、
--instId、--side、--sz;对冲模式下确认--tdMode--posSide - 掉期平仓:确认、
--instId、--mgnMode;将市价全平对应持仓--posSide - 掉期杠杆调整:确认新杠杆值以及对现有持仓的影响;不能超过交易所最大限制
- 算法单(止盈止损):确认触发价格;表示触发后市价执行
--tpOrdPx -1 - 移动止损:确认(例如
--callbackRatio=2%)或0.02(固定价差)--callbackSpread
- 现货下单:确认
Step 3: Verify after writes
步骤3:写入操作后验证
- After : run
spot placeto confirm order is live orokx spot ordersif market orderokx spot fills - After : run
swap placeorokx swap ordersto confirmokx swap positions - After : run
swap closeto confirm position size is 0okx swap positions - After algo place: run or
okx spot algo ordersto confirm algo is activeokx swap algo orders - After cancel: run /
okx spot ordersto confirm order is goneokx swap orders
- 现货下单后:运行确认订单已生效,市价单可运行
okx spot orders查看成交okx spot fills - 掉期下单后:运行或
okx swap orders确认okx swap positions - 掉期平仓后:运行确认持仓数量为0
okx swap positions - 算法单提交后:运行或
okx spot algo orders确认算法单已激活okx swap algo orders - 撤单后:运行/
okx spot orders确认订单已消失okx swap orders
CLI Command Reference
CLI命令参考
Order Type Reference
订单类型参考
| Description | Requires |
|---|---|---|
| Fill immediately at best price | No |
| Fill at specified price or better | Yes |
| Limit order; cancelled if it would be a taker | Yes |
| Fill entire order immediately or cancel | Yes |
| Fill what's available immediately, cancel rest | Yes |
| Algo: single TP or SL trigger | No (set trigger px) |
| Algo: TP + SL together (one cancels other) | No (set both trigger px) |
| Trailing stop (swap only) | No (set callback) |
| 说明 | 需要 |
|---|---|---|
| 以最优价格立即成交 | 否 |
| 以指定价格或更优价格成交 | 是 |
| 限价单;如果会成为吃单方则自动取消 | 是 |
| 立即全部成交否则取消 | 是 |
| 立即成交可成交部分,剩余部分取消 | 是 |
| 算法单:单一止盈或止损触发 | 否(设置触发价即可) |
| 算法单:止盈止损二合一(一个触发另一个自动取消) | 否(设置两个触发价即可) |
| 移动止损(仅掉期支持) | 否(设置回调参数即可) |
Spot — Place Order
现货 — 下单
bash
okx spot place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
[--px <price>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Spot instrument (e.g., |
| Yes | - | |
| Yes | - | |
| Yes | - | Order size in base currency (e.g., BTC amount) |
| Cond. | - | Price — required for |
bash
okx spot place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
[--px <price>] [--json]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 是 | - | 现货交易对(例如 |
| 是 | - | |
| 是 | - | |
| 是 | - | 以计价货币为单位的订单数量(例如BTC数量) |
| 条件必填 | - | 价格 — |
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 or .
--newSz--newPxbash
okx spot amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]必须至少提供或中的一个。
--newSz--newPxSpot — 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]| Param | Required | Default | Description |
|---|---|---|---|
| Cond. | - | Take-profit trigger price |
| Cond. | - | TP order price; use |
| Cond. | - | Stop-loss trigger price |
| Cond. | - | SL order price; use |
For : provide both TP and SL params. For : provide only TP or only SL.
ococonditionalbash
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]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 条件必填 | - | 止盈触发价格 |
| 条件必填 | - | 止盈订单价格; |
| 条件必填 | - | 止损触发价格 |
| 条件必填 | - | 止损订单价格; |
ococonditionalSpot — 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]| Flag | Effect |
|---|---|
| (default) | Open/pending orders |
| Historical (filled, cancelled) orders |
bash
okx spot orders [--instId <id>] [--history] [--json]| 标志 | 效果 |
|---|---|
| (默认) | 未成交/待处理订单 |
| 历史订单(已成交、已取消) |
Spot — Get Order
现货 — 获取订单详情
bash
okx spot get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]Returns: , , , , , , , , , .
ordIdinstIdsideordTypepxszfillSzavgPxstatecTimebash
okx spot get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]返回:, , , , , , , , , .
ordIdinstIdsideordTypepxszfillSzavgPxstatecTimeSpot — Fills
现货 — 成交记录
bash
okx spot fills [--instId <id>] [--ordId <id>] [--json]Returns: , , , , , .
instIdsidefillPxfillSzfeetsbash
okx spot fills [--instId <id>] [--ordId <id>] [--json]返回:, , , , , .
instIdsidefillPxfillSzfeetsSpot — Algo Orders
现货 — 算法单列表
bash
okx spot algo orders [--instId <id>] [--history] [--ordType <type>] [--json]Returns: , , type, , , , , .
algoIdinstIdsidesztpTriggerslTriggerstatebash
okx spot algo orders [--instId <id>] [--history] [--ordType <type>] [--json]返回:, , type, , , , , .
algoIdinstIdsidesztpTriggerslTriggerstateSwap — Place Order
掉期 — 下单
bash
okx swap place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--px <price>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Swap instrument (e.g., |
| Yes | - | |
| Yes | - | |
| Yes | - | Number of contracts |
| Yes | - | |
| Cond. | - | |
| 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]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 是 | - | 掉期交易对(例如 |
| 是 | - | |
| 是 | - | |
| 是 | - | 合约张数 |
| 是 | - | |
| 条件必填 | - | |
| 条件必填 | - | 价格 — 限价单必填 |
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]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Swap instrument |
| Yes | - | |
| Cond. | - | |
| No | false | Auto-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]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 是 | - | 掉期交易对 |
| 是 | - | |
| 条件必填 | - | |
| 否 | false | 平仓前自动取消未成交订单 |
将以市价全平对应持仓。
Swap — Set Leverage
掉期 — 设置杠杆
bash
okx swap leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Swap instrument |
| Yes | - | Leverage multiplier (e.g., |
| Yes | - | |
| Cond. | - | |
bash
okx swap leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--json]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 是 | - | 掉期交易对 |
| 是 | - | 杠杆倍数(例如 |
| 是 | - | |
| 条件必填 | - | |
Swap — Get Leverage
掉期 — 获取杠杆
bash
okx swap get-leverage --instId <id> --mgnMode <cross|isolated> [--json]Returns table: , , , .
instIdmgnModeposSideleverbash
okx swap get-leverage --instId <id> --mgnMode <cross|isolated> [--json]返回表格:, , , .
instIdmgnModeposSideleverSwap — 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]--reduceOnlybash
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]--reduceOnlySwap — 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]| Param | Required | Default | Description |
|---|---|---|---|
| Cond. | - | Trailing callback as a ratio (e.g., |
| Cond. | - | Trailing callback as fixed price distance |
| 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]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 条件必填 | - | 回调比例(例如 |
| 条件必填 | - | 固定回调价差 |
| 否 | - | 移动止损生效的触发价格 |
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: , , , , , , , , , , .
ordIdinstIdsideposSideordTypepxszfillSzavgPxstatecTimebash
okx swap get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]返回:, , , , , , , , , , .
ordIdinstIdsideposSideordTypepxszfillSzavgPxstatecTimeSwap — Positions
掉期 — 持仓列表
bash
okx swap positions [<instId>] [--json]Returns: , , , , , , . Only non-zero positions.
instIdsidesizeavgPxupluplRatioleverbash
okx swap positions [<instId>] [--json]返回:, , , , , , 。仅返回非零持仓。
instIdsidesizeavgPxupluplRatioleverSwap — Fills
掉期 — 成交记录
bash
okx swap fills [--instId <id>] [--ordId <id>] [--archive] [--json]--archivebash
okx swap fills [--instId <id>] [--ordId <id>] [--archive] [--json]--archiveSwap — 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]--instIdBTC-USDT-250328bash
okx futures place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--px <price>] [--reduceOnly] [--json]--instIdBTC-USDT-250328Futures — 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] | Effect |
|---|---|
| Active/pending orders (default) |
| Recent completed/cancelled |
| Older history |
bash
okx futures orders [--instId <id>] [--status <open|history|archive>] [--json] | 效果 |
|---|---|
| 活跃/待处理订单(默认) |
| 近期已完成/已取消订单 |
| 更早的历史订单 |
Futures — Positions
期货 — 持仓列表
bash
okx futures positions [<instId>] [--json]Returns: , , , , , .
instIdsideposavgPxuplleverbash
okx futures positions [<instId>] [--json]返回:, , , , , .
instIdsideposavgPxuplleverFutures — 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]| Param | Required | Description |
|---|---|---|
| Yes | Underlying, e.g. |
| No | Filter by expiry date, e.g. |
Returns: , , , (strike), (C/P), .
instIdulyexpTimestkoptTypestateRun this before placing any option order to get the exact .
instIdbash
okx option instruments --uly <underlying> [--expTime <YYMMDD>] [--json]| 参数 | 必填 | 说明 |
|---|---|---|
| 是 | 标的资产,例如 |
| 否 | 按到期日过滤,例如 |
返回:, , , (行权价), (C/P), .
instIdulyexpTimestkoptTypestate下任何期权订单前必须运行此命令获取准确的。
instIdOption — Get Greeks
期权 — 获取Greeks
bash
okx option greeks --uly <underlying> [--expTime <YYMMDD>] [--json]Returns IV () and BS Greeks (, , , ) plus for each contract.
markVoldeltaBSgammaBSthetaBSvegaBSmarkPxbash
okx option greeks --uly <underlying> [--expTime <YYMMDD>] [--json]返回每个合约的IV()和BS模型Greeks(, , , )以及(标记价格)。
markVoldeltaBSgammaBSthetaBSvegaBSmarkPxOption — 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]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | e.g. |
| Yes | - | |
| Yes | - | |
| Yes | - | |
| Yes | - | Number of contracts |
| Cond. | - | Required for |
| No | false | Close-only; do not open a new position |
tdMode rules:
- Buyer (): always use
side=buy— pay full premium, no margin call riskcash - Seller (): use
side=sellorcross— margin required, liquidation riskisolated
bash
okx option place --instId <id> --side <buy|sell> --ordType <type> \
--tdMode <cash|cross|isolated> --sz <n> \
[--px <price>] [--reduceOnly] [--clOrdId <id>] [--json]| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| 是 | - | 例如 |
| 是 | - | |
| 是 | - | |
| 是 | - | |
| 是 | - | 合约张数 |
| 条件必填 | - | |
| 否 | 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 or .
--newSz--newPxbash
okx option amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]必须至少提供或中的一个。
--newSz--newPxOption — Batch Cancel
期权 — 批量撤单
bash
okx option batch-cancel --orders '<JSON>' [--json]--orders{"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{"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]| Flag | Effect |
|---|---|
| (default) | Live/pending orders |
| Historical (7d) |
| Older archive (3mo) |
bash
okx option orders [--instId <id>] [--uly <underlying>] [--history] [--archive] [--json]| 标志 | 效果 |
|---|---|
| (默认) | 活跃/待处理订单 |
| 历史订单(7天内) |
| 归档历史订单(3个月内) |
Option — Get Order
期权 — 获取订单详情
bash
okx option get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]Returns: , , , , , , , , , .
ordIdinstIdsideordTypepxszfillSzavgPxstatecTimebash
okx option get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]返回:, , , , , , , , , .
ordIdinstIdsideordTypepxszfillSzavgPxstatecTimeOption — Positions
期权 — 持仓列表
bash
okx option positions [--instId <id>] [--uly <underlying>] [--json]Returns: , , , , , , , , . Only non-zero positions shown.
instIdposSideposavgPxupldeltaPAgammaPAthetaPAvegaPAbash
okx option positions [--instId <id>] [--uly <underlying>] [--json]返回:, , , , , , , , 。仅返回非零持仓。
instIdposSideposavgPxupldeltaPAgammaPAthetaPAvegaPAOption — Fills
期权 — 成交记录
bash
okx option fills [--instId <id>] [--ordId <id>] [--archive] [--json]--archivebash
okx option fills [--instId <id>] [--ordId <id>] [--archive] [--json]--archiveMCP Tool Reference
MCP工具参考
| Tool | Description |
|---|---|
| Place spot order |
| Cancel spot order |
| Amend spot order |
| Place spot TP/SL algo |
| Amend spot algo |
| Cancel spot algo |
| List spot orders |
| Get single spot order |
| Spot fill history |
| List spot algo orders |
| Place swap order |
| Cancel swap order |
| Amend swap order |
| Close swap position |
| Set swap leverage |
| Place swap TP/SL algo |
| Place swap trailing stop |
| Amend swap algo |
| Cancel swap algo |
| Swap positions |
| List swap orders |
| Get single swap order |
| Swap fill history |
| Get swap leverage |
| List swap algo orders |
| Place futures order |
| Cancel futures order |
| List futures orders |
| Futures positions |
| Futures fill history |
| Get single futures order |
| Option chain (list available contracts) |
| IV and Greeks by underlying |
| Place option order |
| Cancel option order |
| Amend option order |
| Batch cancel up to 20 option orders |
| List option orders |
| Get single option order |
| Option positions with live Greeks |
| Option fill history |
| 工具 | 说明 |
|---|---|
| 下现货订单 |
| 取消现货订单 |
| 修改现货订单 |
| 下现货止盈止损算法单 |
| 修改现货算法单 |
| 取消现货算法单 |
| 列出现货订单 |
| 获取单个现货订单详情 |
| 现货成交历史 |
| 列出现货算法订单 |
| 下掉期订单 |
| 取消掉期订单 |
| 修改掉期订单 |
| 平掉期持仓 |
| 设置掉期杠杆 |
| 下掉期止盈止损算法单 |
| 下掉期移动止损单 |
| 修改掉期算法单 |
| 取消掉期算法单 |
| 掉期持仓列表 |
| 列出掉期订单 |
| 获取单个掉期订单详情 |
| 掉期成交历史 |
| 获取掉期杠杆 |
| 列出掉期算法订单 |
| 下期货订单 |
| 取消期货订单 |
| 列出期货订单 |
| 期货持仓列表 |
| 期货成交历史 |
| 获取单个期货订单详情 |
| 期权链(列出可用合约) |
| 标的的IV和Greeks |
| 下期权订单 |
| 取消期权订单 |
| 修改期权订单 |
| 批量取消最多20笔期权订单 |
| 列出期权订单 |
| 获取单个期权订单详情 |
| 带实时Greeks的期权持仓 |
| 期权成交历史 |
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
undefinedundefinedEdge Cases
边缘情况
Spot
现货
- Market order size: is in base currency (e.g., BTC amount), not USDT
--sz - Insufficient balance: check before placing
okx-cex-portfolio account balance - Price not required: orders don't need
market;--px/limit/post_only/fokdoioc - Algo oco: provide both and
tpTriggerPx; priceslTriggerPxmeans market execution at trigger-1 - Fills vs orders: shows executed trades;
fillsshows all orders including cancelledorders --history
- 市价单数量:是计价货币数量(例如BTC数量),不是USDT数量
--sz - 余额不足:下单前先通过查询确认
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 (); omit in net mode. Check
long_short_modeforokx account configposMode - tdMode: use for cross-margin,
crossfor isolated marginisolated - Close position: closes the entire position; to partial close, use
swap closewith a reduce-only algoswap place - Leverage: max leverage varies by instrument and account level; exchange rejects if exceeded
- Trailing stop: use either (relative, e.g.,
--callbackRatio) or0.02(absolute price), not both--callbackSpread - Algo on close side: always set opposite to position (e.g., long position → sell algo)
--side
- posSide:对冲模式()下必填;净持仓模式下可省略。可通过
long_short_mode查看okx account configposMode - tdMode:表示全仓保证金,
cross表示逐仓保证金isolated - 平仓:会全平对应持仓;如果要部分平仓,使用
swap close加仅减仓参数swap place - 杠杆:最大杠杆随交易对和账户等级不同而变化;如果超出限制交易所会拒绝请求
- 移动止损:二选一使用(相对比例,例如
--callbackRatio)或0.02(绝对价差),不可同时使用--callbackSpread - 平仓侧算法单:必须和持仓方向相反(例如多持仓 → 卖算法单)
--side
Futures / Delivery
期货/交割合约
- instId format: delivery futures use date suffix: for March 28, 2025 expiry
BTC-USDT-250328 - 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 — use
swap close+futures cancelfor adjustmentsfutures place
- instId格式:交割期货带日期后缀:例如表示2025年3月28日到期
BTC-USDT-250328 - 到期规则:期货在交割日到期 — 所有持仓会自动结算;除非有意持有,否则不要持仓到到期日
- 无掉期专属功能:期货不支持移动止损和;调整操作使用
swap close+futures cancel即可futures place
Options
期权
- instId format: — e.g.
{uly}-{YYMMDD}-{strike}-{C|P}; always runBTC-USD-250328-95000-Cfirst to confirm the exact contract existsokx option instruments --uly BTC-USD - tdMode: buyers always use (full premium paid upfront, no liquidation); sellers use
cashorcross(margin required, liquidation risk)isolated - sz unit: number of contracts (1 BTC option contract = 0.1 BTC on OKX); is quoted in BTC (e.g.
--px= 0.005 BTC premium per contract)0.005 - 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 algocommands do not apply to option positions; manage risk by cancelling/amending option orders directlyspot algo - Greeks in positions: returns live portfolio Greeks (
okx option positions,deltaPA, etc.) from the account's position-level calculation, whilegammaPAreturns BS model Greeks per contractokx option greeks
- 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);以BTC计价(例如
--px=每张合约0.005 BTC权利金)0.005 - 到期规则:期权在到期日UTC时间08:00到期;实值期权会自动行权;除非有意持有,否则不要持仓到到期日
- 期权无TP/SL算法单:/
swap algo命令不适用于期权持仓;直接通过取消/修改期权订单管理风险spot algo - 持仓Greeks:返回账户持仓层面计算的实时组合Greeks(
okx option positions、deltaPA等),而gammaPA返回单合约的BS模型Greeksokx option greeks
Global Notes
全局注意事项
- All write commands require valid credentials in or env vars
~/.okx/config.toml - switches between multiple account configurations
--profile <name> - returns raw OKX API v5 response
--json - flag enables simulated trading with paper funds
--demo - 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 (vs
net) affects whetherlong_short_modeis required--posSide - Spot is base currency; swap/futures
--szis number of contracts--sz
- 所有写入命令需要或环境变量中配置有效的凭证
~/.okx/config.toml - 可切换多个账户配置
--profile <name> - 返回原生OKX API v5响应
--json - 标志启用模拟交易,使用虚拟资金
--demo - 频率限制:每个UID每2秒最多60次订单操作
- 批量操作(批量撤单、批量改单)可直接通过MCP工具调用
- 持仓模式(净持仓 vs
net对冲模式)决定是否需要long_short_mode参数--posSide - 现货是计价货币数量;掉期/期货
--sz是合约张数--sz