dex-original/okx-agent-trade-kit/okx-cex-bot

Claude Code and agent skill by dex-original/okx-agent-trade-kit

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Manage Grid bots (spot/contract/coin-margined) and DCA Martingale bots (Spot DCA 现货马丁 / Contract DCA 合约马丁) on OKX. Covers create, stop, amend, monitor P&L, TP/SL, margin/investment adjustment, and AI-recommended parameters. Requires API credentials. Not for regular orders (okx-cex-trade), market data (okx-cex-market), or account info (okx-cex-portfolio).

Install

npx vskill@latest install dex-original/okx-agent-trade-kit/okx-cex-bot

SKILL.md

OKX CEX Bot Trading

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.

Preflight

Before running any command, follow `../_shared/preflight.md`. Use metadata.version from this file's frontmatter as the reference for Step 2.

Prerequisites

bash
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 init for setup.

Credential & Profile Check

Run before every authenticated command. The auth method is detected during preflight Step 2 and remembered for the session.

Step A — Verify credentials

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.

bash
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.
  • No API-key profile AND auth status --json returns "status":"logged_in" → OAuth mode. Proceed to Step B.
  • No API-key profile AND "status":"pending" — login is in progress, wait for it to complete.
  • No API-key profile AND "status":"not_logged_in" — stop, load okx-cex-auth skill and follow login steps, wait for completion.
Step B — Confirm trading mode

Resolution:

  1. User intent is clear ("real"/"实盘"/"live" → live; "test"/"模拟"/"demo" → demo) → use it, inform user
  2. No explicit declaration → check conversation context for previous choice → reuse if found
  3. Nothing found → ask: "Live (实盘) or Demo (模拟盘)?" — wait before proceeding

How to apply the mode depends on auth method (detected in Step A):

Auth methodLive (实盘)Demo (模拟盘)
API Key--profile <live-profile>--profile <demo-profile>
OAuth(no flag needed, live is default)--demo
  • API Key users: run okx config show --json to discover available profile names and their demo settings.
  • OAuth users: omit flags for live; add --demo for simulated trading.

After every command: append [mode: live] or [mode: demo]

Handling 401 Errors

Authentication error (error contains "401", "Session expired", or "Run okx auth login first"):

  1. Stop immediately
  2. Load okx-cex-auth skill and follow re-authentication steps
  3. Retry original command

Skill Routing

NeedSkill
Market data, prices, depthokx-cex-market
Account balance, positions, feesokx-cex-portfolio
Regular spot/swap/futures ordersokx-cex-trade
Grid / DCA bots`okx-cex-bot` (this skill)

Command Index

Grid Bot
CommandTypeDescription
okx bot grid createWRITECreate a grid bot (spot or contract)
okx bot grid amendWRITEAmend price range, grid count, or TP/SL of a running grid bot
okx bot grid stopWRITEStop a grid bot
okx bot grid ordersREADList active or history grid bots
okx bot grid detailsREADGrid bot details + PnL
okx bot grid sub-ordersREADIndividual grid fills or pending orders
DCA Bot (Spot & Contract)
CommandTypeDescription
okx bot dca createWRITECreate a DCA (Martingale) bot (spot or contract)
okx bot dca stopWRITEStop a DCA bot (spot or contract)
okx bot dca ordersREADList active or history DCA bots (default: contract_dca)
okx bot dca detailsREADDCA bot details + PnL
okx bot dca sub-ordersREADDCA cycles and orders within a cycle

Operation Flow

Step 1 — Identify bot type and action

Parse user request → determine module (Grid / DCA) and action (create / stop / list / details).

Step 2 — Execute

READ commands (orders, details, sub-orders): run immediately after profile confirmation.

WRITE commands (create, amend, stop): confirm key parameters with user once before executing.

Step 3 — Verify after writes
  • After create → run the corresponding orders command to confirm active
  • After amend → run bot grid details to confirm updated config
  • After stop → run orders --history to confirm stopped

Key Rules

  • Never auto-transfer funds. If balance is insufficient for bot creation, report the shortfall (current available vs required) and ask the user how to proceed: (1) transfer funds manually, (2) reduce size, or (3) cancel.
  • `algoId` 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.
  • When operating on existing bots, always list first to get correct IDs, unless the user provides them explicitly.
  • TP/SL constraints: tpTriggerPx/tpRatio and slTriggerPx/slRatio are mutually exclusive pairs.

