
This lets Claude create and manage OKX's native server-side trading bots without you needing to run anything locally. It handles both grid bots (spot and contract, including coin-margined) and DCA Martingale strategies across spot and futures markets. The skill enforces a two-step auth check before every command to distinguish between API key and OAuth modes, then applies the right flags for live versus demo trading. Notable that it never auto-transfers funds when balance is insufficient, instead it reports the shortfall and asks you to decide. Commands cover the full lifecycle: create with AI-suggested parameters, amend price ranges or take-profit levels on running bots, stop execution, and monitor P&L and individual fills.
$ npx -y skills add okx/agent-skills --skill okx-cex-bot --agent claude-codeInstalls into .claude/skills of the current project.
Grid and DCA (Spot & Contract Martingale) bot management on OKX. All bots are native OKX server-side — they run on OKX and do not require a local process.
Before running any command, follow ../_shared/preflight.md.
Use metadata.version from this file's frontmatter as the reference for Step 2.
npm install -g @okx_ai/okx-trade-cli
okx config init # select site -> follow browser OAuth flow
Security: NEVER accept credentials in chat. Guide users to
okx config initfor setup.
Run before every authenticated command. The auth method is detected during preflight Step 2 and remembered for the session.
Run both commands — the apiKey field from okx auth status --json is the auth-binary's internal state and is always false regardless of whether ~/.okx/config.toml has an API-key profile. okx config show --json is the only authoritative source for API-key presence.
okx config show --json # reveals API-key profiles (TOML config)
okx auth status --json # reveals OAuth session state (auth-binary state)
Apply in this order — first match wins:
config show --json has any profile with a non-empty api_key field → API Key mode. Proceed to Step B.auth status --json returns "status":"logged_in" → OAuth mode. Proceed to Step B."status":"pending" — login is in progress, wait for it to complete."status":"not_logged_in" — stop, load okx-cex-auth skill and follow login steps, wait for completion.Resolution:
How to apply the mode depends on auth method (detected in Step A):
| Auth method | Live (实盘) | Demo (模拟盘) |
|---|---|---|
| API Key | --profile <live-profile> | --profile <demo-profile> |
| OAuth | (no flag needed, live is default) | --demo |
okx config show --json to discover available profile names and their demo settings.--demo for simulated trading.After every command: append [mode: live] or [mode: demo]
Authentication error (error contains "401", "Session expired", or "Run okx auth login first"):
okx-cex-auth skill and follow re-authentication steps| Need | Skill |
|---|---|
| Market data, prices, depth | okx-cex-market |
| Account balance, positions, fees | okx-cex-portfolio |
| Regular spot/swap/futures orders | okx-cex-trade |
| Grid / DCA bots | okx-cex-bot (this skill) |
| Command | Type | Description |
|---|---|---|
okx bot grid create | WRITE | Create a grid bot (spot or contract) |
okx bot grid amend | WRITE | Amend price range, grid count, or TP/SL of a running grid bot |
okx bot grid stop | WRITE | Stop a grid bot |
okx bot grid positions | READ | Query open contract-grid positions (liquidation price, margin ratio, unrealized PnL) |
okx bot grid liquidate-price | READ | Estimate liquidation price for a contract-grid bot |
okx bot grid close-position | WRITE | Close remaining position after bot stopped with stopType=2 |
okx bot grid orders | READ | List active or history grid bots |
okx bot grid details | READ | Grid bot details + PnL |
okx bot grid sub-orders | READ | Individual grid fills or pending orders |
| Command | Type | Description |
|---|---|---|
okx bot dca create | WRITE | Create a DCA (Martingale) bot (spot or contract) |
okx bot dca stop | WRITE | Stop a DCA bot (spot or contract) |
okx bot dca orders | READ | List active or history DCA bots (default: contract_dca) |
okx bot dca positions | READ | DCA bot position info (avgPx, upl, liqPx, ...) |
okx bot dca details | READ | Deprecated - use okx bot dca positions (same endpoint) |
okx bot dca sub-orders | READ | DCA cycles and orders within a cycle |
okx bot dca add-margin | WRITE | Add margin to a running contract DCA bot |
okx bot dca reduce-margin | WRITE | Reduce margin on a running contract DCA bot |
okx bot dca update-tp | WRITE | Update take-profit price on a running contract DCA bot |
Note: Load with
--modules bot.smartportfolioorbot.all(not in default modules).
| Command | Type | Description |
|---|---|---|
okx bot smart-portfolio create | WRITE | Create a Smart Portfolio bot (2–10 assets, ratios summing to 1.0, deltaRatio threshold) |
okx bot smart-portfolio stop | WRITE | Stop a running Smart Portfolio bot |
okx bot smart-portfolio orders | READ | List Smart Portfolio bots (default: running; add --history for stopped) |
okx bot smart-portfolio details | READ | Get Smart Portfolio bot details and current allocation |
okx bot smart-portfolio amend-rebalance | WRITE | Update rebalance threshold and interval (both --deltaRatio and --interval required) |
okx bot smart-portfolio instant-rebalance | WRITE | Trigger an immediate rebalance |
okx bot smart-portfolio recommend-zones | READ | Browse OKX-recommended portfolio zone configurations |
okx bot smart-portfolio zones-backtest | READ | Get historical backtest results for a recommended zone |
Parse user request → determine module (Grid / DCA / Smart Portfolio) and action (create / stop / list / details).
READ commands (orders, details, sub-orders): run immediately after profile confirmation.
WRITE commands (create, amend, stop): confirm key parameters with user once before executing.
orders command to confirm activedetails --algoId <id> to confirm updated configorders --history to confirm stoppedsmart-portfolio orders --history to confirm stoppedalgoId is the bot's algo order ID (from create or list output). It is NOT a normal ordId. Never fabricate — always obtain from a prior command.algoOrdType for grid must match the bot's actual type. Always use the value from bot grid orders — do not infer from user description alone. Mismatch causes error 50016.tpTriggerPx/tpRatio and slTriggerPx/slRatio are mutually exclusive pairs.For Grid Bot command syntax, parameter tables, Quickstart examples, and edge cases,
read {baseDir}/references/grid-commands.md.
For DCA Bot command syntax, parameter tables, Quickstart examples, and edge cases,
read {baseDir}/references/dca-commands.md.
For Smart Portfolio Bot command syntax, parameter tables, and examples,
read {baseDir}/references/smart-portfolio-commands.md.
For cross-skill workflow examples (chaining okx-cex-market/okx-cex-portfolio with bot
creation), read {baseDir}/references/workflows.md.
{base}and{quote}: extract frominstIdby splitting on-. E.g.,BTC-USDT-SWAP→ base=BTC, quote=USDT.
--json returns the raw OKX API v5 response by default. Add --env to wrap the output as {"env": "<live|demo>", "profile": "<name>", "data": <response>}--gridNum range: 2–100Sponsors