okx-cex-bot

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OKX CEX Bot Trading CLI

OKX CEX 机器人交易CLI

Grid and DCA (Dollar Cost Averaging / Martingale) trading bot management on OKX exchange. All grid and DCA bots in this skill are native OKX platform bots — they run server-side on OKX and do not require a locally running process. Requires API credentials.
用于在OKX交易所管理网格和DCA(定期定额投资/马丁格尔)交易机器人。本技能中的所有网格和DCA机器人都是OKX平台原生机器人——它们在OKX服务端运行,无需本地运行进程。需要API凭证。

Prerequisites

前置条件

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

Skill Routing

技能路由

  • For market data (prices, charts, depth, funding rates) → use
    okx-cex-market
  • For account balance, P&L, positions history, fees, transfers → use
    okx-cex-portfolio
  • For regular spot/swap/futures/algo orders → use
    okx-cex-trade
  • For grid and DCA trading strategies (native OKX platform bots) → use
    okx-cex-bot
    (this skill)
  • 如需查询市场数据(价格、K线、深度、资金费率)→ 使用
    okx-cex-market
  • 如需查询账户余额、盈亏、持仓历史、手续费、转账 → 使用
    okx-cex-portfolio
  • 如需操作常规现货/杠杆/期货/算法订单 → 使用
    okx-cex-trade
  • 如需操作网格和DCA交易策略(OKX平台原生机器人)→ 使用
    okx-cex-bot
    (本技能)

Quickstart

快速入门

bash
undefined
bash
undefined

Create a spot grid bot on BTC ($90k–$100k, 10 grids, invest 1000 USDT)

在BTC上创建现货网格机器人(价格区间9万-10万美元,10格,投资1000 USDT)

okx bot grid create --instId BTC-USDT --algoOrdType grid
--minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
okx bot grid create --instId BTC-USDT --algoOrdType grid
--minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000

Create a contract grid bot on BTC perp (neutral, 5x leverage, 100 contracts)

在BTC永续合约上创建合约网格机器人(中性策略,5倍杠杆,100张合约)

okx bot grid create --instId BTC-USDT-SWAP --algoOrdType contract_grid
--minPx 90000 --maxPx 100000 --gridNum 10
--direction neutral --lever 5 --sz 100
okx bot grid create --instId BTC-USDT-SWAP --algoOrdType contract_grid
--minPx 90000 --maxPx 100000 --gridNum 10
--direction neutral --lever 5 --sz 100

List all active grid bots

列出所有运行中的网格机器人

okx bot grid orders --algoOrdType grid
okx bot grid orders --algoOrdType grid

Get grid bot details and P&L

获取网格机器人详情和盈亏

okx bot grid details --algoOrdType grid --algoId <algoId>
okx bot grid details --algoOrdType grid --algoId <algoId>

Stop a grid bot (keep assets as-is)

停止网格机器人(保留现有资产)

okx bot grid stop --algoId <algoId> --algoOrdType grid --instId BTC-USDT --stopType 2
okx bot grid stop --algoId <algoId> --algoOrdType grid --instId BTC-USDT --stopType 2

Create a DCA bot on BTC (3% TP, 3 safety orders, each triggers at 5% drop)

创建BTC DCA机器人(止盈3%,3个安全订单,每个在价格下跌5%时触发)

okx bot dca create --instId BTC-USDT
--initOrdAmt 50 --safetyOrdAmt 30 --maxSafetyOrds 3
--pxSteps 0.05 --pxStepsMult 1 --volMult 1
--tpPct 0.03 --triggerType 1
okx bot dca create --instId BTC-USDT
--initOrdAmt 50 --safetyOrdAmt 30 --maxSafetyOrds 3
--pxSteps 0.05 --pxStepsMult 1 --volMult 1
--tpPct 0.03 --triggerType 1

List all active spot DCA bots

列出所有运行中的现货DCA机器人

okx bot dca orders
okx bot dca orders

Get DCA bot details

获取DCA机器人详情

okx bot dca details --algoId <algoId>
okx bot dca details --algoId <algoId>

Stop a DCA bot (sell base and get quote)

停止DCA机器人(卖出基础资产兑换为计价资产)

okx bot dca stop --algoId <algoId> --instId BTC-USDT --stopType 1
undefined
okx bot dca stop --algoId <algoId> --instId BTC-USDT --stopType 1
undefined

Command Index

命令索引

Grid Bot

网格机器人

#CommandTypeDescription
1
okx bot grid create
WRITECreate a grid bot
2
okx bot grid stop
WRITEStop a grid bot
3
okx bot grid orders
READList active or history grid bots
4
okx bot grid details
READSingle grid bot details + PnL
5
okx bot grid sub-orders
READIndividual grid fills or live orders
#命令类型描述
1
okx bot grid create
写入创建网格机器人
2
okx bot grid stop
写入停止网格机器人
3
okx bot grid orders
读取列出运行中或历史网格机器人
4
okx bot grid details
读取单个网格机器人详情+盈亏
5
okx bot grid sub-orders
读取单独的网格成交记录或未结订单