CLI Command Reference

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>] \
[--basePos] [--no-basePos] \
[--tpTriggerPx <px>] [--slTriggerPx <px>] [--tpRatio <ratio>] [--slRatio <ratio>] \
[--algoClOrdId <id>] [--json]
ParamRequiredDefaultDescription
--instIdYes-Instrument (e.g., BTC-USDT for spot, BTC-USDT-SWAP for USDT-M contract, BTC-USD-SWAP for coin-M contract)
--algoOrdTypeYes-grid (spot grid) or contract_grid (contract grid, including coin-margined)
--maxPxYes-Upper price boundary
--minPxYes-Lower price boundary
--gridNumYes-Grid levels (2–100)
--runTypeNo11=arithmetic spacing, 2=geometric spacing
--quoteSzCond.-USDT investment — spot grid only (provide quoteSz or baseSz)
--baseSzCond.-Base currency investment — spot grid only
--directionCond.-long, short, or neutral — required for contract grid
--leverCond.-Leverage (e.g., 5) — contract grid only
--szCond.-Investment margin in USDT (USDT-M) or coin (coin-M) — contract grid only
--basePos / --no-basePosNotrueOpen a base position at creation — contract grid only (ignored for neutral). Use --no-basePos to disable
--tpTriggerPxNo-Take-profit trigger price (mutually exclusive with --tpRatio)
--slTriggerPxNo-Stop-loss trigger price (mutually exclusive with --slRatio)
--tpRatioNo-Take-profit ratio — contract grid only (mutually exclusive with --tpTriggerPx)
--slRatioNo-Stop-loss ratio — contract grid only (mutually exclusive with --slTriggerPx)
--algoClOrdIdNo-Client-defined algo order ID (1-32 alphanumeric). Unique per user, enables idempotent creation

Grid Bot — Amend
bash
okx bot grid amend --algoId <id> \
[--maxPx <px> --minPx <px> --gridNum <n>] \
[--instId <id>] \
[--tpTriggerPx <px>] [--slTriggerPx <px>] \
[--tpRatio <ratio>] [--slRatio <ratio>] \
[--topUpAmt <n>] [--json]

Supports two modes that can be combined in one call:

Price-range mode — triggered when --maxPx is provided:

ParamRequiredDescription
--algoIdYesGrid bot algo order ID
--maxPxYesNew upper price boundary
--minPxYes (with maxPx)New lower price boundary
--gridNumYes (with maxPx)New grid count (integer)
--topUpAmtNoExtra margin to add (contract grid only; omit to auto-use minimum required)

TP/SL mode — triggered when at least one TP/SL param is provided; --instId is also required:

ParamRequiredDescription
--instIdYesInstrument ID (e.g., BTC-USDT)
--tpTriggerPxNoTake-profit trigger price (absolute). Pass -1 to clear
--slTriggerPxNoStop-loss trigger price (absolute). Pass -1 to clear
--tpRatioNoTake-profit ratio (e.g., 0.1 = 10%). Contract grid only. Pass -1 to clear
--slRatioNoStop-loss ratio (e.g., 0.1 = 10%). Contract grid only. Pass -1 to clear
--topUpAmtNoExtra margin to add (contract grid only)
Note: tpTriggerPx/tpRatio are mutually exclusive. Same for slTriggerPx/slRatio.

Grid Bot — Stop
bash
okx bot grid stop --algoId <id> --algoOrdType <type> --instId <id> \
[--stopType <1|2>] [--json]
`--algoId` and `--algoOrdType` must come from bot grid orders output. The algoOrdType must match the bot's actual type — do not guess.
--stopTypeBehavior
1Stop + sell/close all positions at market (default)
2Stop + keep current assets as-is

Grid Bot — List Orders
bash
okx bot grid orders --algoOrdType <type> [--instId <id>] [--algoId <id>] [--history] [--json]
ParamRequiredDefaultDescription
--algoOrdTypeYes-grid (spot), contract_grid (contract), or moon_grid (moon)
--instIdNo-Filter by instrument
--algoIdNo-Filter by algo order ID. NOT a normal trade order ID
--historyNofalseShow completed/stopped bots instead of active

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.


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

DCA Bot — Create (Spot & Contract)
bash
okx bot dca create --algoOrdType <spot_dca|contract_dca> --instId <id> --direction <long|short> \
--initOrdAmt <n> --maxSafetyOrds <n> --tpPct <ratio> \
[--lever <n>] [--safetyOrdAmt <n>] [--pxSteps <ratio>] [--pxStepsMult <mult>] [--volMult <mult>] \
[--slPct <ratio>] [--slMode <limit|market>] [--allowReinvest] \
[--triggerStrategy <instant|price|rsi>] [--triggerPx <price>] \
[--triggerCond <cross_up|cross_down>] [--thold <threshold>] [--timeframe <timeframe>] [--timePeriod <period>] \
[--algoClOrdId <id>] [--reserveFunds <true|false>] [--tradeQuoteCcy <ccy>] [--json]

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
106
Repository forks
2,293
7-day trend score
23

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/dex-original/okx-agent-trade-kit/okx-cex-bot/badge)](https://verified-skill.com/skills/dex-original/okx-agent-trade-kit/okx-cex-bot)

Something wrong with this skill or its page? Tell us.