okx/agent-skills

okx-cex-bot

Manage Grid bots (spot/contract/coin-margined) and DCA Martingale bots (Spot DCA 现货马丁 / Contract DCA 合约马丁) on OKX.

查看源码
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

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 positionsREADQuery open contract-grid positions (liquidation price, margin ratio, unrealized PnL)
okx bot grid liquidate-priceREADEstimate liquidation price for a contract-grid bot
okx bot grid close-positionWRITEClose remaining position after bot stopped with stopType=2
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.

Workflow:

  1. Run bot grid details --algoId <id> --algoOrdType <type> and check the state field.
  2. If state=running: call stop with --stopType 1 (default, clean exit) or --stopType 2 (keep assets).
  3. If state=no_close_position (user previously stopped with stopType=2): call stop again with --stopType 1 to close the remaining open position.
--stopTypeSpot gridContract grid
1 (default)Sells all base assets back to quoteMarket-closes all open positions
2Keeps base assets as-isCancels grid orders, leaves position open

Grid Bot — Positions

bash
okx bot grid positions --algoId <id> --algoOrdType contract_grid [--json]

Returns open contract-grid positions: liquidation price (liqPx), margin ratio (mgnRatio), and unrealized PnL (upl). Only applicable to contract_grid bots.


Grid Bot — Liquidation Price

bash
okx bot grid liquidate-price --instId <id> --sz <margin> --lever <leverage> \
  --maxPx <px> --minPx <px> --gridNum <n> --direction <long|short|neutral> \
  [--runType <1|2>] [--triggerStrategy <instant|price|rsi|webhook>] [--json]

Estimates the liquidation price for a contract-grid bot. Use before creating a bot to assess liquidation risk. The estimate needs the full intended config — the backend requires instId, sz, lever, the grid range (maxPx/minPx/gridNum) and direction (use neutral for a neutral bot); omitting any of them fails fast with the list of what's missing. runType defaults to 1 (arithmetic; 2=geometric) and triggerStrategy is optional.


Grid Bot — Close Position

bash
okx bot grid close-position --algoId <id> (--mktClose | --no-mktClose) [--sz <size>] [--px <price>] [--json]

Closes the remaining open position of a contract-grid bot that was stopped with stopType='2'. The close mode is required (no default, because it moves funds): pass --mktClose for a market close (immediate), or --no-mktClose --sz <size> --px <price> for a limit close order. Omitting both is rejected.


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> [--pending] [--groupId <id>] [--after <id>] [--before <id>] [--limit <n>] [--json]
FlagEffect
(default)Filled sub-orders (executed grid trades)
--pendingPending grid orders currently on the book. (Works in demo mode. --live is a deprecated alias and cannot be combined with --demo.)
--groupIdFilter to one buy-sell pair (shared groupId)
--afterPagination cursor — records older than this id
--beforePagination cursor — records newer than this id
--limitMax records to return (default 100)

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]
ParamRequiredDefaultDescription
--algoOrdTypeYes-spot_dca (Spot DCA) or contract_dca (Contract DCA)
--instIdYes-Instrument (e.g., BTC-USDT for spot, BTC-USDT-SWAP for contract)
--leverCond.-Leverage multiplier (e.g., 3). Required for contract_dca
--directionYes-long or short. spot_dca must be long
--initOrdAmtYes-Initial order amount (quote currency)
--maxSafetyOrdsYes-Max safety orders, integer [0, 100] (e.g., 3; 0 = no DCA)
--safetyOrdAmtCond.-Safety order amount (quote currency). Required when maxSafetyOrds > 0
--pxStepsCond.-Initial price deviation [0.001, 0.5], e.g., 0.03 = 3%. Required when maxSafetyOrds > 0
--pxStepsMultCond.1Price step multiplier (e.g., 1.2). Required when maxSafetyOrds > 0
--volMultCond.1Safety order size multiplier (e.g., 1.5). Required when maxSafetyOrds > 0
--tpPctYes-Take-profit ratio: long [0.001, 10], short [0.001, 0.9999] (e.g., 0.03 = 3%)
--slPctNo-Stop-loss ratio, must exceed MPD (e.g., 0.05 = 5%). Must be used with --slMode
--slModeNomarketStop-loss type: limit or market. Must be used with --slPct
--allowReinvestNotrueReinvest profit into the next DCA cycle
--triggerStrategyNoinstantcontractdca: `instant`, `price`, `rsi`; spotdca: instant, rsi
--triggerPxNo-Trigger price — required when triggerStrategy=price (contract_dca only)
--triggerCondNo-cross_up or cross_down — required when triggerStrategy=rsi, optional when triggerStrategy=price
--tholdNo-RSI threshold (e.g. 30) — required when triggerStrategy=rsi
--timeframeNo-RSI timeframe (e.g. 15m) — required when triggerStrategy=rsi
--timePeriodNo14RSI period — optional when triggerStrategy=rsi
--algoClOrdIdNo-Client-defined strategy order ID (1-32 alphanumeric)
--reserveFundsNotruetrue or false — whether to reserve funds
--tradeQuoteCcyNo-Trade quote currency