DCA Bot

DCA机器人

#CommandTypeDescription
6
okx bot dca create
WRITECreate a DCA bot (spot or contract)
7
okx bot dca stop
WRITEStop a DCA bot (spot or contract)
8
okx bot dca orders
READList active or history DCA bots
9
okx bot dca details
READSingle DCA bot details + PnL
10
okx bot dca sub-orders
READIndividual DCA fills, live orders, or cycles
Use
--type spot
(default) or
--type contract
to switch between spot and contract DCA.
#命令类型描述
6
okx bot dca create
写入创建DCA机器人(现货或合约)
7
okx bot dca stop
写入停止DCA机器人(现货或合约)
8
okx bot dca orders
读取列出运行中或历史DCA机器人
9
okx bot dca details
读取单个DCA机器人详情+盈亏
10
okx bot dca sub-orders
读取单独的DCA成交记录、未结订单或周期
使用
--type spot
(默认)或
--type contract
切换现货和合约DCA。

Cross-Skill Workflows

跨技能工作流

Spot Grid Bot

现货网格机器人

User: "Start a BTC grid bot between $90k and $100k with 10 grids, invest 1000 USDT"
1. okx-cex-market    okx market ticker BTC-USDT                     → confirm price is in range
2. okx-cex-portfolio okx account balance USDT                       → confirm available funds
        ↓ user approves
3. okx-cex-bot       okx bot grid create --instId BTC-USDT --algoOrdType grid \
                       --minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
4. okx-cex-bot       okx bot grid orders --algoOrdType grid          → confirm bot is active
5. okx-cex-bot       okx bot grid details --algoOrdType grid --algoId <id> → monitor PnL
用户:"在9万到10万美元之间启动一个BTC网格机器人,10格,投资1000 USDT"
1. okx-cex-market    okx market ticker BTC-USDT                     → 确认价格在区间内
2. okx-cex-portfolio okx account balance USDT                       → 确认可用资金
        ↓ 用户确认
3. okx-cex-bot       okx bot grid create --instId BTC-USDT --algoOrdType grid \
                       --minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
4. okx-cex-bot       okx bot grid orders --algoOrdType grid          → 确认机器人运行中
5. okx-cex-bot       okx bot grid details --algoOrdType grid --algoId <id> → 监控盈亏

Contract Grid Bot (Long / Short / Neutral)

合约网格机器人(做多/做空/中性)

User: "Create a long grid bot on BTC perp from $90k to $100k, 10x leverage"
1. okx-cex-market    okx market ticker BTC-USDT-SWAP                → confirm current price
2. okx-cex-portfolio okx account balance USDT                       → confirm margin
        ↓ user approves
3. okx-cex-bot       okx bot grid create --instId BTC-USDT-SWAP --algoOrdType contract_grid \
                       --minPx 90000 --maxPx 100000 --gridNum 10 \
                       --direction long --lever 10 --sz 100
                       # For short: --direction short; for neutral: --direction neutral
4. okx-cex-bot       okx bot grid orders --algoOrdType contract_grid → confirm active
用户:"在BTC永续合约上创建做多网格机器人,价格区间9万到10万美元,10倍杠杆"
1. okx-cex-market    okx market ticker BTC-USDT-SWAP                → 确认当前价格
2. okx-cex-portfolio okx account balance USDT                       → 确认保证金
        ↓ 用户确认
3. okx-cex-bot       okx bot grid create --instId BTC-USDT-SWAP --algoOrdType contract_grid \
                       --minPx 90000 --maxPx 100000 --gridNum 10 \
                       --direction long --lever 10 --sz 100
                       # 做空:--direction short;中性:--direction neutral
4. okx-cex-bot       okx bot grid orders --algoOrdType contract_grid → 确认运行中

Spot DCA Bot

现货DCA机器人

User: "Set up a DCA bot on ETH, initial buy $100, 5 safety orders at 3% drops, 2% TP"
1. okx-cex-market    okx market ticker ETH-USDT                     → check current price
2. okx-cex-portfolio okx account balance USDT                       → confirm funds available
        ↓ user approves
3. okx-cex-bot       okx bot dca create --instId ETH-USDT \
                       --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 5 \
                       --pxSteps 0.03 --pxStepsMult 1 --volMult 1 \
                       --tpPct 0.02 --triggerType 1
4. okx-cex-bot       okx bot dca orders                             → confirm bot is active
5. okx-cex-bot       okx bot dca details --algoId <id>              → monitor PnL
用户:"给ETH设置一个DCA机器人,首次买入100美元,3%跌幅触发5个安全订单,止盈2%"
1. okx-cex-market    okx market ticker ETH-USDT                     → 查看当前价格
2. okx-cex-portfolio okx account balance USDT                       → 确认可用资金
        ↓ 用户确认
