okx-cex-bot by okx/agent-skills
npx skills add https://github.com/okx/agent-skills --skill okx-cex-bot在 OKX 交易所管理网格和 DCA(合约马丁格尔)交易机器人。本技能中的所有网格和 DCA 机器人均为原生的 OKX 平台机器人——它们在 OKX 服务器端运行,无需本地运行进程。需要 API 凭证。
安装 okx CLI:
npm install -g @okx_ai/okx-trade-cli
配置凭证 — 先检查,如果缺失再进行设置:
okx config show # 显示已配置的配置文件;如果已设置,api_key 会显示最后 4 个字符
如果凭证已配置 → 继续步骤 3。
如果未配置:
okx config init # 交互式向导 — 模拟盘模式(打开浏览器 → OKX 模拟 API 页面)
okx config init # 再次运行以设置实盘模式(创建第二个配置文件)
创建 okx-demo(模拟盘)和/或 okx-prod(实盘)配置文件。每次运行都会安全地合并到现有配置文件中,不会覆盖其他配置文件。
或者设置环境变量:
export OKX_API_KEY=your_key
export OKX_SECRET_KEY=your_secret
export OKX_PASSPHRASE=your_passphrase
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
安全提示:切勿在聊天中直接接收 API 凭证。如果用户粘贴了凭证,请警告他们,并要求他们运行
okx config init或使用本地编辑器手动编辑~/.okx/config.toml。凭证绝不能出现在对话历史记录中。
在配置文件之间切换:
okx config set default_profile okx-demo # 切换到模拟盘
okx config set default_profile okx-prod # 切换到实盘
okx --profile okx-prod bot grid orders --algoOrdType grid # 一次性覆盖
3. 使用模拟盘模式进行测试(模拟交易,无真实资金):
okx --profile demo bot grid orders --algoOrdType grid
在任何需要身份验证的命令之前运行此检查。
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 bot grid create ... # 实盘 — 真实资金
okx --profile demo bot grid create ... # 模拟盘 — 模拟资金
规则:
--profile — 在"凭证与配置文件检查"步骤 B 中确定[profile: live] 或 [profile: demo]--demo 标志进行模式切换 — 请使用 --profileUser: "Start a BTC grid bot"
Agent: "Live (实盘) or Demo (模拟盘)?"
User: "Demo"
Agent runs: okx --profile demo bot grid create --instId BTC-USDT --algoOrdType grid ...
Agent replies: "Grid bot created: 12345678 (OK) — simulated, no real funds used. [profile: demo]"
okx-cex-marketokx-cex-portfoliookx-cex-tradeokx-cex-bot(本技能)# 在 BTC 上创建现货网格机器人($90k–$100k,10 个网格,投入 1000 USDT)
okx bot grid create --instId BTC-USDT --algoOrdType grid \
--minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
# 在 BTC 永续合约上创建合约网格机器人(中性,5 倍杠杆,100 USDT 保证金)
# 对于做多/做空,basePos 默认为 true(开底仓);中性方向忽略此参数
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 orders --algoOrdType grid
# 获取网格机器人详情和盈亏
okx bot grid details --algoOrdType grid --algoId <algoId>
# 停止一个网格机器人(保持资产不变)
okx bot grid stop --algoId <algoId> --algoOrdType grid --instId BTC-USDT --stopType 2
# 在 BTC 永续合约上创建合约 DCA 机器人(做多,3 倍杠杆,3% 止盈)
okx bot dca create --instId BTC-USDT-SWAP --lever 3 --direction long \
--initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
# 列出所有活跃的合约 DCA 机器人
okx bot dca orders
# 获取 DCA 机器人详情
okx bot dca details --algoId <algoId>
# 停止一个 DCA 机器人
okx bot dca stop --algoId <algoId>
---|---|---|---
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 | 读取 | 单个网格成交或挂单
---|---|---|---
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 周期及周期内的订单
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 → 确认价格在范围内
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> → 监控盈亏
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 → 确认当前价格
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
# basePos 默认为 true(为做多/做空开底仓)
# 做空:--direction short;中性:--direction neutral
4. okx-cex-bot okx bot grid orders --algoOrdType contract_grid → 确认活跃
User: "Start a long DCA bot on BTC perp, 3x leverage, $200 initial, 3% TP"
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 --instId BTC-USDT-SWAP \
--lever 3 --direction long \
--initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
# 做空:--direction short
4. okx-cex-bot okx bot dca orders → 确认活跃
5. okx-cex-bot okx bot dca details --algoId <id> → 监控盈亏
User: "Show all my active bots and stop the ones losing money"
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 → 列出 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
在任何需要身份验证的命令之前:
确定配置文件(必需):
live(实盘)或 demo(模拟盘)— 恰好这两个值"Using --profile live (实盘)""Continuing with --profile live (实盘) from earlier""Live (实盘) or Demo (模拟盘)?" — 等待回答如果未配置凭证: 引导用户运行 okx config init,停止所有交易操作
每个命令结果之后: 在响应中附加 [profile: live] 或 [profile: demo]
algoId 和 algoOrdType 规则algoId 是机器人的算法订单 ID(由 bot grid create / bot dca create 返回或由 bot grid orders / bot dca orders 列出)。它不是普通的交易订单 ID(ordId)。切勿伪造或猜测 algoId — 始终从之前的创建或列表命令中获取。algoOrdType 必须与机器人的实际类型匹配。始终使用 bot grid orders 响应中的 algoOrdType 值 — 不要仅从用户描述推断。传递不匹配的类型(例如,为现货网格机器人使用 contract_grid)会导致错误 50016。algoId 和 algoOrdType 对,除非用户明确提供了它们。okx bot grid createokx bot grid stopokx bot grid orders + okx bot grid detailsokx bot grid sub-ordersokx bot dca create(需要 --lever 和 --direction)okx bot dca stop(仅需 --algoId)okx bot dca orders + okx bot dca detailsokx bot dca sub-orders读取命令(orders, details, sub-orders):立即运行。
--algoOrdType → 根据上下文推断(现货用 grid,永续用 contract_grid)--history → 使用默认值(活跃);仅在明确请求时查询历史写入命令(create, stop):在执行前确认一次。
--minPx、--maxPx、--gridNum;验证 --minPx < 当前价格 < --maxPx;确认投资金额
--quoteSz(USDT)或 --baseSz(基础货币)--direction(long/short/neutral)、--lever、--sz(保证金,以 USDT 计);--basePos 默认为 true(为做多/做空开底仓)--instId、--lever、--direction、--initOrdAmt、--safetyOrdAmt、--maxSafetyOrds、--pxSteps、--pxStepsMult、--volMult、--tpPct;可选:--slPct、--slMode、、、--stopType(默认省略 → 保持资产;1=全部卖出转换为计价货币)--algoIdokx --profile demo bot grid create ...⚠ 余额不足 — 切勿自动划转资金。 如果交易账户余额不足以创建机器人,请不要自动发起资金划转(account_transfer)。相反,告知用户差额(当前可用金额 vs. 所需金额)并询问他们希望如何继续。建议提供以下选项:
okx bot grid orders 确认机器人活跃;然后运行 okx bot grid details 监控盈亏okx bot dca orders 确认机器人活跃;然后运行 okx bot dca details 获取详情okx bot grid orders --history / okx bot dca orders --history 确认机器人已停止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>] \
[--basePos] [--no-basePos] \
[--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 | 条件 | - | 保证金投资金额(USDT)— 仅限合约网格 |
--basePos / --no-basePos | 否 | true | 创建时开底仓 — 仅限合约网格(中性方向忽略此参数)。默认为 true(开底仓)。使用 --no-basePos 禁用。 |
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
[--stopType <1|2|3|5|6>] [--json]
--algoId和--algoOrdType必须来自bot grid orders的输出。algoOrdType必须与机器人的实际类型匹配 — 不要猜测。
--stopType | 行为 |
|---|---|
1 | 停止 + 以市价卖出/平仓所有持仓 |
2 | 停止 + 保持当前资产不变(默认) |
3 | 停止 + 以限价平仓 |
5 | 停止 + 部分平仓 |
6 | 停止但不卖出(智能套利) |
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]
| 参数 | 必需 | 默认值 | 描述 |
|---|---|---|---|
--algoOrdType | 是 | - | grid(现货)、contract_grid(合约)或 moon_grid(月亮) |
--instId | 否 | - | 按交易品种过滤 |
--algoId | 否 | - | 按算法订单 ID 过滤(由创建或之前的列表返回)。不是普通的交易订单 ID。 |
--history | 否 | false | 显示已完成/已停止的机器人,而不是活跃的 |
okx bot grid details --algoOrdType <type> --algoId <id> [--json]
--algoId和--algoOrdType必须来自bot grid orders的输出。algoOrdType必须与机器人的实际类型匹配。
返回:机器人配置、当前盈亏(pnlRatio)、网格范围、网格数量、状态、持仓信息。
okx bot grid sub-orders --algoOrdType <type> --algoId <id> [--live] [--json]
--algoId和--algoOrdType必须来自bot grid orders的输出。
| 标志 | 效果 |
|---|---|
| (默认) | 已成交的子订单(已执行的网格交易) |
--live | 当前挂单簿上的待处理网格订单 |
okx bot dca create --instId <id> --lever <n> --direction <long|short> \
--initOrdAmt <n> --safetyOrdAmt <n> --maxSafetyOrds <n> \
--pxSteps <ratio> --pxStepsMult <mult> --volMult <mult> --tpPct <ratio> \
[--slPct <ratio>] [--slMode <limit|market>] [--allowReinvest <true|false>] \
[--triggerStrategy <instant|price|rsi>] [--triggerPx <price>] [--json]
| 参数 | 必需 | 默认值 | 描述 |
|---|---|---|---|
--instId | 是 | - | 交易品种(例如 BTC-USDT-SWAP) |
--lever | 是 | - | 杠杆倍数(例如 3) |
--direction | 是 | - | long 或 short |
--initOrdAmt | 是 | - | 首单保证金(计价货币) |
--maxSafetyOrds | 是 | - | 最大补仓次数(例如 3;0 = 无 DCA) |
--safetyOrdAmt | 是 | - | 补仓保证金(计价货币) |
--pxSteps | 是 | - | 初始价格偏离百分比(例如 0.03 = 3%) |
--pxStepsMult | 是 | - | 补仓之间的价格步长倍数(例如 1.2) |
--volMult | 是 | - | 补仓金额倍数(例如 1.5) |
--tpPct | 是 | - | 止盈比例(例如 0.03 = 3%) |
--slPct | 否 | - | 止损比例(例如 0.05 = 5%) |
--slMode | 否 | market | 止损价格类型:limit(限价)或 market(市价) |
--allowReinvest | 否 | true | 将利润再投入下一个 DCA 周期 |
--triggerStrategy | 否 | instant | 机器人启动方式:instant(立即)、price(等待触发价格)或 rsi(RSI 信号) |
--triggerPx | 否 | - | 触发价格 — 当 triggerStrategy=price 时必需 |
okx bot dca stop --algoId <id> [--json]
| 参数 | 必需 | 描述 |
|---|---|---|
--algoId | 是 | DCA 机器人算法订单 ID(来自 bot dca orders 或 bot dca create 的输出)。不是普通的交易订单 ID。 |
okx bot dca orders [--algoId <id>] [--instId <id>] [--history] [--json]
| 参数 | 必需 | 默认值 | 描述 |
|---|---|---|---|
--algoId | 否 | - | 按 DCA 机器人算法订单 ID 过滤(来自创建或之前的列表)。不是普通的交易订单 ID。 |
--instId | 否 | - | 按交易品种过滤,例如 BTC-USDT-SWAP |
--history | 否 | false | 显示已完成/已停止的机器人,而不是活跃的 |
okx bot dca details --algoId <id> [--json]
--algoId必须来自bot dca orders或bot dca create的输出。不是普通的交易订单 ID。
返回:持仓详情,包括 avgPx、upl、liqPx、sz、tpPx、slPx、initPx、fundingFee、fee、fillSafetyOrds。
okx bot dca sub-orders --algoId <id> [--cycleId <id>] [--json]
--algoId必须来自bot dca orders或bot dca create的输出。
| 标志 / 参数 | 效果 |
|---|---|
| (默认) | 列出所有周期 |
--cycleId <id> | 显示特定周期内的订单 |
CLI 和 MCP 工具共享相同的底层工具层。所有 DCA 工具仅操作合约 DCA。
| 工具 | 描述 |
|---|---|
dca_create_order | 创建合约 DCA 机器人 |
dca_stop_order | 停止合约 DCA 机器人 |
dca_get_orders | 列出合约 DCA 机器人 |
dca_get_order_details | 单个合约 DCA 机器人详情 |
dca_get_sub_orders | 合约 DCA 周期及周期内的订单 |
"Start a BTC grid bot from $90k to $100k with 10 grids"
okx bot grid create --instId BTC-USDT --algoOrdType grid \
--minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
# → Grid bot created: 12345678 (OK)
"Show all my active grid bots"
okx bot grid orders --algoOrdType grid
"What's the P &L on my BTC grid bot?"
okx bot grid details --algoOrdType grid --algoId 12345678
# → pnlRatio, pnl, investAmt, totalAnnRate, runType, gridNum, maxPx, minPx
"Stop my BTC grid bot and keep the assets"
okx bot grid stop --algoId 12345678 --algoOrdType grid --instId BTC-USDT --stopType 2
"Create a DCA bot on BTC perp, long, 3x leverage, 3% TP"
okx bot dca create --instId BTC-USDT-SWAP --lever 3 --direction long \
--initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
# → DCA bot created: 87654321 (OK)
"Create a DCA bot with safety orders and stop-loss"
okx bot dca create --instId BTC-USDT-SWAP --lever 3 --direction long \
--initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 \
--tpPct 0.03 --slPct 0.15 --slMode market
"Show my active DCA bots"
okx bot dca orders
"How is my BTC DCA bot doing?"
okx bot dca details --algoId 87654321
# → avgPx, upl, liqPx, sz, tpPx, slPx, fillSafetyOrds
"Stop my BTC DCA bot"
okx bot dca stop --algoId 87654321
--minPx 必须 < 当前价格 < --maxPx;首先使用 okx-cex-market 检查okx-cex-portfolio → account balance。如果不足,切勿自动划转 — 报告差额并询问用户指示(见步骤 2)long(在较低价格买入更多)、short(在较高价格卖出)、neutral(双向)true — 做多/做空网格在创建时自动开底仓。中性方向忽略此参数。传递 --no-basePos 来禁用。stopType 1 卖出/平仓所有;stopType 2 保持资产;stopType 5/6 用于合约网格持仓bot grid orders --history 以确认状态okx --profile demo bot grid create ... — 安全测试,无真实资金BTC-USDT-SWAP)。现货 DCA 不可用。okx-cex-portfolio → account balance。如果不足,切勿自动划转 — 报告差额并询问用户指示(见步骤 2)1.0 表示等距价格步长;>1.0 表示扩大连续补仓之间的价格差距1.0 表示等额补仓;>1.0 表示每次补仓增加金额(马丁格尔)instant(默认)立即开始;price 等待触发价格;rsi 使用 RSI 信号--algoId — 不需要 instId 或 stopTypebot dca orders --history 以确认状态--instId、--lever、--direction(long/short)、--initOrdAmt、--safetyOrdAmt、--maxSafetyOrds、--pxSteps、--pxStepsMult、--volMult、--tpPct与用户沟通时,使用显示名称而非原始 API 字段名。API 字段仅用于内部映射。
货币占位符:
{base}和{quote}指代交易对中的实际货币。通过将instId按-分割来提取:对于BTC-USDT-SWAP→ base=BTC, quote=USDT(忽略 SWAP 后缀);对于ETH-USDT-SWAP→ base=ETH, quote=USDT。
algoOrdType=grid)| API 字段 | 显示名称(英文) | 显示名称(中文) |
|---|---|---|
instId | Trading pair | 交易对 |
minPx | Lower price bound | 网格下限价格 |
maxPx | Upper price bound | 网格上限价格 |
gridNum | Number of grids | 网格数量 |
quoteSz | Investment amount ({quote}) | 投入金额({quote}) |
baseSz | Investment amount ({base}) | 投入金额({base}) |
runType | Spacing mode |
Grid and DCA (Contract 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.
Install okx CLI:
npm install -g @okx_ai/okx-trade-cli
Configure credentials — check first, then set up if missing :
okx config show # shows configured profiles; api_key shows last 4 chars if set
If credentials are already configured → proceed to step 3.
If not configured :
okx config init # interactive wizard — demo mode (opens browser → OKX demo API page)
okx config init # run again for live mode (creates a second profile)
Creates okx-demo (demo) and/or okx-prod (live) profiles. Each run safely merges into the existing config file without overwriting other profiles.
Or set environment variables:
export OKX_API_KEY=your_key
export OKX_SECRET_KEY=your_secret
export OKX_PASSPHRASE=your_passphrase
Security : NEVER accept API credentials directly in chat. If the user pastes credentials, warn them and ask them to run
okx config initor edit~/.okx/config.tomlmanually with their local editor instead. Credentials must never appear in conversation history.
Switch between profiles :
okx config set default_profile okx-demo # switch to demo
okx config set default_profile okx-prod # switch to live
okx --profile okx-prod bot grid orders --algoOrdType grid # one-off override
3. Test with demo mode (simulated trading, no real funds):
okx --profile demo bot grid orders --algoOrdType grid
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 — bot operates with real money |
demo | 模拟盘 | Simulated — safe for testing bot configurations |
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 funds — bot operates with real money |
demo | 模拟盘 | Simulated — no real funds |
okx --profile live bot grid create ... # 实盘 — real funds
okx --profile demo bot grid create ... # 模拟盘 — 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: "Start a BTC grid bot"
Agent: "Live (实盘) or Demo (模拟盘)?"
User: "Demo"
Agent runs: okx --profile demo bot grid create --instId BTC-USDT --algoOrdType grid ...
Agent replies: "Grid bot created: 12345678 (OK) — simulated, no real funds used. [profile: demo]"
okx-cex-marketokx-cex-portfoliookx-cex-tradeokx-cex-bot (this skill)# Create a spot grid bot on BTC ($90k–$100k, 10 grids, invest 1000 USDT)
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 USDT margin)
# basePos defaults to true for long/short (opens base position); neutral ignores it
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
# Get grid bot details and P&L
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
# Create a contract DCA bot on BTC perp (long, 3x leverage, 3% TP)
okx bot dca create --instId BTC-USDT-SWAP --lever 3 --direction long \
--initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
# List all active contract DCA bots
okx bot dca orders
# Get DCA bot details
okx bot dca details --algoId <algoId>
# Stop a DCA bot
okx bot dca stop --algoId <algoId>
---|---|---|---
1 | okx bot grid create | WRITE | Create a grid bot
2 | okx bot grid stop | WRITE | Stop a grid bot
3 | okx bot grid orders | READ | List active or history grid bots
4 | okx bot grid details | READ | Single grid bot details + PnL
5 | okx bot grid sub-orders | READ | Individual grid fills or live orders
---|---|---|---
6 | okx bot dca create | WRITE | Create a Contract DCA bot
7 | okx bot dca stop | WRITE | Stop a Contract DCA bot
8 | okx bot dca orders | READ | List active or history Contract DCA bots
9 | okx bot dca details | READ | Single Contract DCA bot details + PnL
10 | okx bot dca sub-orders | READ | Contract DCA cycles and orders within a cycle
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
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
# basePos defaults to true (opens base position for long/short)
# For short: --direction short; for neutral: --direction neutral
4. okx-cex-bot okx bot grid orders --algoOrdType contract_grid → confirm active
User: "Start a long 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 --instId BTC-USDT-SWAP \
--lever 3 --direction long \
--initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
# For short: --direction short
4. okx-cex-bot okx bot dca orders → confirm active
5. okx-cex-bot okx bot dca details --algoId <id> → monitor PnL
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 → 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
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
algoId and algoOrdType RulesalgoId is the bot's algo order ID (returned by bot grid create / bot dca create or listed by bot grid orders / bot dca orders). It is NOT a normal trade order ID (ordId). Never fabricate or guess an algoId — always obtain it from a prior create or list command.algoOrdType for grid commands must match the bot's actual type. Always use the algoOrdType value from the bot grid orders response — do not infer from user description alone. Passing a mismatched type (e.g., for a spot grid bot) causes error .okx bot grid createokx bot grid stopokx bot grid orders + okx bot grid detailsokx bot grid sub-ordersokx bot dca create (requires --lever and --direction)okx bot dca stop (only --algoId needed)Read commands (orders, details, sub-orders): run immediately.
--algoOrdType for grid → infer from context (grid for spot, contract_grid for perp)--history → use default (active); only query history if explicitly requestedWrite commands (create, stop): confirm once before executing.
--minPx, --maxPx, --gridNum; verify --minPx < current price < --maxPx; confirm investment size
--quoteSz (USDT) or --baseSz (base currency)--direction (long/short/neutral), , (investment margin in USDT); defaults to (open base position for long/short)⚠ Insufficient balance — NEVER auto-transfer funds. If the trading account balance is insufficient to create a bot, do NOT automatically initiate a fund transfer (account_transfer). Instead, inform the user of the shortfall (current available vs. required amount) and ask how they want to proceed. Suggested options to present:
okx bot grid orders to confirm bot is active; then okx bot grid details to monitor PnLokx bot dca orders to confirm bot is active; then okx bot dca details for detailsokx bot grid orders --history / okx bot dca orders --history to confirm bot is stoppedokx 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>] \
[--basePos] [--no-basePos] \
[--json]
| Param | Required | Default | Description |
|---|---|---|---|
--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 |
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
[--stopType <1|2|3|5|6>] [--json]
--algoIdand--algoOrdTypemust come frombot grid ordersoutput. ThealgoOrdTypemust match the bot's actual type — do not guess.
--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) |
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--algoOrdType | Yes | - | grid (spot), contract_grid (contract), or moon_grid (moon) |
--instId | No | - | Filter by instrument |
--algoId | No | - |
okx bot grid details --algoOrdType <type> --algoId <id> [--json]
--algoIdand--algoOrdTypemust come frombot grid ordersoutput. ThealgoOrdTypemust match the bot's actual type.
Returns: bot config, current PnL (pnlRatio), grid range, number of grids, state, position info.
okx bot grid sub-orders --algoOrdType <type> --algoId <id> [--live] [--json]
--algoIdand--algoOrdTypemust come frombot grid ordersoutput.
| Flag | Effect |
|---|---|
| (default) | Filled sub-orders (executed grid trades) |
--live | Pending grid orders currently on the book |
okx bot dca create --instId <id> --lever <n> --direction <long|short> \
--initOrdAmt <n> --safetyOrdAmt <n> --maxSafetyOrds <n> \
--pxSteps <ratio> --pxStepsMult <mult> --volMult <mult> --tpPct <ratio> \
[--slPct <ratio>] [--slMode <limit|market>] [--allowReinvest <true|false>] \
[--triggerStrategy <instant|price|rsi>] [--triggerPx <price>] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--instId | Yes | - | Instrument (e.g., BTC-USDT-SWAP) |
--lever | Yes | - | Leverage multiplier (e.g., 3) |
--direction | Yes | - | long or |
okx bot dca stop --algoId <id> [--json]
| Param | Required | Description |
|---|---|---|
--algoId | Yes | DCA bot algo order ID (from bot dca orders or bot dca create output). NOT a normal trade order ID. |
okx bot dca orders [--algoId <id>] [--instId <id>] [--history] [--json]
| Param | Required | Default | Description |
|---|---|---|---|
--algoId | No | - | Filter by DCA bot algo order ID (from create or previous list). NOT a normal trade order ID. |
--instId | No | - | Filter by instrument, e.g. BTC-USDT-SWAP |
--history | No | false | Show completed/stopped bots instead of active |
okx bot dca details --algoId <id> [--json]
--algoIdmust come frombot dca ordersorbot dca createoutput. NOT a normal trade order ID.
Returns: position details including avgPx, upl, liqPx, sz, tpPx, slPx, initPx, fundingFee, fee, fillSafetyOrds.
okx bot dca sub-orders --algoId <id> [--cycleId <id>] [--json]
--algoIdmust come frombot dca ordersorbot dca createoutput.
| Flag / Param | Effect |
|---|---|
| (default) | List all cycles |
--cycleId <id> | Show orders within a specific cycle |
CLI and MCP tools share the same underlying tool layer. All DCA tools operate on contract DCA only.
| Tool | Description |
|---|---|
dca_create_order | Create a Contract DCA bot |
dca_stop_order | Stop a Contract DCA bot |
dca_get_orders | List Contract DCA bots |
dca_get_order_details | Single Contract DCA bot details |
dca_get_sub_orders | Contract DCA cycles and orders within a cycle |
"Start a BTC grid bot from $90k to $100k with 10 grids"
okx bot grid create --instId BTC-USDT --algoOrdType grid \
--minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000
# → Grid bot created: 12345678 (OK)
"Show all my active grid bots"
okx bot grid orders --algoOrdType grid
"What's the P &L on my BTC grid bot?"
okx bot grid details --algoOrdType grid --algoId 12345678
# → pnlRatio, pnl, investAmt, totalAnnRate, runType, gridNum, maxPx, minPx
"Stop my BTC grid bot and keep the assets"
okx bot grid stop --algoId 12345678 --algoOrdType grid --instId BTC-USDT --stopType 2
"Create a DCA bot on BTC perp, long, 3x leverage, 3% TP"
okx bot dca create --instId BTC-USDT-SWAP --lever 3 --direction long \
--initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
# → DCA bot created: 87654321 (OK)
"Create a DCA bot with safety orders and stop-loss"
okx bot dca create --instId BTC-USDT-SWAP --lever 3 --direction long \
--initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
--pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 \
--tpPct 0.03 --slPct 0.15 --slMode market
"Show my active DCA bots"
okx bot dca orders
"How is my BTC DCA bot doing?"
okx bot dca details --algoId 87654321
# → avgPx, upl, liqPx, sz, tpPx, slPx, fillSafetyOrds
"Stop my BTC DCA bot"
okx bot dca stop --algoId 87654321
--minPx must be < current price < --maxPx; check with okx-cex-market firstokx-cex-portfolio → account balance before creating. If insufficient, do NOT auto-transfer — report the shortfall and ask the user for instructions (see Step 2)long (buys more at lower prices), short (sells at higher), neutral (both)true — long/short grids automatically open a base position at creation. Neutral direction ignores this. Pass to disable.BTC-USDT-SWAP). Spot DCA is not available.okx-cex-portfolio → account balance before creating. If insufficient, do NOT auto-transfer — report the shortfall and ask the user for instructions (see Step 2)1.0 for equal price spacing; >1.0 to widen gaps between successive safety orders1.0 for equal safety order sizes; >1.0 to increase size per safety order (Martingale)instant (default) starts immediately; waits for a trigger price; uses RSI signalsWhen communicating with users, use the display name instead of the raw API field name. The API field is for internal mapping only.
Currency placeholders :
{base}and{quote}refer to the actual currencies from the trading pair. Extract them by splittinginstIdon-: forBTC-USDT-SWAP→ base=BTC, quote=USDT (ignore the SWAP suffix); forETH-USDT-SWAP→ base=ETH, quote=USDT.
algoOrdType=grid)| API Field | Display Name (EN) | Display Name (ZH) |
|---|---|---|
instId | Trading pair | 交易对 |
minPx | Lower price bound | 网格下限价格 |
maxPx | Upper price bound | 网格上限价格 |
gridNum | Number of grids | 网格数量 |
quoteSz | Investment amount ({quote}) | 投入金额({quote}) |
algoOrdType=contract_grid)| API Field | Display Name (EN) | Display Name (ZH) |
|---|---|---|
instId | Trading pair | 交易对 |
minPx | Lower price bound | 网格下限价格 |
maxPx | Upper price bound | 网格上限价格 |
gridNum | Number of grids | 网格数量 |
sz | Investment margin ({quote}) | 投入保证金({quote}) |
| API Field | Display Name (EN) | Display Name (ZH) |
|---|---|---|
instId | Trading pair | 交易对 |
initOrdAmt | Initial margin ({quote}) | 首单保证金({quote}) |
safetyOrdAmt | Safety order margin ({quote}) | 补仓保证金({quote}) |
maxSafetyOrds | Max safety orders | 最大补仓次数 |
pxSteps | Price drop per safety order (%) |
slPctstop-loss logic (contract DCA):
- Long (
direction=long): stop-loss price = initial order fill price × (1 − slPct)- Short (
direction=short): stop-loss price = initial order fill price × (1 + slPct)
When the stop-loss price is triggered and the position is fully closed, the bot ends.
When collecting parameters from the user, always use natural language — never expose raw API field names.
If the user already provides values in their initial request, do not re-ask — map them directly to the corresponding API fields.
~/.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 response--gridNum range: 2–100--pxSteps increments--triggerStrategy)Weekly Installs
962
Repository
GitHub Stars
40
First Seen
Mar 8, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode956
codex955
gemini-cli947
kimi-cli946
github-copilot946
amp946
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
59,200 周安装
--allowReinvest--triggerStrategy--triggerPxcontract_grid50016algoId and algoOrdType pair, unless the user provides them explicitly.okx bot dca orders + okx bot dca detailsokx bot dca sub-orders--lever--sz--basePostrue--instId, --lever, --direction, --initOrdAmt, --safetyOrdAmt, --maxSafetyOrds, --pxSteps, --pxStepsMult, --volMult, --tpPct; optional: --slPct, --slMode, --allowReinvest, --triggerStrategy, --triggerPx--stopType (default omitted → keep assets; 1=sell all to quote)--algoId neededokx --profile demo bot grid create ... when user is unsure| 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. | - | Investment margin in USDT — contract grid only |
--basePos / --no-basePos | No | true | Open a base position at creation — contract grid only (ignored for neutral direction). Default is true (opens base position). Use --no-basePos to disable. |
| Filter by algo order ID (returned by create or previous list). NOT a normal trade order ID. |
--history | No | false | Show completed/stopped bots instead of active |
short--initOrdAmt | Yes | - | Initial order margin (quote currency) |
--maxSafetyOrds | Yes | - | Max number of safety orders (e.g., 3; 0 = no DCA) |
--safetyOrdAmt | Yes | - | Safety order margin (quote currency) |
--pxSteps | Yes | - | Initial price deviation percentage (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%) |
--slMode | No | market | Stop-loss price type: limit (limit price) or market (market price) |
--allowReinvest | No | true | Reinvest profit into the next DCA cycle |
--triggerStrategy | No | instant | How the bot starts: instant, price (wait for trigger price), or rsi (RSI signal) |
--triggerPx | No | - | Trigger price — required when triggerStrategy=price |
--no-basePosstopType 1 sells/closes all; stopType 2 keeps assets; stopType 5/6 for contract grid positionsbot grid orders --history first to confirm stateokx --profile demo bot grid create ... — safe for testing, no real fundspricersi--algoId is needed — no instId or stopType requiredbot dca orders --history first to confirm state--instId, --lever, --direction (long/short), --initOrdAmt, --safetyOrdAmt, --maxSafetyOrds, --pxSteps, --pxStepsMult, --volMult, --tpPctbaseSz | Investment amount ({base}) | 投入金额({base}) |
runType | Spacing mode (1=arithmetic, 2=geometric) | 网格间距模式(1=等差, 2=等比) |
stopType | Stop behavior | 停止方式 |
direction | Direction (long / short / neutral) | 方向(做多 / 做空 / 中性) |
lever | Leverage | 杠杆倍数 |
runType | Spacing mode (1=arithmetic, 2=geometric) | 网格间距模式(1=等差, 2=等比) |
basePos | Open base position | 是否开底仓 |
stopType | Stop behavior | 停止方式 |
| 补仓价格跌幅(%) |
pxStepsMult | Price step multiplier | 补仓跌幅倍数 |
volMult | Safety order size multiplier | 补仓金额倍数 |
tpPct | Take-profit ratio (%) | 止盈比例(%) |
slPct | Stop-loss ratio (%) | 止损比例(%) |
slMode | Stop-loss type (limit / market) | 止损类型(限价 / 市价) |
lever | Leverage | 杠杆倍数 |
direction | Direction (long / short) | 方向(做多 / 做空) |
allowReinvest | Reinvest profit into next cycle | 利润再投入下一轮 |
triggerStrategy | Trigger mode (instant / price / rsi) | 触发方式(立即 / 价格 / RSI) |
triggerPx | Trigger price (for price mode) | 触发价格(价格模式时) |