Conditional required logic:

  • Always required: --algoOrdType, --instId, --direction, --initOrdAmt, --maxSafetyOrds, --tpPct
  • When algoOrdType=contract_dca: also required --lever
  • When maxSafetyOrds > 0: also required --safetyOrdAmt, --pxSteps, --pxStepsMult, --volMult
  • --slPct and --slMode must be both set or both omitted

DCA Bot — Stop

bash
okx bot dca stop --algoOrdType <spot_dca|contract_dca> --algoId <id> [--stopType <1|2>] [--json]

Workflow:

  1. Run bot dca details --algoId <id> --algoOrdType <type> and check the state field.
  2. If state=running: call stop (with --stopType for spot_dca).
  3. If state=no_close_position (user previously stopped with stopType=2): call stop again with --stopType 1 to close the remaining open position.
ParamRequiredDefaultDescription
--algoOrdTypeYes-spot_dca or contract_dca
--algoIdYes-DCA bot algo order ID (from create or list output). NOT a normal trade order ID
--stopTypeCond.1spot_dca required: 1=sell all tokens, 2=keep tokens. contract_dca: 1=close position (default), 2=keep position open

DCA Bot — List Orders

bash
okx bot dca orders [--algoOrdType <spot_dca|contract_dca>] [--algoId <id>] [--instId <id>] [--history] [--json]
ParamRequiredDefaultDescription
--algoOrdTypeNocontract_dcaFilter by strategy type
--algoIdNo-Filter by DCA bot algo order ID
--instIdNo-Filter by instrument
--historyNofalseShow completed/stopped bots instead of active

DCA Bot — Details

bash
okx bot dca details --algoOrdType <spot_dca|contract_dca> --algoId <id> [--json]

Returns: avgPx, upl, liqPx, sz, tpPx, slPx, initPx, fundingFee, fee, fillSafetyOrds, algoClOrdId, baseSz, quoteSz, tradeQuoteCcy.


DCA Bot — Sub-Orders

bash
okx bot dca sub-orders --algoOrdType <spot_dca|contract_dca> --algoId <id> [--cycleId <id>] [--json]
Flag / ParamEffect
(default)List all cycles
--cycleId <id>Show orders within a specific cycle

Quickstart

bash
# Spot grid: BTC $90k–$100k, 10 grids, 1000 USDT
okx bot grid create --instId BTC-USDT --algoOrdType grid \
  --minPx 90000 --maxPx 100000 --gridNum 10 --quoteSz 1000

# Contract grid: BTC perp, neutral, 5x, 100 USDT margin
okx bot grid create --instId BTC-USDT-SWAP --algoOrdType contract_grid \
  --minPx 90000 --maxPx 100000 --gridNum 10 \
  --direction neutral --lever 5 --sz 100

# Coin-margined contract grid: BTC inverse perp
okx bot grid create --instId BTC-USD-SWAP --algoOrdType contract_grid \
  --minPx 90000 --maxPx 100000 --gridNum 10 \
  --direction long --lever 5 --sz 0.01

# Contract DCA bot: BTC perp, long, 3x, 3% TP
okx bot dca create --algoOrdType contract_dca --instId BTC-USDT-SWAP --lever 3 --direction long \
  --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
  --pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03

# Spot DCA bot: BTC spot, long, 5% TP
okx bot dca create --algoOrdType spot_dca --instId BTC-USDT --direction long \
  --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
  --pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 --tpPct 0.05