3. okx-cex-bot       okx bot dca create --instId ETH-USDT \
                       --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 5 \
                       --pxSteps 0.03 --pxStepsMult 1 --volMult 1 \
                       --tpPct 0.02 --triggerType 1
4. okx-cex-bot       okx bot dca orders                             → 确认机器人运行中
5. okx-cex-bot       okx bot dca details --algoId <id>              → 监控盈亏

Contract DCA Bot (Long / Short)

合约DCA机器人(做多/做空)

User: "Start a short DCA bot on BTC perp, 3x leverage, $200 initial, 3% TP"
1. okx-cex-market    okx market ticker BTC-USDT-SWAP               → confirm current price
2. okx-cex-portfolio okx account balance USDT                       → confirm margin
        ↓ user approves
3. okx-cex-bot       okx bot dca create --type contract --instId BTC-USDT-SWAP \
                       --initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
                       --pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 \
                       --tpPct 0.03 --lever 3 --side sell
                       # For long: --side buy
4. okx-cex-bot       okx bot dca orders --type contract             → confirm active
5. okx-cex-bot       okx bot dca details --type contract --algoId <id> → monitor PnL
用户:"给BTC永续合约启动一个做空DCA机器人,3倍杠杆,初始投资200美元,止盈3%"
1. okx-cex-market    okx market ticker BTC-USDT-SWAP               → 确认当前价格
2. okx-cex-portfolio okx account balance USDT                       → 确认保证金
        ↓ 用户确认
3. okx-cex-bot       okx bot dca create --type contract --instId BTC-USDT-SWAP \
                       --initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
                       --pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 \
                       --tpPct 0.03 --lever 3 --side sell
                       # 做多:--side buy
4. okx-cex-bot       okx bot dca orders --type contract             → 确认运行中
5. okx-cex-bot       okx bot dca details --type contract --algoId <id> → 监控盈亏

Monitor and Stop All Bots

监控和停止所有机器人

User: "Show all my active bots and stop the ones losing money"
1. okx-cex-bot       okx bot grid orders --algoOrdType grid         → list spot grid bots
2. okx-cex-bot       okx bot grid orders --algoOrdType contract_grid → list contract grid bots
3. okx-cex-bot       okx bot dca orders [--type contract]           → list DCA bots
4. okx-cex-bot       okx bot grid details --algoOrdType grid --algoId <id>  → check PnL
5. okx-cex-bot       okx bot grid stop --algoId <id> --algoOrdType grid --instId BTC-USDT --stopType 2
用户:"展示我所有运行中的机器人,停止亏损的那些"
1. okx-cex-bot       okx bot grid orders --algoOrdType grid         → 列出现货网格机器人
2. okx-cex-bot       okx bot grid orders --algoOrdType contract_grid → 列出合约网格机器人
3. okx-cex-bot       okx bot dca orders [--type contract]           → 列出DCA机器人
4. okx-cex-bot       okx bot grid details --algoOrdType grid --algoId <id>  → 查看盈亏
5. okx-cex-bot       okx bot grid stop --algoId <id> --algoOrdType grid --instId BTC-USDT --stopType 2

Operation Flow

操作流程

Step 1: Identify Bot Type and Action

