okx-cex-trade by okx/agent-skills
npx skills add https://github.com/okx/agent-skills --skill okx-cex-trade在 OKX 交易所进行现货、永续合约、交割合约和期权订单管理。下单、撤单、改单和监控订单;查询期权链和希腊值;设置止盈止损和追踪止损;管理杠杆和仓位。需要 API 凭证。
安装 okx CLI:
npm install -g @okx_ai/okx-trade-cli
配置凭证:
okx config init
或者设置环境变量:
export OKX_API_KEY=your_key
export OKX_SECRET_KEY=your_secret
export OKX_PASSPHRASE=your_passphrase
3. 使用演示模式测试(模拟交易,无真实资金):
okx --profile demo spot orders
在执行任何需要认证的命令之前,请先运行此检查。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
okx config show # 验证配置状态(输出已脱敏)
okx config init,并等待设置完成后再重试。所有需要认证的命令都必须使用 --profile。切勿隐式添加配置文件。
| 值 | 模式 | 资金 |
|---|---|---|
live | 实盘 | 真实资金 |
demo | 模拟盘 | 模拟资金 |
解析规则:
live;"test" / "模拟" / "demo" → demo)→ 使用它并告知用户:"Using --profile live (实盘)" 或 "Using --profile demo (模拟盘)""Continuing with --profile live (实盘) from earlier""Live (实盘) or Demo (模拟盘)?" — 等待回答后再继续如果任何命令返回 401 / 认证错误:
立即停止 — 不要重试同一命令
告知用户:"Authentication failed (401). Your API credentials may be invalid or expired."
引导用户通过本地编辑器直接编辑文件来更新凭证:
~/.okx/config.toml
在相关配置文件下更新字段 api_key、secret_key、passphrase。请勿将新凭证粘贴到聊天中。
4. 用户确认文件已更新后,运行 okx config show 进行验证(输出已脱敏)
5. 只有在此之后才能重试原始操作
配置文件是切换 实盘/模拟盘 的唯一控制项 — 恰好有两个选项:
--profile | 模式 | 资金 |
|---|---|---|
live | 实盘 | 真实资金 — 不可逆 |
demo | 模拟盘 | 模拟 — 无真实资金 |
okx --profile live spot place ... # 实盘 — 真实资金
okx --profile demo spot place ... # 模拟盘 — 模拟资金
规则:
--profile — 在"凭证与配置文件检查"步骤 B 中确定[profile: live] 或 [profile: demo]--demo 标志进行模式切换 — 请改用 --profileUser: "Buy 0.01 BTC"
Agent: "Live (实盘) or Demo (模拟盘)?"
User: "Demo"
Agent runs: okx --profile demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
Agent replies: "Order placed: 7890123456 (OK) — simulated, no real funds used. [profile: demo]"
okx-cex-marketokx-cex-portfoliookx-cex-trade(本技能)okx-cex-bot适用于所有合约、期货和期权订单。--sz 始终表示合约张数,而非货币金额。在每次衍生品下单前遵循此流程。
| instId 模式 | 合约类型 | 结算 | ctVal 单位 |
|---|---|---|---|
*-USDT-SWAP | 线性永续合约 | USDT | 基础货币 (BTC/ETH/…) |
*-USDT-YYMMDD | 线性交割期货 | USDT | 基础货币 |
*-USD-SWAP | 反向永续合约 | 基础币 | USD(固定,例如 100 USD) |
*-USD-YYMMDD | 反向交割期货 | 基础币 | USD(固定,例如 100 USD) |
*-USD-YYMMDD-strike-C/P | 反向期权 | 基础币 | 基础货币(例如 0.1 BTC) |
User mentions a quantity:
1. Includes currency unit (USDT / USD / $ / ¥ / 元)
→ User is specifying a quote-currency amount → must convert to contracts (see Step 3)
2. Explicitly says "X contracts" / "X 张" / "X 手"
→ Use directly as sz, no conversion needed
3. Plain number with no unit (for swap/futures/option orders)
→ Ambiguous — ask before proceeding:
"您输入的 X 是合约张数还是 USDT 金额?"
(Is X the number of contracts or a USDT amount?)
Wait for the user's answer before continuing.
在运行任何公式之前,获取所需数据:
# 获取该交易品种的 ctVal、minSz、lotSz
okx market instruments --instType <SWAP|FUTURES|OPTION> --instId <instId> --json
# 获取当前标记价格(用于线性合约和期权)
okx market mark-price --instType <SWAP|FUTURES|OPTION> --instId <instId> --json
*-USDT-SWAP / *-USDT-YYMMDD)ctVal unit: base currency (e.g. ETH)
markPx unit: USDT
Formula: sz = floor(usdtAmt / (markPx × ctVal))
Example — ETH-USDT-SWAP (ctVal=0.1 ETH, markPx=2000 USDT):
200 USDT → floor(200 / (2000 × 0.1)) = floor(1.0) = 1 contract ✓
50 USDT → floor(50 / (2000 × 0.1)) = floor(0.25) = 0 ✗ insufficient
*-USD-SWAP / *-USD-YYMMDD)ctVal unit: USD (fixed face value, e.g. 100 USD per contract)
markPx is NOT needed for sz calculation
Formula: sz = floor(usdtAmt / ctVal) (1 USDT ≈ 1 USD)
Example — BTC-USD-SWAP (ctVal=100 USD):
500 USDT → floor(500 / 100) = 5 contracts ✓
⚠ Settlement warning (always show):
"This is an inverse contract. Margin and P&L are settled in BTC, not USDT.
Your USDT must be converted to BTC to meet margin requirements."
*-USD-YYMMDD-strike-C/P)markPx unit: base currency (e.g. BTC per contract)
ctVal unit: base currency (e.g. 0.1 BTC)
Need BTC spot price to convert USDT → contracts
Required data:
okx option greeks --uly <BTC-USD> --expTime <YYMMDD> --json → markPx (BTC)
okx market ticker BTC-USDT --json → last price (btcPx)
Formula (buyer cost):
sz = floor(usdtAmt / (markPx_BTC × btcPx × ctVal))
Example — BTC-USD-250328-95000-C (markPx=0.005 BTC, btcPx=95000, ctVal=0.1 BTC):
200 USDT → floor(200 / (0.005 × 95000 × 0.1))
= floor(200 / 47.5) = floor(4.21) = 4 contracts
Total premium ≈ 4 × 0.005 × 0.1 = 0.002 BTC ≈ 190 USDT
⚠ Always show both BTC and USDT premium cost to the buyer.
⚠ Seller margin is also in BTC — remind user of liquidation risk.
After computing sz:
1. sz == 0 or sz < minSz
→ Reject. Inform user:
"Amount too small: minimum order is {minSz} contract(s),
equivalent to ~{minSz × markPx × ctVal} USDT."
2. sz not a multiple of lotSz
→ Round down to the nearest valid multiple:
sz = floor(sz / lotSz) × lotSz
3. sz ≥ minSz
→ Show conversion summary and wait for user confirmation before placing:
Conversion summary:
Input: {usdtAmt} USDT
markPx: {markPx} | ctVal: {ctVal}
Raw: {usdtAmt} / ({markPx} × {ctVal}) = {rawResult}
Rounded: {sz} contracts (~{sz × markPx × ctVal} USDT actual value)
Confirm order with sz={sz}?
# 市价买入 0.01 BTC(现货)
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
# 买入价值 $10 的 SOL(现货,USDT 金额)
okx spot place --instId SOL-USDT --side buy --ordType market --sz 10 --tgtCcy quote_ccy
# 限价卖出 0.01 BTC 在 $100,000(现货)
okx spot place --instId BTC-USDT --side sell --ordType limit --sz 0.01 --px 100000
# 做多 1 张 BTC 永续合约(全仓保证金)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long
# 做多 1 张合约并附带止盈止损(一步完成)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx -1 --slTriggerPx 88000 --slOrdPx -1
# 市价平仓 BTC 永续多头仓位
okx swap close --instId BTC-USDT-SWAP --mgnMode cross --posSide long
# 设置 BTC 永续合约杠杆为 10 倍(全仓)
okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross
# --- 股票代币 (TSLA, NVDA, 等) ---
# 步骤 1: 设置杠杆 ≤ 5 倍(股票代币最大杠杆为 5 倍)
okx swap leverage --instId TSLA-USDT-SWAP --lever 5 --mgnMode cross
# 步骤 2: 做多 TSLA(股票代币需要 --posSide)
okx swap place --instId TSLA-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long
# 做空 NVDA
okx swap leverage --instId NVDA-USDT-SWAP --lever 3 --mgnMode cross
okx swap place --instId NVDA-USDT-SWAP --side sell --ordType market --sz 1 \
--tdMode cross --posSide short
# 市价平仓 TSLA 多头仓位
okx swap close --instId TSLA-USDT-SWAP --mgnMode cross --posSide long
# 在现货 BTC 仓位上设置止盈止损(价格达到 $105k 时卖出,$88k 时止损)
okx spot algo place --instId BTC-USDT --side sell --ordType oco --sz 0.01 \
--tpTriggerPx 105000 --tpOrdPx -1 \
--slTriggerPx 88000 --slOrdPx -1
# 在 BTC 永续多头仓位上设置追踪止损(回调 2%)
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 1 \
--tdMode cross --posSide long --callbackRatio 0.02
# 在现货 BTC 仓位上设置追踪止损(回调 2%)
okx spot algo trail --instId BTC-USDT --side sell --sz 0.01 --callbackRatio 0.02
# 查看现货挂单
okx spot orders
# 查看永续合约仓位
okx swap positions
# 取消一个现货订单
okx spot cancel --instId BTC-USDT --ordId <ordId>
---|---|---|---
1 | okx spot place | WRITE | 下现货订单(市价/限价/只做maker/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 algo trail | WRITE | 下现货追踪止损订单
8 | okx spot orders | READ | 列出当前或历史现货订单
9 | okx spot get | READ | 单个现货订单详情
10 | okx spot fills | READ | 现货成交历史
11 | okx spot algo orders | READ | 列出现货止盈止损算法订单
---|---|---|---
12 | okx swap place | WRITE | 下永续合约订单
13 | okx swap cancel | WRITE | 取消合约订单
14 | okx swap amend | WRITE | 修改合约订单价格或数量
15 | okx swap close | WRITE | 市价平仓整个仓位
16 | okx swap leverage | WRITE | 设置交易品种杠杆
17 | okx swap algo place | WRITE | 下合约止盈止损算法订单
18 | okx swap algo trail | WRITE | 下合约追踪止损订单
19 | okx swap algo amend | WRITE | 修改合约算法订单
20 | okx swap algo cancel | WRITE | 取消合约算法订单
21 | okx swap positions | READ | 当前永续合约仓位
22 | okx swap orders | READ | 列出当前或历史合约订单
23 | okx swap get | READ | 单个合约订单详情
24 | okx swap fills | READ | 合约成交历史
25 | okx swap get-leverage | READ | 当前杠杆设置
26 | okx swap algo orders | READ | 列出合约算法订单
---|---|---|---
27 | okx futures place | WRITE | 下交割期货订单
28 | okx futures cancel | WRITE | 取消期货订单
29 | okx futures amend | WRITE | 修改期货订单价格或数量
30 | okx futures close | WRITE | 市价平仓整个期货仓位
31 | okx futures leverage | WRITE | 设置期货交易品种杠杆
32 | okx futures algo place | WRITE | 下期货止盈止损算法订单
33 | okx futures algo trail | WRITE | 下期货追踪止损订单
34 | okx futures algo amend | WRITE | 修改期货算法订单
35 | okx futures algo cancel | WRITE | 取消期货算法订单
36 | okx futures orders | READ | 列出交割期货订单
37 | okx futures positions | READ | 当前交割期货仓位
38 | okx futures fills | READ | 期货成交历史
39 | okx futures get | READ | 单个期货订单详情
40 | okx futures get-leverage | READ | 当前期货杠杆设置
41 | okx futures algo orders | READ | 列出期货算法订单
---|---|---|---
42 | okx option instruments | READ | 期权链:列出标的物的可用合约
43 | okx option greeks | READ | 隐含波动率 + 希腊值(delta/gamma/theta/vega),按标的物
44 | okx option place | WRITE | 下期权订单(看涨或看跌,买方或卖方)
45 | okx option cancel | WRITE | 取消未成交期权订单
46 | okx option amend | WRITE | 修改期权订单价格或数量
47 | okx option batch-cancel | WRITE | 批量取消最多 20 个期权订单
48 | okx option orders | READ | 列出期权订单(当前 / 历史 / 存档)
49 | okx option get | READ | 单个期权订单详情
50 | okx option positions | READ | 当前期权仓位及实时希腊值
51 | okx option fills | READ | 期权成交历史
User: "Buy $500 worth of ETH at market"
1. okx-cex-portfolio okx account balance USDT → confirm available funds ≥ $500
↓ user approves
2. okx-cex-trade okx spot place --instId ETH-USDT --side buy --ordType market --sz 500 --tgtCcy quote_ccy
3. okx-cex-trade okx spot fills --instId ETH-USDT → confirm fill price and size
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 \
--tpTriggerPx 105000 --tpOrdPx -1 \
--slTriggerPx 88000 --slOrdPx -1
4. okx-cex-trade okx swap positions → confirm position opened
注意: 止盈止损通过
--tpTriggerPx/--slTriggerPx直接附加到订单上 — 无需单独的swap algo place步骤。仅当向现有仓位添加止盈止损时才使用swap algo place。
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
User: "Set a 3% trailing stop on my open position"
现货示例(无需保证金模式):
1. okx-cex-portfolio okx account balance BTC → confirm spot BTC holdings
2. okx-cex-market okx market ticker BTC-USDT → current price reference
↓ user approves
3. okx-cex-trade okx spot algo trail --instId BTC-USDT --side sell \
--sz <spot_sz> --callbackRatio 0.03
4. okx-cex-trade okx spot algo orders --instId BTC-USDT → confirm trail order placed
合约/永续示例:
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
期货/交割示例:
1. okx-cex-trade okx futures positions → confirm size of open long
2. okx-cex-market okx market ticker BTC-USDT-<YYMMDD> → current price reference
↓ user approves
3. okx-cex-trade okx futures algo trail --instId BTC-USDT-<YYMMDD> --side sell \
--sz <pos_size> --tdMode cross --posSide long --callbackRatio 0.03
4. okx-cex-trade okx futures algo orders --instId BTC-USDT-<YYMMDD> → confirm trail order placed
User: "I want to long TSLA with 500 USDT"
1. okx-cex-market okx market stock-tokens → confirm TSLA-USDT-SWAP is available
2. okx-cex-market okx market ticker TSLA-USDT-SWAP → current price (e.g., markPx=310 USDT)
3. okx-cex-market okx market instruments --instType SWAP --instId TSLA-USDT-SWAP --json
→ ctVal=1, minSz=1, lotSz=1
Agent computes: sz = floor(500 / (310 × 1)) = 1 contract (~310 USDT)
Agent shows conversion summary and asks to confirm
↓ user confirms
4. okx-cex-portfolio okx account balance USDT → confirm margin available
5. okx-cex-trade okx swap get-leverage --instId TSLA-USDT-SWAP --mgnMode cross
→ check current leverage; must be ≤ 5x
(if not set or > 5x) okx swap leverage --instId TSLA-USDT-SWAP --lever 5 --mgnMode cross
6. okx-cex-trade okx swap place --instId TSLA-USDT-SWAP --side buy --ordType market \
--sz 1 --tdMode cross --posSide long
7. okx-cex-trade okx swap positions TSLA-USDT-SWAP → confirm position opened
⚠ 股票代币限制:最大杠杆 5 倍(交易所拒绝 > 5 倍)。
--posSide是必需的。交易遵循股市交易时间 — 下单前确认实时行情。
User: "用 200 USDT 做多 ETH 永续 (cross margin)"
1. okx-cex-market okx market instruments --instType SWAP --instId ETH-USDT-SWAP --json
→ ctVal=0.1 ETH, minSz=1, lotSz=1
2. okx-cex-market okx market mark-price --instType SWAP --instId ETH-USDT-SWAP --json
→ markPx=2000 USDT
3. Agent computes: sz = floor(200 / (2000 × 0.1)) = 1 contract (~200 USDT)
Agent informs user of conversion summary and asks to confirm
↓ user confirms
4. okx-cex-trade okx swap place --instId ETH-USDT-SWAP --side buy --ordType market \
--sz 1 --tdMode cross --profile <live|demo>
5. okx-cex-trade okx swap positions ETH-USDT-SWAP → confirm position opened
User: "用 500 USDT 开一个 BTC 币本位永续多单"
1. okx-cex-market okx market instruments --instType SWAP --instId BTC-USD-SWAP --json
→ ctVal=100 USD, minSz=1
2. Agent computes: sz = floor(500 / 100) = 5 contracts
Agent warns: "BTC-USD-SWAP 是币本位合约,保证金和盈亏以 BTC 结算,非 USDT。
请确认账户有足够 BTC 作为保证金。"
Agent shows conversion summary and asks to confirm
↓ user confirms
3. okx-cex-trade okx swap place --instId BTC-USD-SWAP --side buy --ordType market \
--sz 5 --tdMode cross --profile <live|demo>
4. okx-cex-trade okx swap positions BTC-USD-SWAP → confirm position opened
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
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
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
在任何需要认证的命令之前:
确定配置文件(必需):
live(实盘)或 demo(模拟盘)— 恰好这两个值"Using --profile live (实盘)""Continuing with --profile live (实盘) from earlier""Live (实盘) or Demo (模拟盘)?" — 等待回答如果未配置凭证: 引导用户运行 okx config init,停止所有交易操作
在每个命令结果之后: 在响应中附加 [profile: live] 或 [profile: demo]
现货(instId 格式:BTC-USDT):
okx spot place/cancel/amendokx spot algo place/amend/cancelokx spot algo trailokx spot orders/get/fills/algo orders合约/永续(instId 格式:BTC-USDT-SWAP):
okx swap place/cancel/amendokx swap closeokx swap leverage / okx swap get-leverageokx swap algo place/amend/cancelokx swap algo trailokx swap positions/orders/get/fills/get-leverage/algo orders期货/交割(instId 格式:BTC-USDT-<YYMMDD>):
okx futures place/cancel/amendokx futures closeokx futures leverage / okx futures get-leverageokx futures algo place/amend/cancelokx futures algo trailokx futures orders/positions/fills/get/get-leverage/algo orders期权(instId 格式:BTC-USD-250328-95000-C 或 ...-P):
okx option instruments --uly BTC-USDokx option greeks --uly BTC-USDokx option place/cancel/amendokx option batch-cancel --orders '[...]'okx option orders/get/positions/fillscash(全额支付权利金,无强平风险);卖方使用 cross 或 isolated(需要保证金)读取命令(orders, positions, fills, get, get-leverage, algo orders):立即运行;注意使用的配置文件。
--history 标志:默认为活跃/挂单;仅当用户明确要求历史记录时才使用 --history--ordType:conditional = 单个止盈或止损;oco = 止盈和止损一起(二选一)--tdMode:cross 或 isolated;现货始终使用 cash(自动设置)--posSide:long 或 short;净头寸模式下省略写入命令(place, cancel, amend, close, leverage, algo):需要两次确认:
--profile live(实盘)或 --profile demo(模拟盘)--instId、--side、--ordType、--sz;限价订单需要价格(--px);可选地使用 --tpTriggerPx/--slTriggerPx 附加止盈止损--sz 之前,应用"衍生品 Sz 转换规则" — 如果用户的输入是 USDT 金额,先将其解析为合约张数,显示转换摘要,并在确认中使用计算出的 sz;确认 --instId、--side、--sz、--tdMode;如果是对冲模式,确认 --posSide;可选地使用 --tpTriggerPx/--slTriggerPx 附加止盈止损--instId、--mgnMode、--posSide;以市价平仓整个仓位--instId、--mgnMode、--posSide;以市价平仓整个仓位--tpOrdPx -1 在触发时以市价执行--callbackRatio(例如,0.02 = 2%)或 --callbackSpread(固定价差);现货不需要 --tdMode 或 --posSidespot place 之后:运行 okx spot orders 确认订单已挂单,或如果是市价单则运行 okx spot fillsswap place 之后:运行 okx swap orders 或 okx swap positions 确认swap close 之后:运行 okx swap positions 确认仓位大小为 0futures place 之后:运行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.
Install okx CLI:
npm install -g @okx_ai/okx-trade-cli
Configure credentials:
okx config init
Or set environment variables:
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):
okx --profile demo spot orders
Run this check before any authenticated command.
okx config show # verify configuration status (output is masked)
okx config init, and wait for setup to complete before retrying.--profile is required for all authenticated commands. Never add a profile implicitly.
| Value | Mode | Funds |
|---|---|---|
live | 实盘 | Real funds |
demo | 模拟盘 | Simulated funds |
Resolution rules:
live; "test" / "模拟" / "demo" → demo) → use it and inform the user: "Using --profile live (实盘)" or "Using --profile demo (模拟盘)""Continuing with --profile live (实盘) from earlier""Live (实盘) or Demo (模拟盘)?" — wait for answer before proceedingIf any command returns a 401 / authentication error:
Stop immediately — do not retry the same command
Inform the user: "Authentication failed (401). Your API credentials may be invalid or expired."
Guide the user to update credentials by editing the file directly with their local editor:
~/.okx/config.toml
Update the fields api_key, secret_key, passphrase under the relevant profile. Do NOT paste the new credentials into chat.
4. After the user confirms the file is updated, run okx config show to verify (output is masked)
5. Only then retry the original operation
Profile is the single control for 实盘/模拟盘 switching — exactly two options:
--profile | Mode | Funds |
|---|---|---|
live | 实盘 | Real money — irreversible |
demo | 模拟盘 | Simulated — no real funds |
okx --profile live spot place ... # 实盘 — real funds
okx --profile demo spot place ... # 模拟盘 — simulated funds
Rules:
--profile is required on every authenticated command — determined in "Credential & Profile Check" Step B[profile: live] or [profile: demo]--demo flag for mode switching — use --profile insteadUser: "Buy 0.01 BTC"
Agent: "Live (实盘) or Demo (模拟盘)?"
User: "Demo"
Agent runs: okx --profile demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
Agent replies: "Order placed: 7890123456 (OK) — simulated, no real funds used. [profile: demo]"
okx-cex-marketokx-cex-portfoliookx-cex-trade (this skill)okx-cex-botApplies to all swap, futures, and option orders.--sz always means number of contracts, never a currency amount. Follow this flow before every derivative place order.
| instId pattern | Contract type | Settlement | ctVal unit |
|---|---|---|---|
*-USDT-SWAP | Linear perpetual swap | USDT | Base currency (BTC/ETH/…) |
*-USDT-YYMMDD | Linear delivery futures | USDT | Base currency |
*-USD-SWAP | Inverse perpetual swap | Base coin | USD (fixed, e.g. 100 USD) |
*-USD-YYMMDD | Inverse delivery futures | Base coin | USD (fixed, e.g. 100 USD) |
User mentions a quantity:
1. Includes currency unit (USDT / USD / $ / ¥ / 元)
→ User is specifying a quote-currency amount → must convert to contracts (see Step 3)
2. Explicitly says "X contracts" / "X 张" / "X 手"
→ Use directly as sz, no conversion needed
3. Plain number with no unit (for swap/futures/option orders)
→ Ambiguous — ask before proceeding:
"您输入的 X 是合约张数还是 USDT 金额?"
(Is X the number of contracts or a USDT amount?)
Wait for the user's answer before continuing.
Before running any formula, fetch the required data:
# Get ctVal, minSz, lotSz for the instrument
okx market instruments --instType <SWAP|FUTURES|OPTION> --instId <instId> --json
# Get current mark price (for linear contracts and options)
okx market mark-price --instType <SWAP|FUTURES|OPTION> --instId <instId> --json
*-USDT-SWAP / *-USDT-YYMMDD)ctVal unit: base currency (e.g. ETH)
markPx unit: USDT
Formula: sz = floor(usdtAmt / (markPx × ctVal))
Example — ETH-USDT-SWAP (ctVal=0.1 ETH, markPx=2000 USDT):
200 USDT → floor(200 / (2000 × 0.1)) = floor(1.0) = 1 contract ✓
50 USDT → floor(50 / (2000 × 0.1)) = floor(0.25) = 0 ✗ insufficient
*-USD-SWAP / *-USD-YYMMDD)ctVal unit: USD (fixed face value, e.g. 100 USD per contract)
markPx is NOT needed for sz calculation
Formula: sz = floor(usdtAmt / ctVal) (1 USDT ≈ 1 USD)
Example — BTC-USD-SWAP (ctVal=100 USD):
500 USDT → floor(500 / 100) = 5 contracts ✓
⚠ Settlement warning (always show):
"This is an inverse contract. Margin and P&L are settled in BTC, not USDT.
Your USDT must be converted to BTC to meet margin requirements."
*-USD-YYMMDD-strike-C/P)markPx unit: base currency (e.g. BTC per contract)
ctVal unit: base currency (e.g. 0.1 BTC)
Need BTC spot price to convert USDT → contracts
Required data:
okx option greeks --uly <BTC-USD> --expTime <YYMMDD> --json → markPx (BTC)
okx market ticker BTC-USDT --json → last price (btcPx)
Formula (buyer cost):
sz = floor(usdtAmt / (markPx_BTC × btcPx × ctVal))
Example — BTC-USD-250328-95000-C (markPx=0.005 BTC, btcPx=95000, ctVal=0.1 BTC):
200 USDT → floor(200 / (0.005 × 95000 × 0.1))
= floor(200 / 47.5) = floor(4.21) = 4 contracts
Total premium ≈ 4 × 0.005 × 0.1 = 0.002 BTC ≈ 190 USDT
⚠ Always show both BTC and USDT premium cost to the buyer.
⚠ Seller margin is also in BTC — remind user of liquidation risk.
After computing sz:
1. sz == 0 or sz < minSz
→ Reject. Inform user:
"Amount too small: minimum order is {minSz} contract(s),
equivalent to ~{minSz × markPx × ctVal} USDT."
2. sz not a multiple of lotSz
→ Round down to the nearest valid multiple:
sz = floor(sz / lotSz) × lotSz
3. sz ≥ minSz
→ Show conversion summary and wait for user confirmation before placing:
Conversion summary:
Input: {usdtAmt} USDT
markPx: {markPx} | ctVal: {ctVal}
Raw: {usdtAmt} / ({markPx} × {ctVal}) = {rawResult}
Rounded: {sz} contracts (~{sz × markPx × ctVal} USDT actual value)
Confirm order with sz={sz}?
# Market buy 0.01 BTC (spot)
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
# Buy $10 worth of SOL (spot, USDT amount)
okx spot place --instId SOL-USDT --side buy --ordType market --sz 10 --tgtCcy quote_ccy
# Limit sell 0.01 BTC at $100,000 (spot)
okx spot place --instId BTC-USDT --side sell --ordType limit --sz 0.01 --px 100000
# Long 1 contract BTC perp (cross margin)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long
# Long 1 contract with attached TP/SL (one step)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx -1 --slTriggerPx 88000 --slOrdPx -1
# Close BTC perp long position entirely at market
okx swap close --instId BTC-USDT-SWAP --mgnMode cross --posSide long
# Set 10x leverage on BTC perp (cross)
okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross
# --- Stock Token (TSLA, NVDA, etc.) ---
# Step 1: set leverage ≤ 5x (stock tokens max leverage is 5x)
okx swap leverage --instId TSLA-USDT-SWAP --lever 5 --mgnMode cross
# Step 2: open long on TSLA (--posSide required for stock tokens)
okx swap place --instId TSLA-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long
# Open short on NVDA
okx swap leverage --instId NVDA-USDT-SWAP --lever 3 --mgnMode cross
okx swap place --instId NVDA-USDT-SWAP --side sell --ordType market --sz 1 \
--tdMode cross --posSide short
# Close TSLA long entirely at market
okx swap close --instId TSLA-USDT-SWAP --mgnMode cross --posSide long
# Set TP/SL on a spot BTC position (sell when price hits $105k, SL at $88k)
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%)
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 1 \
--tdMode cross --posSide long --callbackRatio 0.02
# Place trailing stop on spot BTC position (callback 2%)
okx spot algo trail --instId BTC-USDT --side sell --sz 0.01 --callbackRatio 0.02
# View open spot orders
okx spot orders
# View open swap positions
okx swap positions
# Cancel a spot order
okx spot cancel --instId BTC-USDT --ordId <ordId>
---|---|---|---
1 | okx spot place | WRITE | Place spot order (market/limit/post_only/fok/ioc)
2 | okx spot cancel | WRITE | Cancel spot order
3 | okx spot amend | WRITE | Amend spot order price or size
4 | okx spot algo place | WRITE | Place spot TP/SL algo order
5 | okx spot algo amend | WRITE | Amend spot TP/SL levels
6 | okx spot algo cancel | WRITE | Cancel spot algo order
7 | okx spot algo trail | WRITE | Place spot trailing stop order
8 | okx spot orders | READ | List open or historical spot orders
9 | okx spot get | READ | Single spot order details
10 | okx spot fills | READ | Spot trade fill history
11 | | READ | List spot TP/SL algo orders
---|---|---|---
12 | okx swap place | WRITE | Place perpetual swap order
13 | okx swap cancel | WRITE | Cancel swap order
14 | okx swap amend | WRITE | Amend swap order price or size
15 | okx swap close | WRITE | Close entire position at market
16 | okx swap leverage | WRITE | Set leverage for an instrument
17 | okx swap algo place | WRITE | Place swap TP/SL algo order
18 | okx swap algo trail | WRITE | Place swap trailing stop order
19 | okx swap algo amend | WRITE | Amend swap algo order
20 | okx swap algo cancel | WRITE | Cancel swap algo order
21 | okx swap positions | READ | Open perpetual swap positions
22 | | READ | List open or historical swap orders
23 | | READ | Single swap order details
24 | | READ | Swap trade fill history
25 | | READ | Current leverage settings
26 | | READ | List swap algo orders
---|---|---|---
27 | okx futures place | WRITE | Place delivery futures order
28 | okx futures cancel | WRITE | Cancel delivery futures order
29 | okx futures amend | WRITE | Amend delivery futures order price or size
30 | okx futures close | WRITE | Close entire futures position at market
31 | okx futures leverage | WRITE | Set leverage for a futures instrument
32 | okx futures algo place | WRITE | Place futures TP/SL algo order
33 | okx futures algo trail | WRITE | Place futures trailing stop order
34 | okx futures algo amend | WRITE | Amend futures algo order
35 | okx futures algo cancel | WRITE | Cancel futures algo order
36 | | READ | List delivery futures orders
37 | | READ | Open delivery futures positions
38 | | READ | Delivery futures fill history
39 | | READ | Single delivery futures order details
40 | | READ | Current futures leverage settings
41 | | READ | List futures algo orders
---|---|---|---
42 | okx option instruments | READ | Option chain: list available contracts for an underlying
43 | okx option greeks | READ | Implied volatility + Greeks (delta/gamma/theta/vega) by underlying
44 | okx option place | WRITE | Place option order (call or put, buyer or seller)
45 | okx option cancel | WRITE | Cancel unfilled option order
46 | okx option amend | WRITE | Amend option order price or size
47 | okx option batch-cancel | WRITE | Batch cancel up to 20 option orders
48 | okx option orders | READ | List option orders (live / history / archive)
49 | okx option get | READ | Single option order details
50 | okx option positions | READ | Open option positions with live Greeks
51 | | READ | Option trade fill history
User: "Buy $500 worth of ETH at market"
1. okx-cex-portfolio okx account balance USDT → confirm available funds ≥ $500
↓ user approves
2. okx-cex-trade okx spot place --instId ETH-USDT --side buy --ordType market --sz 500 --tgtCcy quote_ccy
3. okx-cex-trade okx spot fills --instId ETH-USDT → confirm fill price and size
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 \
--tpTriggerPx 105000 --tpOrdPx -1 \
--slTriggerPx 88000 --slOrdPx -1
4. okx-cex-trade okx swap positions → confirm position opened
Note: TP/SL is attached directly to the order via
--tpTriggerPx/--slTriggerPx— no separateswap algo placestep needed. Useswap algo placeonly when adding TP/SL to an existing position.
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
User: "Set a 3% trailing stop on my open position"
Spot example (no margin mode needed):
1. okx-cex-portfolio okx account balance BTC → confirm spot BTC holdings
2. okx-cex-market okx market ticker BTC-USDT → current price reference
↓ user approves
3. okx-cex-trade okx spot algo trail --instId BTC-USDT --side sell \
--sz <spot_sz> --callbackRatio 0.03
4. okx-cex-trade okx spot algo orders --instId BTC-USDT → confirm trail order placed
Swap/Perpetual example:
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
Futures/Delivery example:
1. okx-cex-trade okx futures positions → confirm size of open long
2. okx-cex-market okx market ticker BTC-USDT-<YYMMDD> → current price reference
↓ user approves
3. okx-cex-trade okx futures algo trail --instId BTC-USDT-<YYMMDD> --side sell \
--sz <pos_size> --tdMode cross --posSide long --callbackRatio 0.03
4. okx-cex-trade okx futures algo orders --instId BTC-USDT-<YYMMDD> → confirm trail order placed
User: "I want to long TSLA with 500 USDT"
1. okx-cex-market okx market stock-tokens → confirm TSLA-USDT-SWAP is available
2. okx-cex-market okx market ticker TSLA-USDT-SWAP → current price (e.g., markPx=310 USDT)
3. okx-cex-market okx market instruments --instType SWAP --instId TSLA-USDT-SWAP --json
→ ctVal=1, minSz=1, lotSz=1
Agent computes: sz = floor(500 / (310 × 1)) = 1 contract (~310 USDT)
Agent shows conversion summary and asks to confirm
↓ user confirms
4. okx-cex-portfolio okx account balance USDT → confirm margin available
5. okx-cex-trade okx swap get-leverage --instId TSLA-USDT-SWAP --mgnMode cross
→ check current leverage; must be ≤ 5x
(if not set or > 5x) okx swap leverage --instId TSLA-USDT-SWAP --lever 5 --mgnMode cross
6. okx-cex-trade okx swap place --instId TSLA-USDT-SWAP --side buy --ordType market \
--sz 1 --tdMode cross --posSide long
7. okx-cex-trade okx swap positions TSLA-USDT-SWAP → confirm position opened
⚠ Stock token constraints : max leverage 5x (exchange rejects > 5x).
--posSideis required. Trading follows stock market hours — confirm live ticker before placing.
User: "用 200 USDT 做多 ETH 永续 (cross margin)"
1. okx-cex-market okx market instruments --instType SWAP --instId ETH-USDT-SWAP --json
→ ctVal=0.1 ETH, minSz=1, lotSz=1
2. okx-cex-market okx market mark-price --instType SWAP --instId ETH-USDT-SWAP --json
→ markPx=2000 USDT
3. Agent computes: sz = floor(200 / (2000 × 0.1)) = 1 contract (~200 USDT)
Agent informs user of conversion summary and asks to confirm
↓ user confirms
4. okx-cex-trade okx swap place --instId ETH-USDT-SWAP --side buy --ordType market \
--sz 1 --tdMode cross --profile <live|demo>
5. okx-cex-trade okx swap positions ETH-USDT-SWAP → confirm position opened
User: "用 500 USDT 开一个 BTC 币本位永续多单"
1. okx-cex-market okx market instruments --instType SWAP --instId BTC-USD-SWAP --json
→ ctVal=100 USD, minSz=1
2. Agent computes: sz = floor(500 / 100) = 5 contracts
Agent warns: "BTC-USD-SWAP 是币本位合约,保证金和盈亏以 BTC 结算,非 USDT。
请确认账户有足够 BTC 作为保证金。"
Agent shows conversion summary and asks to confirm
↓ user confirms
3. okx-cex-trade okx swap place --instId BTC-USD-SWAP --side buy --ordType market \
--sz 5 --tdMode cross --profile <live|demo>
4. okx-cex-trade okx swap positions BTC-USD-SWAP → confirm position opened
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
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
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
Before any authenticated command:
Determine profile (required):
live (实盘) or demo (模拟盘) — exactly these two values"Using --profile live (实盘)""Continuing with --profile live (实盘) from earlier""Live (实盘) or Demo (模拟盘)?" — wait for answerIf no credentials configured: guide user to run okx config init, stop all trading actions
After every command result: append [profile: live] or [profile: demo] to the response
Spot (instId format: BTC-USDT):
okx spot place/cancel/amendokx spot algo place/amend/cancelokx spot algo trailokx spot orders/get/fills/algo ordersSwap/Perpetual (instId format: BTC-USDT-SWAP):
okx swap place/cancel/amendokx swap closeokx swap leverage / okx swap get-leverageokx swap algo place/amend/cancelokx swap algo trailokx swap positions/orders/get/fills/get-leverage/algo ordersFutures/Delivery (instId format: BTC-USDT-<YYMMDD>):
okx futures place/cancel/amendokx futures closeokx futures leverage / okx futures get-leverageokx futures algo place/amend/cancelokx futures algo trailokx futures orders/positions/fills/get/get-leverage/algo ordersOptions (instId format: BTC-USD-250328-95000-C or ...-P):
okx option instruments --uly BTC-USDokx option greeks --uly BTC-USDokx option place/cancel/amendokx option batch-cancel --orders '[...]'okx option orders/get/positions/fillscash for buyers (full premium upfront, no liquidation risk); cross or isolated for sellers (margin required)Read commands (orders, positions, fills, get, get-leverage, algo orders): run immediately; note the profile 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 ; omit in net modeWrite commands (place, cancel, amend, close, leverage, algo): two confirmations required:
--profile live (实盘) or --profile demo (模拟盘)--instId, --side, --ordType, --sz; price (--px) required for limit orders; optionally attach TP/SL with --tpTriggerPx/--slTriggerPxspot place: run okx spot orders to confirm order is live or okx spot fills if market orderswap place: run okx swap orders or okx swap positions to confirmswap close: run okx swap positions to confirm position size is 0futures place: run okx futures orders or okx futures positions to confirm--ordType | Description | Requires --px |
|---|---|---|
market | Fill immediately at best price | No |
limit | Fill at specified price or better | Yes |
post_only | Limit order; cancelled if it would be a taker | Yes |
fok | Fill entire order immediately or cancel | Yes |
okx spot place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
[--tgtCcy <base_ccy|quote_ccy>] [--px <price>] \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Spot instrument (e.g., BTC-USDT) |
--side | Yes | - | buy or sell |
--ordType | Yes | - | , , , , |
okx spot cancel --instId <id> --ordId <id> [--json]
okx spot amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of --newSz or --newPx.
okx spot algo place --instId <id> --side <buy|sell> \
--ordType <oco|conditional|move_order_stop> --sz <n> \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--callbackRatio <r>] [--callbackSpread <s>] [--activePx <p>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Spot instrument (e.g., BTC-USDT) |
--side | Yes | - | buy or sell |
--ordType | Yes | - | , , or |
For oco: provide both TP and SL params. For conditional: provide only TP or only SL. For move_order_stop: provide --callbackRatio or --callbackSpread (one required).
okx spot algo amend --instId <id> --algoId <id> \
[--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
[--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]
okx spot algo cancel --instId <id> --algoId <id> [--json]
okx spot algo trail --instId <id> --side <buy|sell> --sz <n> \
[--callbackRatio <ratio>] [--callbackSpread <spread>] \
[--activePx <price>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Spot instrument (e.g., BTC-USDT) |
--side | Yes | - | buy or sell — use sell to protect a long spot position |
--sz |
Spot trailing stop does not require
--tdModeor--posSide(spot has no margin mode or position side concept).
okx spot orders [--instId <id>] [--history] [--json]
| Flag | Effect |
|---|---|
| (default) | Open/pending orders |
--history | Historical (filled, cancelled) orders |
okx spot get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns: ordId, instId, side, ordType, px, sz, fillSz, avgPx, state, cTime.
okx spot fills [--instId <id>] [--ordId <id>] [--json]
Returns: instId, side, fillPx, fillSz, fee, ts.
okx spot algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
Returns: algoId, instId, type, side, sz, tpTrigger, slTrigger, state.
okx swap place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
--tdMode <cross|isolated> \
[--tgtCcy <base_ccy|quote_ccy>] \
[--posSide <long|short>] [--px <price>] \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Swap instrument (e.g., BTC-USDT-SWAP) |
--side | Yes | - | buy or sell |
--ordType | Yes | - | , , , , |
okx swap cancel --instId <id> --ordId <id> [--json]
okx swap amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
okx swap close --instId <id> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--autoCxl] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Swap instrument |
--mgnMode | Yes | - | cross or isolated |
--posSide | Cond. | - | long or — required in hedge mode |
Closes the entire position at market price.
okx swap leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Swap instrument |
--lever | Yes | - | Leverage multiplier (e.g., 10) |
--mgnMode | Yes | - | cross or isolated |
⚠ Stock tokens (e.g.,
TSLA-USDT-SWAP): maximum leverage is 5x. The exchange will reject--levervalues above 5 for stock token instruments.
okx swap get-leverage --instId <id> --mgnMode <cross|isolated> [--json]
Returns table: instId, mgnMode, posSide, lever.
okx swap algo place --instId <id> --side <buy|sell> \
--ordType <oco|conditional|move_order_stop> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--reduceOnly] \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--callbackRatio <r>] [--callbackSpread <s>] [--activePx <p>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Swap instrument (e.g., BTC-USDT-SWAP) |
--side | Yes | - | buy or sell |
--ordType | Yes | - | , , or |
For move_order_stop: provide --callbackRatio or --callbackSpread (one required).
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 |
|---|---|---|---|
--callbackRatio | Cond. | - | Trailing callback as a ratio (e.g., 0.02 = 2%); cannot be combined with --callbackSpread |
--callbackSpread | Cond. | - | Trailing callback as fixed price distance; cannot be combined with --callbackRatio |
--activePx | No |
okx swap algo amend --instId <id> --algoId <id> \
[--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
[--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]
okx swap algo cancel --instId <id> --algoId <id> [--json]
okx swap orders [--instId <id>] [--history] [--json]
okx swap get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns: ordId, instId, side, posSide, ordType, px, sz, fillSz, avgPx, state, cTime.
okx swap positions [<instId>] [--json]
Returns: instId, side, size, avgPx, upl, uplRatio, lever. Only non-zero positions.
okx swap fills [--instId <id>] [--ordId <id>] [--archive] [--json]
--archive: access older fills beyond the default window.
okx swap algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
okx futures place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
--tdMode <cross|isolated> \
[--tgtCcy <base_ccy|quote_ccy>] \
[--posSide <long|short>] [--px <price>] [--reduceOnly] \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--tgtCcy | No | base_ccy | base_ccy: sz in contracts; quote_ccy: sz in USDT amount |
--tpTriggerPx | No | - | Attached take-profit trigger price |
--tpOrdPx | No | - | TP order price; use -1 for market execution |
--instId format: BTC-USDT-<YYMMDD> (delivery date suffix).
okx futures cancel --instId <id> --ordId <id> [--json]
okx futures amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of --newSz or --newPx.
okx futures close --instId <id> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--autoCxl] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Futures instrument (e.g., BTC-USDT-260328) |
--mgnMode | Yes | - | cross or isolated |
--posSide | Cond. | - | or — required in hedge mode |
Closes the entire position at market price.
okx futures leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Futures instrument |
--lever | Yes | - | Leverage multiplier (e.g., 10) |
--mgnMode | Yes | - | cross or isolated |
okx futures get-leverage --instId <id> --mgnMode <cross|isolated> [--json]
Returns table: instId, mgnMode, posSide, lever.
okx futures orders [--instId <id>] [--status <open|history|archive>] [--json]
--status | Effect |
|---|---|
open | Active/pending orders (default) |
history | Recent completed/cancelled |
archive | Older history |
okx futures positions [<instId>] [--json]
Returns: instId, side, pos, avgPx, upl, lever.
okx futures fills [--instId <id>] [--ordId <id>] [--archive] [--json]
okx futures get --instId <id> [--ordId <id>] [--json]
okx futures algo place --instId <id> --side <buy|sell> \
--ordType <oco|conditional|move_order_stop> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--reduceOnly] \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--callbackRatio <r>] [--callbackSpread <s>] [--activePx <p>] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Futures instrument (e.g., BTC-USDT-<YYMMDD>) |
--side | Yes | - | buy or sell |
--ordType | Yes | - | , , or |
--instId format: BTC-USDT-<YYMMDD> (e.g., BTC-USDT-250328). For move_order_stop: provide --callbackRatio or --callbackSpread (one required).
okx futures 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 |
|---|---|---|---|
--callbackRatio | Cond. | - | Trailing callback as a ratio (e.g., 0.02 = 2%); cannot be combined with --callbackSpread |
--callbackSpread | Cond. | - | Trailing callback as fixed price distance; cannot be combined with --callbackRatio |
--activePx | No |
okx futures algo amend --instId <id> --algoId <id> \
[--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
[--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]
okx futures algo cancel --instId <id> --algoId <id> [--json]
okx futures algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
okx option instruments --uly <underlying> [--expTime <YYMMDD>] [--json]
| Param | Required | Description |
|---|---|---|
--uly | Yes | Underlying, e.g. BTC-USD or ETH-USD |
--expTime | No | Filter 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.
okx option greeks --uly <underlying> [--expTime <YYMMDD>] [--json]
Returns IV (markVol) and BS Greeks (deltaBS, gammaBS, thetaBS, vegaBS) plus markPx for each contract.
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 |
|---|---|---|---|
--instId | Yes | - | e.g. BTC-USD-250328-95000-C (call) or ...-P (put) |
--side | Yes | - | buy or sell |
--ordType |
tdMode rules:
side=buy): always use cash — pay full premium, no margin call riskside=sell): use cross or isolated — margin required, liquidation riskokx option cancel --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
okx option amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of --newSz or --newPx.
okx option batch-cancel --orders '<JSON>' [--json]
--orders is a JSON array of up to 20 objects, each {"instId":"...","ordId":"..."}:
okx option batch-cancel --orders '[{"instId":"BTC-USD-250328-95000-C","ordId":"123"},{"instId":"BTC-USD-250328-90000-P","ordId":"456"}]'
okx option orders [--instId <id>] [--uly <underlying>] [--history] [--archive] [--json]
| Flag | Effect |
|---|---|
| (default) | Live/pending orders |
--history | Historical (7d) |
--archive | Older archive (3mo) |
okx option get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns: ordId, instId, side, ordType, px, sz, fillSz, avgPx, state, cTime.
okx option positions [--instId <id>] [--uly <underlying>] [--json]
Returns: instId, posSide, pos, avgPx, upl, deltaPA, gammaPA, thetaPA, vegaPA. Only non-zero positions shown.
okx option fills [--instId <id>] [--ordId <id>] [--archive] [--json]
--archive: access fills beyond the default 3-day window (up to 3 months).
| Tool | Description |
|---|---|
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 |
"Buy 0.05 BTC at market"
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.05
# → Order placed: 7890123456 (OK)
"Set a limit sell for 0.1 ETH at $3500"
okx spot place --instId ETH-USDT --side sell --ordType limit --sz 0.1 --px 3500
# → Order placed: 7890123457 (OK)
"Show my open spot orders"
okx spot orders
# → table: ordId, instId, side, type, price, size, filled, state
"Long 10 contracts BTC perp at market (cross margin)"
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 10 \
--tdMode cross --posSide long
# → Order placed: 7890123458 (OK)
"Long 10 contracts BTC perp with TP at $105k and SL at $88k"
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 10 \
--tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx -1 --slTriggerPx 88000 --slOrdPx -1
# → Order placed: 7890123459 (OK) — TP/SL attached via attachAlgoOrds
"Set take profit at $105k and stop loss at $88k on an existing BTC perp long"
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)
"Close my ETH perp position"
okx swap close --instId ETH-USDT-SWAP --mgnMode cross --posSide long
# → Position closed: ETH-USDT-SWAP long
"Set BTC perp leverage to 5x (cross)"
okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross
# → Leverage set: 5x BTC-USDT-SWAP
"Long 1 contract TSLA stock token at market (cross margin)"
okx swap place --instId TSLA-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long
# → Order placed: 7890123461 (OK) [profile: live]
"Open short on NVDA, 2 contracts"
okx swap place --instId NVDA-USDT-SWAP --side sell --ordType market --sz 2 \
--tdMode cross --posSide short
# → Order placed: 7890123462 (OK) [profile: live]
"Place a 2% trailing stop on my BTC perp long"
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 10 \
--tdMode cross --posSide long --callbackRatio 0.02
# → Trailing stop placed: TRAIL123 (OK)
"Place a 3% trailing stop on my spot BTC"
okx spot algo trail --instId BTC-USDT --side sell --sz 0.01 --callbackRatio 0.03
# → Trailing stop placed: TRAIL456 (OK)
"Place a 2% trailing stop on my BTC futures long"
okx futures algo trail --instId BTC-USDT-<YYMMDD> --side sell --sz 5 \
--tdMode cross --posSide long --callbackRatio 0.02
# → Trailing stop placed: TRAIL789 (OK)
"Close my BTC futures long position"
okx futures close --instId BTC-USDT-260328 --mgnMode cross --posSide long
# → Position closed: BTC-USDT-260328 long
"Set BTC futures leverage to 10x (cross)"
okx futures leverage --instId BTC-USDT-260328 --lever 10 --mgnMode cross
# → Leverage set: 10x BTC-USDT-260328
"Place a TP at $105k and SL at $88k on my ETH futures long"
okx futures algo place --instId ETH-USDT-260328 --side sell --ordType oco --sz 5 \
--tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx -1 \
--slTriggerPx 88000 --slOrdPx -1
# → Algo order placed: ALGO789012 (OK)
"Show my open swap positions"
okx swap positions
# → table: instId, side, size, avgPx, upl, uplRatio, lever
"What are my recent fill trades for BTC spot?"
okx spot fills --instId BTC-USDT
# → table: instId, side, fillPx, fillSz, fee, ts
"Show me the BTC option chain expiring March 28"
okx option instruments --uly BTC-USD --expTime 250328
# → table: instId, expTime, stk, optType (C/P), state
"What's the IV and delta for BTC options expiring March 28?"
okx option greeks --uly BTC-USD --expTime 250328
# → table: instId, delta, gamma, theta, vega, iv (markVol), markPx
"Buy 1 BTC call at strike 95000 expiring March 28, limit at 0.005 BTC"
okx option place --instId BTC-USD-250328-95000-C \
--side buy --ordType limit --tdMode cash --sz 1 --px 0.005
# → Order placed: 7890123460 (OK)
"Show my open option positions"
okx option positions
# → table: instId, posSide, pos, avgPx, upl, delta, gamma, theta, vega
--sz is in base currency (e.g., BTC amount), not USDTokx-cex-portfolio account balance before placingmarket orders don't need --px; limit / post_only / fok / ioc dotpTriggerPx and slTriggerPx; price means market execution at triggerBTC-USDT-SWAP is linear (USDT-margined); BTC-USD-SWAP is inverse (BTC-margined). For inverse, warn the user that margin and P&L are settled in BTClong_short_mode); omit in net mode. Check okx account config for posModecross for cross-margin, isolated for isolated marginswap close closes the position; to partial close, use with a reduce-only algoBTC-USDT-<YYMMDD> is linear; BTC-USD-<YYMMDD> is inverse (USD face value, BTC settlement). For inverse, sz = floor(usdtAmt / ctVal) where ctVal is typically 100 USDBTC-USDT-<YYMMDD> (e.g., BTC-USDT-260328 for March 28, 2026 expiry)futures close to close the entire position at market price — same semantics as swap close; to partial close, use futures place with sz = floor(usdtAmt / (markPx_BTC × btcPx × ctVal)){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 existscash (full premium paid upfront, no liquidation); sellers use cross or isolated (margin required, liquidation risk)0.005 = 0.005 BTC premium per contract); always show equivalent USDT value to the user~/.okx/config.toml or env vars--profile <name> is required for all authenticated commands; see "Credential & Profile Check" section[profile: <name>] tag for audit reference--json returns raw OKX API v5 responsenet vs long_short_mode) affects whether --posSide is required--tgtCcy: use quote_ccy when user specifies USDT amount, (default) for base currency or contracts. Do NOT manually convert between currencies — let the API handle it via tgtCcy. Option does not support tgtCcy.Weekly Installs
1.1K
Repository
GitHub Stars
41
First Seen
Mar 8, 2026
Security Audits
Gen Agent Trust HubPassSocketWarnSnykWarn
Installed on
opencode1.1K
codex1.1K
gemini-cli1.1K
amp1.1K
github-copilot1.1K
kimi-cli1.1K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
NestJS专家服务 | 企业级TypeScript后端开发与架构设计
1,000 周安装
安全代码卫士:AI驱动的安全编码指南与最佳实践,防止SQL注入、XSS攻击
1,000 周安装
ESLint迁移到Oxlint完整指南:JavaScript/TypeScript项目性能优化工具
1,000 周安装
Chrome CDP 命令行工具:轻量级浏览器自动化,支持截图、执行JS、无障碍快照
1,000 周安装
Sanity内容建模最佳实践:结构化内容设计原则与无头CMS指南
1,000 周安装
AI Sprint规划器 - 敏捷团队Scrum迭代计划工具,自动估算故事点与容量管理
1,000 周安装
*-USD-YYMMDD-strike-C/P | Inverse option | Base coin | Base currency (e.g. 0.1 BTC) |
okx spot algo ordersokx swap ordersokx swap getokx swap fillsokx swap get-leverageokx swap algo ordersokx futures ordersokx futures positionsokx futures fillsokx futures getokx futures get-leverageokx futures algo ordersokx option fillsshort--szsz--instId--side--sz--tdMode--posSide--tpTriggerPx--slTriggerPx--instId, --mgnMode, --posSide; closes the entire position at market--instId, --mgnMode, --posSide; closes the entire position at market--tpOrdPx -1 for market execution at trigger--callbackRatio (e.g., 0.02 = 2%) or --callbackSpread (fixed price spread); spot does not require --tdMode or --posSidefutures close: run okx futures positions to confirm position size is 0okx spot algo orders to confirm algo is activeokx swap algo orders to confirm algo is activeokx futures algo orders to confirm algo is activeokx spot orders / okx swap orders / okx futures orders to confirm order is goneioc | Fill what's available immediately, cancel rest | Yes |
conditional | Algo: single TP or SL trigger | No (set trigger px) |
oco | Algo: TP + SL together (one cancels other) | No (set both trigger px) |
move_order_stop | Trailing stop (spot/swap/futures) | No (set callback) |
marketlimitpost_onlyfokioc--sz | Yes | - | Order size — unit depends on --tgtCcy |
--tgtCcy | No | base_ccy | base_ccy: sz in base currency (e.g. SOL amount); quote_ccy: sz in quote currency (e.g. USDT amount) |
--px | Cond. | - | Price — required for limit, post_only, fok, ioc |
--tpTriggerPx | No | - | Attached take-profit trigger price |
--tpOrdPx | No | - | TP order price; use -1 for market execution |
--slTriggerPx | No | - | Attached stop-loss trigger price |
--slOrdPx | No | - | SL order price; use -1 for market execution |
ococonditionalmove_order_stop--sz | Yes | - | Order size in base currency |
--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 |
--callbackRatio | Cond. | - | Trailing callback as a ratio (e.g., 0.02 = 2%); cannot be combined with --callbackSpread |
--callbackSpread | Cond. | - | Trailing callback as fixed price distance; cannot be combined with --callbackRatio |
--activePx | No | - | Price at which trailing stop becomes active |
| Yes |
| - |
| Order size in base currency |
--callbackRatio | Cond. | - | Trailing callback as a ratio (e.g., 0.02 = 2%); cannot be combined with --callbackSpread |
--callbackSpread | Cond. | - | Trailing callback as fixed price distance; cannot be combined with --callbackRatio |
--activePx | No | - | Price at which trailing stop becomes active |
marketlimitpost_onlyfokioc--sz | Yes | - | Order size — unit depends on --tgtCcy |
--tdMode | Yes | - | cross or isolated |
--tgtCcy | No | base_ccy | base_ccy: sz in contracts; quote_ccy: sz in USDT amount |
--posSide | Cond. | - | long or short — required in hedge mode |
--px | Cond. | - | Price — required for limit orders |
--tpTriggerPx | No | - | Attached take-profit trigger price |
--tpOrdPx | No | - | TP order price; use -1 for market execution |
--slTriggerPx | No | - | Attached stop-loss trigger price |
--slOrdPx | No | - | SL order price; use -1 for market execution |
short--autoCxl | No | false | Auto-cancel pending orders before closing |
--posSide | Cond. | - | long or short — required for isolated mode in hedge mode |
ococonditionalmove_order_stop--sz | Yes | - | Number of contracts |
--tdMode | Yes | - | cross or isolated |
--posSide | Cond. | - | long or short — required in hedge mode |
--reduceOnly | No | false | Close-only; will not open a new position if one doesn't exist |
--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 |
--callbackRatio | Cond. | - | Trailing callback as a ratio (e.g., 0.02 = 2%); cannot be combined with --callbackSpread |
--callbackSpread | Cond. | - | Trailing callback as fixed price distance; cannot be combined with --callbackRatio |
--activePx | No | - | Price at which trailing stop becomes active |
| - |
| Price at which trailing stop becomes active |
--slTriggerPx | No | - | Attached stop-loss trigger price |
--slOrdPx | No | - | SL order price; use -1 for market execution |
longshort--autoCxl | No | false | Auto-cancel pending orders before closing |
--posSide | Cond. | - | long or short — required for isolated mode in hedge mode |
ococonditionalmove_order_stop--sz | Yes | - | Number of contracts |
--tdMode | Yes | - | cross or isolated |
--posSide | Cond. | - | long or short — required in hedge mode |
--reduceOnly | No | false | Close-only; will not open a new position if one doesn't exist |
--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 |
--callbackRatio | Cond. | - | Trailing callback as a ratio (e.g., 0.02 = 2%); cannot be combined with --callbackSpread |
--callbackSpread | Cond. | - | Trailing callback as fixed price distance; cannot be combined with --callbackRatio |
--activePx | No | - | Price at which trailing stop becomes active |
| - |
| Price at which trailing stop becomes active |
| 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 | No | false | Close-only; do not open a new position |
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 trailing stop (swap/futures) |
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_amend_order | Amend futures order |
futures_close_position | Close futures position |
futures_set_leverage | Set futures leverage |
futures_place_algo_order | Place futures TP/SL algo |
futures_place_move_stop_order | Place futures trailing stop |
futures_amend_algo_order | Amend futures algo |
futures_cancel_algo_orders | Cancel futures algo |
futures_get_orders | List futures orders |
futures_get_positions | Futures positions |
futures_get_fills | Futures fill history |
futures_get_order | Get single futures order |
futures_get_leverage | Get futures leverage |
futures_get_algo_orders | List futures algo orders |
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 |
-1fills shows executed trades; orders --history shows all orders including cancelled--callbackRatio (relative, e.g., 0.02) or --callbackSpread (absolute price), not both; --tdMode and --posSide are not required for spot--side opposite to position direction (e.g., long spot holding → sell algo, short spot → buy algo)swap place--callbackRatio (relative, e.g., 0.02) or --callbackSpread (absolute price), not both--side opposite to position (e.g., long position → sell algo)TSLA-USDT-SWAP, NVDA-USDT-SWAP follow the same linear SWAP flow (USDT-margined, sz in contracts). Key differences: (1) max leverage 5x — check with swap get-leverage before placing, set with swap leverage --lever <n≤5>; (2) --posSide is always required; (3) trading restricted to stock market hours (US stocks: Mon–Fri ~09:30–16:00 ET) — confirm live ticker before placing. Use okx market stock-tokens to list available instruments--reduceOnlyfutures leverage sets leverage for a futures instrument, same constraints as swap; max leverage varies by instrument and account level--callbackRatio (relative, e.g., 0.02) or --callbackSpread (absolute price), not both; same parameters as swap — --tdMode and --posSide required in hedge mode--side opposite to position (e.g., long position → sell algo)swap algo / spot algo commands do not apply to option positions; manage risk by cancelling/amending option orders directlyokx 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 contractbase_ccy