# Amend grid price range
okx bot grid amend --algoId 3486105572796182528 --maxPx 102000 --minPx 88000 --gridNum 14

# Amend grid TP/SL
okx bot grid amend --algoId 3486105572796182528 --instId BTC-USDT --tpTriggerPx 110000 --slTriggerPx 80000

# Amend both in one call (combined mode)
okx bot grid amend --algoId 3486105572796182528 \
  --maxPx 102000 --minPx 88000 --gridNum 14 \
  --instId BTC-USDT --tpTriggerPx 110000 --slTriggerPx 80000

# Clear TP/SL (use =-1 syntax for negative values)
okx bot grid amend --algoId 3486105572796182528 --instId BTC-USDT --tpTriggerPx=-1 --slTriggerPx=-1

# List all active bots
okx bot grid orders --algoOrdType grid
okx bot grid orders --algoOrdType contract_grid
okx bot dca orders --algoOrdType contract_dca
okx bot dca orders --algoOrdType spot_dca

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 DCA Bot

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 --algoOrdType contract_dca --instId BTC-USDT-SWAP \
                       --lever 3 --direction long \
                       --initOrdAmt 200 --safetyOrdAmt 100 --maxSafetyOrds 3 \
                       --pxSteps 0.03 --pxStepsMult 1 --volMult 1 --tpPct 0.03
4. okx-cex-bot       okx bot dca orders --algoOrdType contract_dca   → confirm active
5. okx-cex-bot       okx bot dca details --algoOrdType contract_dca --algoId <id> → monitor PnL

Spot DCA Bot

User: "帮我在现货上 DCA BTC,首单 100 USDT,5% 止盈"
1. okx-cex-market    okx market ticker BTC-USDT                     → confirm current price
2. okx-cex-portfolio okx account balance USDT                       → confirm funds
        ↓ user approves
3. okx-cex-bot       okx bot dca create --algoOrdType spot_dca --instId BTC-USDT \
                       --direction long \
                       --initOrdAmt 100 --safetyOrdAmt 50 --maxSafetyOrds 3 \
                       --pxSteps 0.03 --pxStepsMult 1.2 --volMult 1.5 --tpPct 0.05
4. okx-cex-bot       okx bot dca orders --algoOrdType spot_dca       → confirm active

Edge Cases

Grid Bot

  • Price out of range: --minPx must be < current price < --maxPx; check with okx-cex-market first
  • Insufficient balance: check okx-cex-portfolioaccount balance before creating. If insufficient, do NOT auto-transfer — report the shortfall and ask the user for instructions
  • Contract grid direction: long (buys more at lower prices), short (sells at higher), neutral (both). Direction is required for contract grid
  • Contract grid basePos: defaults to true — long/short grids automatically open a base position at creation. Neutral direction ignores this. Pass --no-basePos to disable
  • Contract grid --sz: investment margin in USDT (USDT-M) or coin (coin-M), not number of contracts
  • Coin-margined grids: use inverse instruments (e.g., BTC-USD-SWAP). Margin unit is the base coin (BTC), not USDT
  • Stop type: stopType 1 sells/closes all (default); stopType 2 keeps assets as-is (spot grid) or leaves position open for manual close (contract grid)
  • TP/SL: tpTriggerPx/tpRatio and slTriggerPx/slRatio are mutually exclusive pairs. Ratio-based TP/SL is contract grid only
  • Amend — at least one mode required: must provide either price-range params (--maxPx+--minPx+--gridNum) or TP/SL params; providing neither returns a validation error
  • Amend — combined mode: price-range and TP/SL can be combined in one call (two sequential API requests internally)
  • Amend — clear TP/SL: pass --tpTriggerPx=-1 or --slTriggerPx=-1 (use = syntax for negative values, not --flag -1)
  • Amend — contract grid topUpAmt: if new range requires more margin, provide --topUpAmt; omit to auto-use the minimum required
  • Amend — spot grid topUpAmt: not supported; omit --topUpAmt for spot grids
  • Already stopped bot: stop returns error — check bot grid orders --history first to confirm state
  • Insufficient margin (51340): extract required minimum from error, check balance via okx-cex-portfolio, report shortfall to user — do NOT auto-transfer
  • Demo mode: okx --demo bot grid create ... (OAuth) or okx --profile <demo-profile> bot grid create ... (API Key) — safe for testing, no real funds
  • algoClOrdId duplicate: if the same algoClOrdId already exists, the API returns error code 51065