步骤1:识别机器人类型和操作

  • Grid bot create →
    okx bot grid create
  • Grid bot stop →
    okx bot grid stop
  • Grid bot status/P&L →
    okx bot grid orders
    +
    okx bot grid details
  • Grid individual fills →
    okx bot grid sub-orders
  • DCA bot create →
    okx bot dca create
    (add
    --type contract
    for contract DCA)
  • DCA bot stop →
    okx bot dca stop
    (add
    --type contract
    for contract DCA)
  • DCA bot status/P&L →
    okx bot dca orders
    +
    okx bot dca details
  • DCA individual fills/cycles →
    okx bot dca sub-orders
  • 创建网格机器人 →
    okx bot grid create
  • 停止网格机器人 →
    okx bot grid stop
  • 网格机器人状态/盈亏 →
    okx bot grid orders
    +
    okx bot grid details
  • 网格单独成交记录 →
    okx bot grid sub-orders
  • 创建DCA机器人 →
    okx bot dca create
    (合约DCA添加
    --type contract
  • 停止DCA机器人 →
    okx bot dca stop
    (合约DCA添加
    --type contract
  • DCA机器人状态/盈亏 →
    okx bot dca orders
    +
    okx bot dca details
  • DCA单独成交记录/周期 →
    okx bot dca sub-orders

Step 2: Run Read Commands Immediately — Confirm Writes

步骤2:立即运行读取命令 — 写入操作需确认

Read commands (orders, details, sub-orders): run immediately.
  • --algoOrdType
    for grid → infer from context (
    grid
    for spot,
    contract_grid
    for perp)
  • --type
    for DCA → defaults to
    spot
    ; use
    --type contract
    for contract DCA
  • --history
    → use default (active); only query history if explicitly requested
Write commands (create, stop): confirm once before executing.
  • Grid create: confirm
    --minPx
    ,
    --maxPx
    ,
    --gridNum
    ; verify
    --minPx
    < current price <
    --maxPx
    ; confirm investment size
    • Spot grid:
      --quoteSz
      (USDT) or
      --baseSz
      (base currency)
    • Contract grid:
      --direction
      (
      long
      /
      short
      /
      neutral
      ),
      --lever
      ,
      --sz
      (number of contracts)
  • DCA create: confirm
    --initOrdAmt
    ,
    --safetyOrdAmt
    ,
    --maxSafetyOrds
    ,
    --pxSteps
    ,
    --tpPct
    • Spot DCA: requires
      --triggerType
      (
      1
      =instant,
      2
      =RSI); default
      --type spot
    • Contract DCA: add
      --type contract
      ,
      --lever
      , and
      --side
      (
      buy
      =long,
      sell
      =short)
  • Grid stop: confirm
    --stopType
    (default omitted → keep assets;
    1
    =sell all to quote)
  • DCA stop: confirm
    --stopType
    (
    1
    =sell base to quote, default;
    2
    =keep base)
  • Demo dry-run: suggest
    okx --demo bot grid create ...
    when user is unsure
读取命令(列表、详情、子订单):立即运行。
  • 网格的
    --algoOrdType
    → 从上下文推断(现货用
    grid
    ,永续合约用
    contract_grid
  • DCA的
    --type
    → 默认是
    spot
    ;合约DCA使用
    --type contract
  • --history
    → 默认查询运行中;仅在用户明确要求时查询历史
写入命令(创建、停止):执行前需确认一次。
  • 创建网格:确认
    --minPx
    --maxPx
    --gridNum
    ;验证
    --minPx
    < 当前价格 <
    --maxPx
    ;确认投资金额
    • 现货网格:
      --quoteSz
      (USDT)或
      --baseSz
      (基础货币)
    • 合约网格:
      --direction
      long
      /
      short
      /
      neutral
      )、
      --lever
      --sz
      (合约张数)
  • 创建DCA:确认
    --initOrdAmt
    --safetyOrdAmt
    --maxSafetyOrds
    --pxSteps
    --tpPct
    • 现货DCA:需要
      --triggerType
      1
      =立即启动,
      2
      =RSI信号触发);默认
      --type spot
    • 合约DCA:添加
      --type contract
      --lever
      --side
      buy
      =做多,
      sell
      =做空)
  • 停止网格:确认
    --stopType
    (默认省略→保留资产;
    1
    =全部卖出为计价资产)
  • 停止DCA:确认
    --stopType
    (默认
    1
    =卖出基础资产为计价资产;
    2
    =保留基础资产)
  • 演示试运行:当用户不确定时,建议使用
    okx --demo bot grid create ...

Step 3: Verify After Writes

步骤3:写入操作后验证

  • After grid create: run
    okx bot grid orders
    to confirm bot is active; then
    okx bot grid details
    to monitor PnL
  • After DCA create: run
    okx bot dca orders
    to confirm bot is active; then
    okx bot dca details
    for details
  • After stop: run
    okx bot grid orders --history
    /
    okx bot dca orders --history
    to confirm bot is stopped
  • 创建网格后:运行
    okx bot grid orders
    确认机器人运行中;然后运行
    okx bot grid details
    监控盈亏
  • 创建DCA后:运行
    okx bot dca orders
    确认机器人运行中;然后运行
    okx bot dca details
    查看详情
  • 停止后:运行
    okx bot grid orders --history
    /
    okx bot dca orders --history
    确认机器人已停止

CLI Command Reference

CLI命令参考

Grid Bot — Create

网格机器人 — 创建

bash
okx bot grid create --instId <id> --algoOrdType <type> \
  --maxPx <px> --minPx <px> --gridNum <n> \
  [--runType <1|2>] \
  [--quoteSz <n>] [--baseSz <n>] \
  [--direction <long|short|neutral>] [--lever <n>] [--sz <n>] \
  [--json]
ParamRequiredDefaultDescription
--instId
Yes-Instrument (e.g.,
BTC-USDT
for spot grid,
BTC-USDT-SWAP
for contract grid)
--algoOrdType
Yes-
grid
(spot grid) or
contract_grid
(contract grid)
--maxPx
Yes-Upper price boundary
--minPx
Yes-Lower price boundary
--gridNum
Yes-Grid levels (2–100)
--runType
No
1
1
=arithmetic spacing,
2
=geometric spacing
--quoteSz
Cond.-USDT investment — spot grid only (provide
quoteSz
or
baseSz
)
--baseSz
Cond.-Base currency investment — spot grid only
--direction
Cond.-
long
,
short
, or
neutral
— contract grid only
--lever
Cond.-Leverage (e.g.,
5
) — contract grid only
--sz
Cond.-Number of contracts to invest — contract grid only

