okx-cex-bot
OKX中央集権型取引所(CEX)の取引ボットに特化し、ユーザーがグリッド取引やその他の自動化戦略を開始する際にサポートを提供し、Web3市場での自動取引を実現します。
npx skills add okx/agent-skills --skill okx-cex-botBefore / After 効果比較
1 组手動でグリッド取引やDCA(ドルコスト平均法)投資を行う場合、長時間の市場監視と手動での注文が必要となり、感情に左右されやすく、複雑な取引戦略を正確に実行することが困難であるため、最適な取引機会を逃すことにつながります。
CLIコマンドを通じてOKX上のグリッド取引ボットとDCAボットを作成、起動、停止、監視することで、取引戦略の自動実行が実現されます。ボットは24時間365日中断することなく稼働し、市場の変動を正確に捉え、リスクを効果的に管理し、潜在的な取引収益を向上させることができます。
OKX CEX Bot Trading CLI
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.
Prerequisites
-
Install
okxCLI: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 setIf 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/orokx-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_passphraseSecurity: 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 -
Test with demo mode (simulated trading, no real funds):
okx --profile demo bot grid orders --algoOrdType grid
Credential & Profile Check
Run this check before any authenticated command.
Step A — Verify credentials
okx config show # verify configuration status (output is masked)
- If the command returns an error or shows no configuration: stop all operations, guide the user to run
okx config init, and wait for setup to complete before retrying. - If credentials are configured: proceed to Step B.
Step B — Confirm profile (required)
--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:
- Current message intent is clear (e.g. "real" / "实盘" / "live" →
live; "test" / "模拟" / "demo" →demo) → use it and inform the user:"Using --profile live (实盘)"or"Using --profile demo (模拟盘)" - Current message has no explicit declaration → check conversation context for a previous profile:
- Found → use it, inform user:
"Continuing with --profile live (实盘) from earlier" - Not found → ask:
"Live (实盘) or Demo (模拟盘)?"— wait for answer before proceeding
- Found → use it, inform user:
Handling 401 Authentication Errors
If 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:
Update the fields~/.okx/config.tomlapi_key,secret_key,passphraseunder the relevant profile. Do NOT paste the new credentials into chat. - After the user confirms the file is updated, run
okx config showto verify (output is masked) - Only then retry the original operation
Demo vs Live Mode
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:
--profileis required on every authenticated command — determined in "Credential & Profile Check" Step B- Every response after a command must append:
[profile: live]or[profile: demo] - Do not use the
--demoflag for mode switching — use--profileinstead - For bot create/stop operations (write commands), profile must be explicitly confirmed before execution
Example
User: "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]"
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)
Quickstart
# 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>
Command Index
Grid Bot
| # | Command | Type | Description |
|---|---|---|---|
| 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 |
DCA Bot (Contract Only)
| # | Command | Type | Description |
|---|---|---|---|
| 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 |
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
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
# 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
Contract DCA Bot (Long / Short)
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
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 → 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
Operation Flow
Step 0 — Credential & Profile Check
Before any authenticated command:
Determine profile (required):
- Options:
live(实盘) ordemo(模拟盘) — exactly these two values
- Current message intent clear (e.g. "real"/"实盘"/"live" → live; "test"/"模拟"/"demo" → demo) → use it, inform user:
"Using --profile live (实盘)" - Current message has no explicit declaration → check conversation context for previous profile:
- Found → use it, inform user:
"Continuing with --profile live (实盘) from earlier" - Not found → ask:
"Live (实盘) or Demo (模拟盘)?"— wait for answer
- Found → use it, inform user:
If 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
Critical: algoId and algoOrdType Rules
algoIdis the bot's algo order ID (returned bybot grid create/bot dca createor listed bybot grid orders/bot dca orders). It is NOT a normal trade order ID (ordId). Never fabricate or guess analgoId— always obtain it from a prior create or list command.algoOrdTypefor grid commands must match the bot's actual type. Always use thealgoOrdTypevalue from thebot grid ordersresponse — do not infer from user description alone. Passing a mismatched type (e.g.,contract_gridfor a spot grid bot) causes error50016.- When operating on an existing bot (details, sub-orders, stop), always retrieve the bot list first to get the correct
algoIdandalgoOrdTypepair, unless the user provides them explicitly.
Step 1: Identify Bot Type and Action
- 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(requires--leverand--direction) - DCA bot stop →
okx bot dca stop(only--algoIdneeded) - DCA bot status/P&L →
okx bot dca orders+okx bot dca details - DCA individual cycles/orders →
okx bot dca sub-orders
Step 2: Run Read Commands Immediately — Confirm Profile (Step 0) then Writes
Read commands (orders, details, sub-orders): run immediately.
--algoOrdTypefor grid → infer from context (gridfor spot,contract_gridfor perp)--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(investment margin in USDT);--basePosdefaults totrue(open base position for long/short)
- Spot grid:
- DCA create: confirm
--instId,--lever,--direction,--initOrdAmt,--safetyOrdAmt,--maxSafetyOrds,--pxSteps,--pxStepsMult,--volMult,--tpPct; optional:--slPct,--slMode,--allowReinvest,--triggerStrategy,--triggerPx - Grid stop: confirm
--stopType(default omitted → keep assets;1=sell all to quote) - DCA stop: only
--algoIdneeded - Demo dry-run: suggest
okx --profile demo bot grid create ...when user is unsure
⚠ 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:
- Transfer funds from funding account to trading account (specify amount)
- Reduce the investment size to fit available balance
- Cancel the bot creation
Step 3: Verify After Writes
- After grid create: run
okx bot grid ordersto confirm bot is active; thenokx bot grid detailsto monitor PnL - After DCA create: run
okx bot dca ordersto confirm bot is active; thenokx bot dca detailsfor details - After stop: run
okx bot grid orders --history/okx bot dca orders --historyto confirm bot is stopped
CLI Command Reference
Grid Bot — Create
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]
| 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 | Yes | - | Upper price boundary |
--minPx |
...
ユーザーレビュー (0)
レビューを書く
レビューなし
統計データ
ユーザー評価
この Skill を評価