DCA Bot

  • Spot DCA direction: must always be long. If user says "short spot DCA", explain that spot DCA only supports long direction
  • Spot DCA stopType: always ask user whether to sell all tokens (1) or keep them (2) when stopping
  • Contract DCA lever: required. If missing, the tool returns a validation error
  • pxStepsMult: 1.0 = equal spacing; >1.0 = widen gaps between successive safety orders
  • volMult: 1.0 = equal sizes; >1.0 = increase per safety order (Martingale scaling)
  • triggerStrategy: instant starts immediately; price waits for trigger price (contractdca only); `rsi` waits for RSI condition (both spotdca and contract_dca)
  • Already stopped bot: stop returns error — check bot dca orders --history first
  • Demo mode: okx --demo bot dca create ... (OAuth) or okx --profile <demo-profile> bot dca create ... (API Key) — safe testing, no real funds
  • INVALID_PRICE_STEPS_MULTIPLIER error: adjust slPct. Recalculate MPD = Σ(pxSteps × pxStepsMult^i) for i = 0..maxSafetyOrds−1, then set slPct > MPD
  • algoClOrdId duplicate: error code 51065

Communication Guidelines

  • Grid/DCA: use "bot" not "strategy" (e.g., "grid bot", "DCA bot")
  • DCA: always say "DCA" or "Martingale" — DCA supports both Spot DCA and Contract DCA
  • Chinese: Grid = "网格", Spot DCA = "现货马丁", Contract DCA = "合约马丁"
  • Use natural language for parameters — "What price range?" not "Enter minPx and maxPx"
  • If the user already provides values, map directly — don't re-ask

Parameter Display Names

{base} and {quote}: extract from instId by splitting on -. E.g., BTC-USDT-SWAP → base=BTC, quote=USDT.

Grid Bot — Spot (algoOrdType=grid)

API FieldENZH
instIdTrading pair交易对
minPxLower price bound网格下限价格
maxPxUpper price bound网格上限价格
gridNumNumber of grids网格数量
quoteSzInvestment amount ({quote})投入金额({quote})
baseSzInvestment amount ({base})投入金额({base})
runTypeSpacing mode (1=arithmetic, 2=geometric)网格间距模式(1=等差, 2=等比)
stopTypeStop behavior停止方式

Grid Bot — Contract (algoOrdType=contract_grid)

API FieldENZH
instIdTrading pair交易对
minPxLower price bound网格下限价格
maxPxUpper price bound网格上限价格
gridNumNumber of grids网格数量
szInvestment margin (USDT for USDT-M; {base} for coin-M)投入保证金(USDT-M 为 USDT;币本位为 {base})
directionDirection (long / short / neutral)方向(做多 / 做空 / 中性)
leverLeverage杠杆倍数
runTypeSpacing mode (1=arithmetic, 2=geometric)网格间距模式(1=等差, 2=等比)
basePosOpen base position是否开底仓
stopTypeStop behavior停止方式

DCA Bot (Spot & Contract)

API FieldENZH
algoOrdTypeStrategy type (spot/contract)策略类型(现货/合约)
instIdTrading pair交易对
initOrdAmtInitial order amount ({quote})首单金额({quote})
safetyOrdAmtSafety order amount ({quote})补仓金额({quote})
maxSafetyOrdsMax safety orders最大补仓次数
pxStepsPrice drop per safety order (%)补仓价格跌幅(%)
pxStepsMultPrice step multiplier补仓跌幅倍数
volMultSafety order size multiplier补仓金额倍数
tpPctTake-profit ratio (%)止盈比例(%)
slPctStop-loss ratio (%)止损比例(%)
slModeStop-loss type (limit/market)止损类型(限价/市价)
leverLeverage杠杆倍数
directionDirection (long/short)方向(做多/做空)
allowReinvestReinvest profit利润再投入
triggerStrategyTrigger mode (contractdca: instant/price/rsi; spotdca: instant/rsi)触发方式
triggerPxTrigger price触发价格
algoClOrdIdClient order ID客户端策略订单 ID
stopTypeStop type (sell all / keep tokens)停止类型(卖出/保留)
reserveFundsReserve funds预留资金
`slPct` stop-loss logic: - Long: stop-loss price = initial fill price × (1 − slPct) - Short: stop-loss price = initial fill price × (1 + slPct) When triggered and position fully closed, the bot ends.