bash
okx bot grid create --instId <id> --algoOrdType <type> \
  --maxPx <px> --minPx <px> --gridNum <n> \
  [--runType <1|2>] \
  [--quoteSz <n>] [--baseSz <n>] \
  [--direction <long|short|neutral>] [--lever <n>] [--sz <n>] \
  [--json]
参数必填默认值描述
--instId
-交易对(例如现货网格用
BTC-USDT
,合约网格用
BTC-USDT-SWAP
--algoOrdType
-
grid
(现货网格)或
contract_grid
(合约网格)
--maxPx
-价格上限
--minPx
-价格下限
--gridNum
-网格数量(2-100)
--runType
1
1
=等差间距,
2
=等比间距
--quoteSz
条件必填-USDT投资金额 — 仅现货网格(提供
quoteSz
baseSz
二者其一)
--baseSz
条件必填-基础货币投资金额 — 仅现货网格
--direction
条件必填-
long
short
neutral
— 仅合约网格
--lever
条件必填-杠杆倍数(例如
5
) — 仅合约网格
--sz
条件必填-投资的合约张数 — 仅合约网格

Grid Bot — Stop

网格机器人 — 停止

bash
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
  [--stopType <1|2|3|5|6>] [--json]
--stopType
Behavior
1
Stop + sell/close all positions at market
2
Stop + keep current assets as-is (default)
3
Stop + close at limit prices
5
Stop + partial close
6
Stop without selling (smart arbitrage)

bash
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
  [--stopType <1|2|3|5|6>] [--json]
--stopType
行为
1
停止+市价卖出/平仓所有持仓
2
停止+保留现有资产(默认)
3
停止+限价平仓
5
停止+部分平仓
6
停止不卖出(智能套利)

Grid Bot — List Orders

网格机器人 — 列出订单

bash
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]
ParamRequiredDefaultDescription
--algoOrdType
Yes-
grid
or
contract_grid
--instId
No-Filter by instrument
--algoId
No-Filter by algo ID
--history
NofalseShow completed/stopped bots instead of active

bash
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]
参数必填默认值描述
--algoOrdType
-
grid
contract_grid
--instId
-按交易对筛选
--algoId
-按算法ID筛选
--history
false展示已完成/已停止的机器人,而非运行中的

Grid Bot — Details

网格机器人 — 详情

bash
okx bot grid details --algoOrdType <type> --algoId <id> [--json]
Returns: bot config, current PnL (
pnlRatio
), grid range, number of grids, state, position info.

bash
okx bot grid details --algoOrdType <type> --algoId <id> [--json]
返回:机器人配置、当前盈亏(
pnlRatio
)、网格区间、网格数量、状态、持仓信息。

Grid Bot — Sub-Orders

网格机器人 — 子订单

bash
okx bot grid sub-orders --algoOrdType <type> --algoId <id> [--live] [--json]
FlagEffect
(default)Filled sub-orders (executed grid trades)
--live
Pending grid orders currently on the book

bash
okx bot grid sub-orders --algoOrdType <type> --algoId <id> [--live] [--json]
标识效果
(默认)已成交子订单(已执行的网格交易)
--live
挂单中的未结网格订单

DCA Bot — Create

DCA机器人 — 创建

bash
undefined
bash
undefined

Spot DCA (default)

现货DCA(默认)

okx bot dca create --instId <id>
--initOrdAmt <n> --safetyOrdAmt <n> --maxSafetyOrds <n>
--pxSteps <ratio> --pxStepsMult <mult> --volMult <mult>
--tpPct <ratio> [--slPct <ratio>]
--triggerType <1|2>
[--reserveFunds <true|false>] [--json]
okx bot dca create --instId <id>
--initOrdAmt <n> --safetyOrdAmt <n> --maxSafetyOrds <n>
--pxSteps <ratio> --pxStepsMult <mult> --volMult <mult>
--tpPct <ratio> [--slPct <ratio>]
--triggerType <1|2>
[--reserveFunds <true|false>] [--json]

Contract DCA

合约DCA

okx bot dca create --type contract --instId <id>
--initOrdAmt <n> --safetyOrdAmt <n> --maxSafetyOrds <n>
--pxSteps <ratio> --pxStepsMult <mult> --volMult <mult>
--tpPct <ratio> [--slPct <ratio>]
--lever <n> --side <buy|sell>
[--reserveFunds <true|false>] [--json]

