okx-cex-bot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOKX 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
前置条件
- Install CLI:
okxbashnpm install -g @okx_ai/okx-trade-cli - Configure credentials:
Or set environment variables:bash
okx config initbashexport OKX_API_KEY=your_key export OKX_SECRET_KEY=your_secret export OKX_PASSPHRASE=your_passphrase - Test with demo mode (simulated trading, no real funds):
bash
okx --demo bot grid orders --algoOrdType grid
- 安装 CLI:
okxbashnpm install -g @okx_ai/okx-trade-cli - 配置凭证:
或者设置环境变量:bash
okx config initbashexport OKX_API_KEY=your_key export OKX_SECRET_KEY=your_secret export OKX_PASSPHRASE=your_passphrase - 使用演示模式测试(模拟交易,无需真实资金):
bash
okx --demo 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 (this skill)
okx-cex-bot
- 如需查询市场数据(价格、K线、深度、资金费率)→ 使用
okx-cex-market - 如需查询账户余额、盈亏、持仓历史、手续费、转账 → 使用
okx-cex-portfolio - 如需操作常规现货/杠杆/期货/算法订单 → 使用
okx-cex-trade - 如需操作网格和DCA交易策略(OKX平台原生机器人)→ 使用 (本技能)
okx-cex-bot
Quickstart
快速入门
bash
undefinedbash
undefinedCreate 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
--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
--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
--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
--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
--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
--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
undefinedokx bot dca stop --algoId <algoId> --instId BTC-USDT --stopType 1
undefinedCommand Index
命令索引
Grid Bot
网格机器人
| # | Command | Type | Description |
|---|---|---|---|
| 1 | | WRITE | Create a grid bot |
| 2 | | WRITE | Stop a grid bot |
| 3 | | READ | List active or history grid bots |
| 4 | | READ | Single grid bot details + PnL |
| 5 | | READ | Individual grid fills or live orders |
| # | 命令 | 类型 | 描述 |
|---|---|---|---|
| 1 | | 写入 | 创建网格机器人 |
| 2 | | 写入 | 停止网格机器人 |
| 3 | | 读取 | 列出运行中或历史网格机器人 |
| 4 | | 读取 | 单个网格机器人详情+盈亏 |
| 5 | | 读取 | 单独的网格成交记录或未结订单 |
DCA Bot
DCA机器人
| # | Command | Type | Description |
|---|---|---|---|
| 6 | | WRITE | Create a DCA bot (spot or contract) |
| 7 | | WRITE | Stop a DCA bot (spot or contract) |
| 8 | | READ | List active or history DCA bots |
| 9 | | READ | Single DCA bot details + PnL |
| 10 | | READ | Individual DCA fills, live orders, or cycles |
Use(default) or--type spotto switch between spot and contract DCA.--type contract
| # | 命令 | 类型 | 描述 |
|---|---|---|---|
| 6 | | 写入 | 创建DCA机器人(现货或合约) |
| 7 | | 写入 | 停止DCA机器人(现货或合约) |
| 8 | | 读取 | 列出运行中或历史DCA机器人 |
| 9 | | 读取 | 单个DCA机器人详情+盈亏 |
| 10 | | 读取 | 单独的DCA成交记录、未结订单或周期 |
使用(默认)或--type spot切换现货和合约DCA。--type contract
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 2Operation 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 ordersokx bot grid details - Grid individual fills →
okx bot grid sub-orders - DCA bot create → (add
okx bot dca createfor contract DCA)--type contract - DCA bot stop → (add
okx bot dca stopfor contract DCA)--type contract - DCA bot status/P&L → +
okx bot dca ordersokx bot dca details - DCA individual fills/cycles →
okx bot dca sub-orders
- 创建网格机器人 →
okx bot grid create - 停止网格机器人 →
okx bot grid stop - 网格机器人状态/盈亏 → +
okx bot grid ordersokx bot grid details - 网格单独成交记录 →
okx bot grid sub-orders - 创建DCA机器人 → (合约DCA添加
okx bot dca create)--type contract - 停止DCA机器人 → (合约DCA添加
okx bot dca stop)--type contract - DCA机器人状态/盈亏 → +
okx bot dca ordersokx 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.
- for grid → infer from context (
--algoOrdTypefor spot,gridfor perp)contract_grid - for DCA → defaults to
--type; usespotfor contract DCA--type contract - → use default (active); only query history if explicitly requested
--history
Write commands (create, stop): confirm once before executing.
- Grid create: confirm ,
--minPx,--maxPx; verify--gridNum< current price <--minPx; confirm investment size--maxPx- Spot grid: (USDT) or
--quoteSz(base currency)--baseSz - Contract grid: (
--direction/long/short),neutral,--lever(number of contracts)--sz
- Spot grid:
- DCA create: confirm ,
--initOrdAmt,--safetyOrdAmt,--maxSafetyOrds,--pxSteps--tpPct- Spot DCA: requires (
--triggerType=instant,1=RSI); default2--type spot - Contract DCA: add ,
--type contract, and--lever(--side=long,buy=short)sell
- Spot DCA: requires
- Grid stop: confirm (default omitted → keep assets;
--stopType=sell all to quote)1 - DCA stop: confirm (
--stopType=sell base to quote, default;1=keep base)2 - Demo dry-run: suggest when user is unsure
okx --demo bot grid create ...
读取命令(列表、详情、子订单):立即运行。
- 网格的 → 从上下文推断(现货用
--algoOrdType,永续合约用grid)contract_grid - DCA的 → 默认是
--type;合约DCA使用spot--type contract - → 默认查询运行中;仅在用户明确要求时查询历史
--history
写入命令(创建、停止):执行前需确认一次。
- 创建网格:确认、
--minPx、--maxPx;验证--gridNum< 当前价格 <--minPx;确认投资金额--maxPx- 现货网格:(USDT)或
--quoteSz(基础货币)--baseSz - 合约网格:(
--direction/long/short)、neutral、--lever(合约张数)--sz
- 现货网格:
- 创建DCA:确认、
--initOrdAmt、--safetyOrdAmt、--maxSafetyOrds、--pxSteps--tpPct- 现货DCA:需要(
--triggerType=立即启动,1=RSI信号触发);默认2--type spot - 合约DCA:添加、
--type contract和--lever(--side=做多,buy=做空)sell
- 现货DCA:需要
- 停止网格:确认(默认省略→保留资产;
--stopType=全部卖出为计价资产)1 - 停止DCA:确认(默认
--stopType=卖出基础资产为计价资产;1=保留基础资产)2 - 演示试运行:当用户不确定时,建议使用
okx --demo bot grid create ...
Step 3: Verify After Writes
步骤3:写入操作后验证
- After grid create: run to confirm bot is active; then
okx bot grid ordersto monitor PnLokx bot grid details - After DCA create: run to confirm bot is active; then
okx bot dca ordersfor detailsokx bot dca details - After stop: run /
okx bot grid orders --historyto confirm bot is stoppedokx bot dca orders --history
- 创建网格后:运行确认机器人运行中;然后运行
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]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Instrument (e.g., |
| Yes | - | |
| Yes | - | Upper price boundary |
| Yes | - | Lower price boundary |
| Yes | - | Grid levels (2–100) |
| No | | |
| Cond. | - | USDT investment — spot grid only (provide |
| Cond. | - | Base currency investment — spot grid only |
| Cond. | - | |
| Cond. | - | Leverage (e.g., |
| 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]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 交易对(例如现货网格用 |
| 是 | - | |
| 是 | - | 价格上限 |
| 是 | - | 价格下限 |
| 是 | - | 网格数量(2-100) |
| 否 | | |
| 条件必填 | - | USDT投资金额 — 仅现货网格(提供 |
| 条件必填 | - | 基础货币投资金额 — 仅现货网格 |
| 条件必填 | - | |
| 条件必填 | - | 杠杆倍数(例如 |
| 条件必填 | - | 投资的合约张数 — 仅合约网格 |
Grid Bot — Stop
网格机器人 — 停止
bash
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
[--stopType <1|2|3|5|6>] [--json] | Behavior |
|---|---|
| Stop + sell/close all positions at market |
| Stop + keep current assets as-is (default) |
| Stop + close at limit prices |
| Stop + partial close |
| Stop without selling (smart arbitrage) |
bash
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
[--stopType <1|2|3|5|6>] [--json] | 行为 |
|---|---|
| 停止+市价卖出/平仓所有持仓 |
| 停止+保留现有资产(默认) |
| 停止+限价平仓 |
| 停止+部分平仓 |
| 停止不卖出(智能套利) |
Grid Bot — List Orders
网格机器人 — 列出订单
bash
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | |
| No | - | Filter by instrument |
| No | - | Filter by algo ID |
| No | false | Show completed/stopped bots instead of active |
bash
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | |
| 否 | - | 按交易对筛选 |
| 否 | - | 按算法ID筛选 |
| 否 | false | 展示已完成/已停止的机器人,而非运行中的 |
Grid Bot — Details
网格机器人 — 详情
bash
okx bot grid details --algoOrdType <type> --algoId <id> [--json]Returns: bot config, current PnL (), grid range, number of grids, state, position info.
pnlRatiobash
okx bot grid details --algoOrdType <type> --algoId <id> [--json]返回:机器人配置、当前盈亏()、网格区间、网格数量、状态、持仓信息。
pnlRatioGrid Bot — Sub-Orders
网格机器人 — 子订单
bash
okx bot grid sub-orders --algoOrdType <type> --algoId <id> [--live] [--json]| Flag | Effect |
|---|---|
| (default) | Filled sub-orders (executed grid trades) |
| Pending grid orders currently on the book |
bash
okx bot grid sub-orders --algoOrdType <type> --algoId <id> [--live] [--json]| 标识 | 效果 |
|---|---|
| (默认) | 已成交子订单(已执行的网格交易) |
| 挂单中的未结网格订单 |
DCA Bot — Create
DCA机器人 — 创建
bash
undefinedbash
undefinedSpot 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]
--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]
--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]
--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]
--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] | Behavior |
|---|---|
| Sell base currency to quote at market (cash out) — default |
| Keep base currency as-is |
bash
okx bot dca stop [--type <spot|contract>] --algoId <id> --instId <id> \
[--stopType <1|2>] [--json] | 行为 |
|---|---|
| 市价卖出基础资产兑换为计价资产(变现)—— 默认 |
| 保留基础资产不变 |
DCA Bot — List Orders
DCA机器人 — 列出订单
bash
okx bot dca orders [--type <spot|contract>] [--history] [--json]| Param | Required | Default | Description |
|---|---|---|---|
| No | | |
| No | false | Show completed/stopped bots instead of active |
bash
okx bot dca orders [--type <spot|contract>] [--history] [--json]| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 否 | | |
| 否 | false | 展示已完成/已停止的机器人,而非运行中的 |
DCA Bot — Details
DCA机器人 — 详情
bash
okx bot dca details [--type <spot|contract>] --algoId <id> [--json]Returns: bot config, current PnL (), safety orders triggered, state. Contract also returns , , .
pnlRatiodirectionleveravgPxbash
okx bot dca details [--type <spot|contract>] --algoId <id> [--json]返回:机器人配置、当前盈亏()、已触发安全订单数量、状态。合约类型还会返回、、。
pnlRatiodirectionleveravgPxDCA Bot — Sub-Orders
DCA机器人 — 子订单
bash
okx bot dca sub-orders [--type <spot|contract>] --algoId <id> [--live] [--cycleId <id>] [--json]| Flag / Param | Effect |
|---|---|
| (default, spot) | Filled sub-orders (executed DCA buys) |
| Spot: pending orders currently on the book |
| (default, contract) | List all cycles |
| Contract: show orders within a specific cycle |
bash
okx bot dca sub-orders [--type <spot|contract>] --algoId <id> [--live] [--cycleId <id>] [--json]| 标识/参数 | 效果 |
|---|---|
| (默认,现货) | 已成交子订单(已执行的DCA买入) |
| 现货:挂单中的未结订单 |
| (默认,合约) | 列出所有周期 |
| 合约:展示特定周期内的订单 |
MCP Tool Reference
MCP工具参考
CLI and MCP tools share the same underlying tool layer. MCP tools accept or directly.
type=spottype=contract| Tool | Description |
|---|---|
| Create spot or contract DCA bot |
| Stop spot or contract DCA bot |
| List spot or contract DCA bots |
| Single DCA bot details |
| Sub-orders (spot) or cycles (contract) |
CLI和MCP工具共享同一底层工具层。MCP工具可直接接受或参数。
type=spottype=contract| 工具 | 描述 |
|---|---|
| 创建现货或合约DCA机器人 |
| 停止现货或合约DCA机器人 |
| 列出现货或合约DCA机器人 |
| 获取单个DCA机器人详情 |
| 获取子订单(现货)或周期(合约) |
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 buyEdge Cases
边缘情况
Grid Bot
网格机器人
- Price out of range: must be < current price <
--minPx; check with--maxPxfirstokx-cex-market - Insufficient balance: check →
okx-cex-portfoliobefore creatingaccount balance - Contract grid direction: (buys more at lower prices),
long(sells at higher),short(both)neutral - Contract grid --sz: number of contracts, not USDT amount
- Stop type: sells/closes all;
stopType 1keeps assets;stopType 2for contract grid positionsstopType 5/6 - Already stopped bot: stop returns error — check first to confirm state
bot grid orders --history - Demo mode: — safe for testing, no real funds
okx --demo bot grid create ...
- 价格超出区间:必须 < 当前价格 <
--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-portfoliobefore creatingaccount balance - pxStepsMult: use for equal price spacing;
1.0to widen gaps between successive safety orders>1.0 - volMult: use for equal safety order sizes;
1.0to increase size per safety order (Martingale)>1.0 - triggerType 2 (RSI): requires additional RSI parameters — use (instant) unless specifically requested
1 - Stop type: sells base to quote (cash out);
stopType 1keeps base currency as-isstopType 2 - Already stopped bot: stop returns error — check first to confirm state
bot dca orders --history - Contract DCA: add to any DCA CLI command; create also requires
--type contractand--lever--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 or env vars
~/.okx/config.toml - switches between multiple accounts
--profile <name> - returns raw OKX API v5 response
--json - Rate limit: 20 requests per 2 seconds per UID for all bot operations
- Grid range: 2–100
--gridNum - DCA safety orders are triggered sequentially as price drops by increments
--pxSteps - Contract DCA automatically starts with an instant trigger (set by the tool internally)
- 网格和DCA机器人是OKX平台原生机器人 — 完全在OKX服务器上运行,关闭CLI不会影响它们
- 所有写入命令都需要或环境变量中存在有效凭证
~/.okx/config.toml - 可切换多个账户
--profile <name> - 返回原始OKX API v5响应
--json - 限流规则:所有机器人操作每个UID每2秒最多20次请求
- 网格范围:2-100
--gridNum - DCA安全订单会随着价格下跌的幅度依次触发
--pxSteps - 合约DCA默认立即触发启动(工具内部自动设置)