Global Notes

  • All bots run on OKX servers — stopping the CLI does not affect them
  • Auth method and trading mode are determined in "Credential & Profile Check"; see that section for parameter rules
  • --json returns the raw OKX API v5 response by default. Add --env to wrap the output as {"env": "<live|demo>", "profile": "<name>", "data": <response>}
  • Rate limit: 20 requests per 2 seconds per UID
  • Grid --gridNum range: 2–100
来自同一仓库

更多 Skills

全部 Skills
okx
社区

okx-cex-smartmoney

Smart Money analytics on OKX: leaderboard traders, position tracking, trade records, closed-position history, aggregated consensus signals, and signal history. Use this skill when the user asks about 聪明钱, smart money, 牛人榜, leaderboard, top traders, 交易员排行, trader ranking, trader positions, trader PnL, 交易员持仓, 交易员收益, 历史平仓, closed positions, realized PnL track record, trade history, 成交记录, smart money signal, 聪明钱信号, long/short ratio, 多空比, capital flow, 资金流向, position conviction, 仓位强度, entry price distribution, smart money overview, 聪明钱总览, signal history, 信号历史, trader search, 搜索交易员, who is trading BTC, 谁在交易BTC, recommend traders, 推荐交易员, best traders, top performers.

安装量
5
GitHub Stars
170
最近更新
9月7日
okx
社区

earn-hunter

Automatically monitors OKX Flash Earn, Fixed Earn and Flexible Earn opportunities, sends push notifications, and guides subscription. 自动监控 OKX 闪赚、定期和活期赚币机会,推送通知并引导申购。Use when user says: 有闪赚通知我, 监控赚币, monitor earn, notify me about earn, 定时检查理财, 执行 earn-hunter 扫描, earn-hunter scan, 活期年化高了通知我, 监控活期.

安装量
4
GitHub Stars
170
最近更新
9月7日
okx
社区

okx-cex-auth

Use this skill when the user wants to 'login/log in/sign in', 'authenticate', 'authorize', 'connect OKX account', 'set up credentials', 'first time setup', 'configure okx', '登录', '授权', '认证', '连接账户', '首次配置'. Also when any OKX CLI command fails with an auth error: 'Run okx auth login first', 'Session expired', 'not authenticated', 'requiresauth', '401 Unauthorized', 'token expired/not found', 'StorageNotFoundError', '会话过期', '未认证', '需要登录'. Also when the user asks about login status or the login was interrupted. Also when the user wants to install/update/check/remove the okx-auth binary — 'install/update/remove auth', 'download okx-auth', '安装/更新/卸载认证', 'auth binary status', 'Failed to spawn okx-auth'. Also use before using okx-cex-trade/portfolio/earn/bot for the first time. Do NOT use for market data queries (use okx-cex-market).

安装量
4
GitHub Stars
170
最近更新
9月7日
okx
社区

okx-cex-earn

Manages OKX Simple Earn (flexible savings/lending), Flash Earn, On-chain Earn (staking/DeFi), Dual Investment (DCD/双币赢), and AutoEarn (自动赚币) via the okx CLI. Use this skill whenever the user wants to check earn balances, browse flash-earn projects, subscribe or redeem earn products, view or set lending rates, monitor on-chain staking orders, interact with dual investment structured products, or manage auto-earn — even if phrased casually as 活期赚币, 定期赚币, 闪赚, 赚币, 申购, 赎回, 链上赚币, 质押, 理财, 双币赢, 双币理财, 双币申购, 高卖, 低买, dual investment, DCD, flash earn, buy low, sell high structured product, earn with target price, 目标价, 自动赚币, auto earn, auto-earn, 自动借出, 自动质押, auto lend, auto staking, USDG earn, USDG 赚币, 闲置资金自动理财, fixed earn, fixed deposit, term deposit, 定期理财, 定期. Also use when the user asks about idle funds and whether to earn on them.

安装量
4
GitHub Stars
170
最近更新
9月7日