| Param | Required | Default | Description |
|---|---|---|---|
| `--type` | No | `spot` | `spot` or `contract` |
| `--instId` | Yes | - | Instrument (e.g., `BTC-USDT` for spot, `BTC-USDT-SWAP` for contract) |
| `--initOrdAmt` | Yes | - | Initial order amount in USDT |
| `--safetyOrdAmt` | Yes | - | Safety order amount in USDT |
| `--maxSafetyOrds` | Yes | - | Max number of safety orders (e.g., `3`) |
| `--pxSteps` | Yes | - | Price drop % per safety order (e.g., `0.03` = 3%) |
| `--pxStepsMult` | Yes | - | Price step multiplier between safety orders (e.g., `1.2`) |
| `--volMult` | Yes | - | Safety order size multiplier (e.g., `1.5`) |
| `--tpPct` | Yes | - | Take-profit ratio (e.g., `0.03` = 3%) |
| `--slPct` | No | - | Stop-loss ratio (e.g., `0.05` = 5%) |
| `--reserveFunds` | No | `false` | Pre-reserve full required assets upfront |
| `--triggerType` | Spot only | - | `1`=instant start, `2`=RSI signal trigger |
| `--lever` | Contract only | - | Leverage multiplier (e.g., `3`) |
| `--side` | Contract only | - | `buy`=long, `sell`=short |

---
okx bot dca create --type contract --instId <id>
--initOrdAmt <n> --safetyOrdAmt <n> --maxSafetyOrds <n>
--pxSteps <ratio> --pxStepsMult <mult> --volMult <mult>
--tpPct <ratio> [--slPct <ratio>]
--lever <n> --side <buy|sell>
[--reserveFunds <true|false>] [--json]

| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| `--type` | 否 | `spot` | `spot`或`contract` |
| `--instId` | 是 | - | 交易对(例如现货用`BTC-USDT`,合约用`BTC-USDT-SWAP`) |
| `--initOrdAmt` | 是 | - | 初始订单金额(USDT) |
| `--safetyOrdAmt` | 是 | - | 安全订单金额(USDT) |
| `--maxSafetyOrds` | 是 | - | 最大安全订单数量(例如`3`) |
| `--pxSteps` | 是 | - | 每个安全订单触发的价格跌幅比例(例如`0.03`=3%) |
| `--pxStepsMult` | 是 | - | 安全订单之间的价格步长乘数(例如`1.2`) |
| `--volMult` | 是 | - | 安全订单金额乘数(例如`1.5`) |
| `--tpPct` | 是 | - | 止盈比例(例如`0.03`=3%) |
| `--slPct` | 否 | - | 止损比例(例如`0.05`=5%) |
| `--reserveFunds` | 否 | `false` | 提前预扣全部所需资产 |
| `--triggerType` | 仅现货必填 | - | `1`=立即启动,`2`=RSI信号触发 |
| `--lever` | 仅合约必填 | - | 杠杆倍数(例如`3`) |
| `--side` | 仅合约必填 | - | `buy`=做多,`sell`=做空 |

---

DCA Bot — Stop

DCA机器人 — 停止

bash
okx bot dca stop [--type <spot|contract>] --algoId <id> --instId <id> \
  [--stopType <1|2>] [--json]
--stopType
Behavior
1
Sell base currency to quote at market (cash out) — default
2
Keep base currency as-is

bash
okx bot dca stop [--type <spot|contract>] --algoId <id> --instId <id> \
  [--stopType <1|2>] [--json]
--stopType
行为
1
市价卖出基础资产兑换为计价资产(变现)—— 默认
2
保留基础资产不变

DCA Bot — List Orders

DCA机器人 — 列出订单

bash
okx bot dca orders [--type <spot|contract>] [--history] [--json]
ParamRequiredDefaultDescription
--type
No
spot
spot
or
contract
--history
NofalseShow completed/stopped bots instead of active

bash
okx bot dca orders [--type <spot|contract>] [--history] [--json]
参数必填默认值描述
--type
spot
spot
contract
--history
false展示已完成/已停止的机器人,而非运行中的

DCA Bot — Details

DCA机器人 — 详情

bash
okx bot dca details [--type <spot|contract>] --algoId <id> [--json]
Returns: bot config, current PnL (
pnlRatio
), safety orders triggered, state. Contract also returns
direction
,
lever
,
avgPx
.

bash
okx bot dca details [--type <spot|contract>] --algoId <id> [--json]
返回:机器人配置、当前盈亏(
pnlRatio
)、已触发安全订单数量、状态。合约类型还会返回
direction
lever
avgPx

DCA Bot — Sub-Orders

DCA机器人 — 子订单

bash
okx bot dca sub-orders [--type <spot|contract>] --algoId <id> [--live] [--cycleId <id>] [--json]
Flag / ParamEffect
(default, spot)Filled sub-orders (executed DCA buys)
--live
Spot: pending orders currently on the book
(default, contract)List all cycles
--cycleId <id>
Contract: show orders within a specific cycle

bash
okx bot dca sub-orders [--type <spot|contract>] --algoId <id> [--live] [--cycleId <id>] [--json]
标识/参数效果
(默认,现货)已成交子订单(已执行的DCA买入)
--live
现货:挂单中的未结订单
(默认,合约)列出所有周期
--cycleId <id>
合约:展示特定周期内的订单

MCP Tool Reference

MCP工具参考

CLI and MCP tools share the same underlying tool layer. MCP tools accept
type=spot
or
type=contract
directly.
ToolDescription
dca_create_order
Create spot or contract DCA bot
dca_stop_order
Stop spot or contract DCA bot
dca_get_orders
List spot or contract DCA bots
dca_get_order_details
Single DCA bot details
dca_get_sub_orders
Sub-orders (spot) or cycles (contract)

CLI和MCP工具共享同一底层工具层。MCP工具可直接接受
type=spot
type=contract
参数。
工具描述
dca_create_order
创建现货或合约DCA机器人
dca_stop_order
停止现货或合约DCA机器人
dca_get_orders
列出现货或合约DCA机器人
dca_get_order_details
获取单个DCA机器人详情
dca_get_sub_orders
获取子订单(现货)或周期(合约)

Input / Output Examples

输入输出示例

"Start a BTC grid bot from $90k to $100k with 10 grids"
bash
okx bot grid create --instId BTC-USDT --algoOrdType grid \
  --minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
"在9万到10万美元之间启动一个BTC网格机器人,10格"
bash
okx bot grid create --instId BTC-USDT --algoOrdType grid \
  --minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000

→ Grid bot created: 12345678 (OK)

→ 网格机器人已创建:12345678 (OK)


**"Show all my active grid bots"**
```bash
okx bot grid orders --algoOrdType grid
"What's the P&L on my BTC grid bot?"
bash
okx bot grid details --algoOrdType grid --algoId 12345678

**"展示我所有运行中的网格机器人"**
```bash
okx bot grid orders --algoOrdType grid
"我的BTC网格机器人盈亏是多少?"
bash
okx bot grid details --algoOrdType grid --algoId 12345678

→ pnlRatio, pnl, investAmt, totalAnnRate, runType, gridNum, maxPx, minPx

→ pnlRatio, pnl, investAmt, totalAnnRate, runType, gridNum, maxPx, minPx


**"Stop my BTC grid bot and keep the assets"**
```bash
okx bot grid stop --algoId 12345678 --algoOrdType grid --instId BTC-USDT --stopType 2
"Create a DCA bot on ETH: $100 initial, safety orders at 3% drops, 2% TP"
bash
okx bot dca create --instId ETH-USDT \
  --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
  --pxSteps 0.03 --pxStepsMult 1 --volMult 1 \
  --tpPct 0.02 --triggerType 1

**"停止我的BTC网格机器人,保留资产"**
```bash
okx bot grid stop --algoId 12345678 --algoOrdType grid --instId BTC-USDT --stopType 2
"给ETH创建一个DCA机器人:初始投入100美元,3%跌幅触发安全订单,止盈2%"
bash
okx bot dca create --instId ETH-USDT \
  --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
  --pxSteps 0.03 --pxStepsMult 1 --volMult 1 \
  --tpPct 0.02 --triggerType 1

→ DCA bot created: 87654321 (OK)

→ DCA机器人已创建:87654321 (OK)


**"Show my active DCA bots"**
```bash
okx bot dca orders
"How is my ETH DCA bot doing?"
bash
okx bot dca details --algoId 87654321

**"展示我运行中的DCA机器人"**
```bash
okx bot dca orders
"我的ETH DCA机器人运行情况如何?"
bash
okx bot dca details --algoId 87654321

→ current PnL, avg entry, safety orders triggered, TP target

→ 当前盈亏、平均入场价、已触发安全订单数、止盈目标


**"Stop my ETH DCA bot and sell everything"**
```bash
okx bot dca stop --algoId 87654321 --instId ETH-USDT --stopType 1
"Create a contract DCA bot on BTC perp, long, 3x leverage, 2% TP"
bash
okx bot dca create --type contract --instId BTC-USDT-SWAP \
  --initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
  --pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 \
  --tpPct 0.02 --lever 3 --side buy

**"停止我的ETH DCA机器人,卖出所有资产"**
```bash
okx bot dca stop --algoId 87654321 --instId ETH-USDT --stopType 1
"给BTC永续合约创建一个做多DCA机器人,3倍杠杆,止盈2%"
bash
okx bot dca create --type contract --instId BTC-USDT-SWAP \
  --initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
  --pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 \
  --tpPct 0.02 --lever 3 --side buy

Edge Cases

边缘情况

Grid Bot

网格机器人

  • Price out of range:
    --minPx
    must be < current price <
    --maxPx
    ; check with
    okx-cex-market
    first
  • Insufficient balance: check
    okx-cex-portfolio
    account balance
    before creating
  • Contract grid direction:
    long
    (buys more at lower prices),
    short
    (sells at higher),
    neutral
    (both)
  • Contract grid --sz: number of contracts, not USDT amount
  • Stop type:
    stopType 1
    sells/closes all;
    stopType 2
    keeps assets;
    stopType 5/6
    for contract grid positions
  • Already stopped bot: stop returns error — check
    bot grid orders --history
    first to confirm state
  • Demo mode:
    okx --demo bot grid create ...
    — safe for testing, no real funds
  • 价格超出区间
    --minPx
    必须 < 当前价格 <
    --maxPx
    ;创建前先通过
    okx-cex-market
    查询
  • 余额不足:创建前先通过
    okx-cex-portfolio
    account balance
    查询
  • 合约网格方向
    long
    (价格越低买越多)、
    short
    (价格越高卖越多)、
    neutral
    (双向)
  • 合约网格 --sz:是合约张数,不是USDT金额
  • 停止类型
    stopType 1
    卖出/平仓所有资产;
    stopType 2
    保留资产;
    stopType 5/6
    用于合约网格持仓
  • 机器人已停止:停止操作会返回错误 — 停止前先通过
    bot grid orders --history
    确认状态
  • 演示模式
    okx --demo bot grid create ...
    — 测试安全,无需真实资金

DCA Bot

DCA机器人

  • Insufficient balance: check
    okx-cex-portfolio
    account balance
    before creating
  • pxStepsMult: use
    1.0
    for equal price spacing;
    >1.0
    to widen gaps between successive safety orders
  • volMult: use
    1.0
    for equal safety order sizes;
    >1.0
    to increase size per safety order (Martingale)
  • triggerType 2 (RSI): requires additional RSI parameters — use
    1
    (instant) unless specifically requested
  • Stop type:
    stopType 1
    sells base to quote (cash out);
    stopType 2
    keeps base currency as-is
  • Already stopped bot: stop returns error — check
    bot dca orders --history
    first to confirm state
  • Contract DCA: add
    --type contract
    to any DCA CLI command; create also requires
    --lever
    and
    --side
  • 余额不足:创建前先通过
    okx-cex-portfolio
    account balance
    查询
  • pxStepsMult
    1.0
    代表等间距;
    >1.0
    代表连续安全订单之间的价格间距逐渐扩大
  • volMult
    1.0
    代表安全订单金额相等;
    >1.0
    代表每个后续安全订单金额递增(马丁格尔)
  • triggerType 2 (RSI):需要额外的RSI参数 — 除非用户明确要求,否则使用
    1
    (立即启动)
  • 停止类型
    stopType 1
    卖出基础资产为计价资产(变现);
    stopType 2
    保留基础资产
  • 机器人已停止:停止操作会返回错误 — 停止前先通过
    bot dca orders --history
    确认状态
  • 合约DCA:所有DCA CLI命令都添加
    --type contract
    ;创建还需要
    --lever
    --side
    参数

Communication Guidelines

沟通指南

  • Use "bot" not "strategy" when referring to grid or DCA in user-facing responses (e.g., "grid bot", "DCA bot" — not "grid strategy" or "DCA strategy").
  • Always refer to DCA bots as "DCA" — do not translate to "定投" or "recurring buy". The underlying mechanism is Martingale (马丁格尔), not simple dollar cost averaging. Use "DCA" in all user-facing responses regardless of language.
  • Grid bot can be referred to as "网格" in Chinese contexts.
  • 面向用户回复时,提到网格或DCA请使用**"机器人"**而非"策略"(例如"网格机器人"、"DCA机器人",不要用"网格策略"或"DCA策略")。
  • 所有面向用户的回复中DCA直接称为**"DCA"**,不要翻译成"定投"或"定期买入"。底层机制是马丁格尔,不是简单的定期定额投资,无论语言版本都使用"DCA"。
  • 中文语境下网格机器人可简称为"网格"。

Global Notes

全局注意事项

  • Grid and DCA bots are native OKX platform bots — they run entirely on OKX servers; stopping the CLI does not affect them
  • All write commands require valid credentials in
    ~/.okx/config.toml
    or env vars
  • --profile <name>
    switches between multiple accounts
  • --json
    returns raw OKX API v5 response
  • Rate limit: 20 requests per 2 seconds per UID for all bot operations
  • Grid
    --gridNum
    range: 2–100
  • DCA safety orders are triggered sequentially as price drops by
    --pxSteps
    increments
  • Contract DCA automatically starts with an instant trigger (set by the tool internally)
  • 网格和DCA机器人是OKX平台原生机器人 — 完全在OKX服务器上运行,关闭CLI不会影响它们
  • 所有写入命令都需要
    ~/.okx/config.toml
    或环境变量中存在有效凭证
  • --profile <name>
    可切换多个账户
  • --json
    返回原始OKX API v5响应
  • 限流规则:所有机器人操作每个UID每2秒最多20次请求
  • 网格
    --gridNum
    范围:2-100
  • DCA安全订单会随着价格下跌
    --pxSteps
    的幅度依次触发
  • 合约DCA默认立即触发启动(工具内部自动设置)