okx/agent-skills/okx-cex-trade

Claude Code and agent skill by okx/agent-skills

Trust tier 3
  • community
Source check pending

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

Use when the user asks to 'buy BTC', 'sell ETH', 'place a limit order', 'place a market order', 'cancel my order', 'amend my order', 'long BTC perp', 'short ETH swap', 'open a position', 'close a position', 'set take profit', 'limit take profit', 'immediate TP', 'set stop loss', 'self-trade prevention', 'stpMode', 'auto-cancel on close', 'trailing stop', 'pending order', 'chase order', 'iceberg', 'TWAP', 'split order', 'large order', 'set leverage', 'check my orders', 'fill history', 'buy a call', 'sell a put', 'option chain', 'implied volatility', 'IV', 'Greeks', 'delta', 'gamma', 'event contract', 'buy Yes', 'buy No', 'buy Up', 'buy Down', 'prediction market', or any request to place, cancel, or amend spot, swap, futures, options, or event contract orders on OKX CEX. Covers conditional (TP/SL/trailing) algo orders. Requires API credentials. Do NOT use for market data (okx-cex-market), account balance (okx-cex-portfolio), or bots (okx-cex-bot).

Install

npx vskill@latest install okx/agent-skills/okx-cex-trade

SKILL.md

OKX CEX Trading CLI

Spot, perpetual swap, delivery futures, options, and event contract order management on OKX exchange. Place, cancel, amend, and monitor orders; query option chains and Greeks; trade binary outcome event contracts (Yes/No, Up/Down); set take-profit/stop-loss and trailing stops; manage leverage and positions. Requires API credentials.

CLI vs MCP tool names — Subcommands use spaces (okx swap algo place, okx bot grid create), not hyphens. Do NOT convert an MCP tool identifier (swap_place_algo_order) into a hyphen-joined CLI command (okx swap place-algo) — that will be rejected with "Unknown command". Per-module mapping tables live in references/<module>-commands.md.

Preflight

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

Prerequisites

  1. Install okx CLI:

``bash npm install -g @okx_ai/okx-trade-cli ``

  1. Configure credentials:

``bash okx config init # select site -> follow browser OAuth flow ``

  1. Test with demo mode (simulated trading, no real funds):

``bash okx --demo spot orders ``

Security: NEVER accept credentials in chat. Guide users to okx config init for setup.

Credential & Profile Check

Run this check before any 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 all operations, load okx-cex-auth skill and follow login steps, wait for completion.
Step B — Confirm trading mode

Resolution rules:

  1. Current message intent is clear (e.g. "real" / "实盘" / "live" → live; "test" / "模拟" / "demo" → demo) → use it and inform the user
  2. Current message has no explicit declaration → check conversation context for a previous choice:
  • Found → reuse it, inform user
  • Not found → ask: "Live (实盘) or Demo (模拟盘)?" — wait for answer 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. Use --profile <name> to select the correct one.
  • OAuth users: omit flags for live trading; add --demo for simulated trading. Do not use --profile to switch modes.
Handling Authentication Errors

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

  1. Stop immediately — do not retry the same command
  2. Inform the user: "Authentication failed. Your session may have expired."
  3. Load okx-cex-auth skill and follow the re-authentication steps
  4. After successful re-authentication, retry the original command

Demo vs Live Mode

ModeFundsAPI Key paramOAuth param
实盘 (live)Real money — irreversible--profile <live-profile>(default, no flag)
模拟盘 (demo)Simulated — no real funds--profile <demo-profile>--demo

Rules:

  1. Trading mode is required on every authenticated command — determined in "Credential & Profile Check" Step B
  2. Every response after a command must append: [mode: live] or [mode: demo]

Skill Routing

  • For market data (prices, charts, depth, funding rates) → use okx-cex-market
  • For account balance, P&L, positions, fees, transfers → use okx-cex-portfolio
  • For regular spot/swap/futures/options/algo orders → use okx-cex-trade (this skill)
  • For browsing/discovering event contracts (what's available, how many, list active) → use okx-cex-trade with okx event browse / okx event series
  • For trading event contracts (place/cancel/amend prediction market orders) → use okx-cex-trade with okx event place / okx event cancel / okx event amend
  • For grid and DCA trading bots → use okx-cex-bot
Important: When user asks about "contracts" in the context of event contracts or prediction markets, route to this skill — NOT to okx-cex-portfolio. Portfolio does not handle event contracts — it covers account balance, positions, P&L, and transfers only.

Sz Handling for Derivatives

⚠ CRITICAL: Always verify contract face value before placing orders

Before placing any SWAP/FUTURES/OPTION order, call market_get_instruments to get ctVal (contract face value). Do NOT assume contract sizes — they vary by instrument (e.g. ETH-USDT-SWAP = 0.1 ETH/contract, BTC-USDT-SWAP = 0.01 BTC/contract).

Use ctVal to:

  • Calculate the correct number of contracts from user's intended position size
  • Verify margin requirements before submitting the order
  • Show the user the actual position value: sz × ctVal × price
SWAP and FUTURES orders

Three tgtCcy modes for USDT-denominated sizing:

--tgtCcysz meaningConversion formulaExample: "500U" at 10x lever
base_ccy (default)contract countno conversion500 contracts
quote_ccyUSDT notional valuefloor(sz / (ctVal * lastPx))500 USDT notional
marginUSDT margin costfloor(sz * lever / (ctVal * lastPx))500 USDT margin = 5000 USDT notional

When user specifies a USDT amount (e.g. "200U", "500 USDT", "$1000"): → AMBIGUOUS — this could mean notional value OR margin cost. You MUST ask the user to clarify before proceeding:

  • notional value: sz = position value in USDT (e.g. 500 USDT buys 500 USDT worth of contracts directly)
  • margin cost: actual position = sz × leverage (e.g. 500 USDT margin at 10× = 5000 USDT notional position)

Wait for the user's answer before continuing.

  • If notional value → use --tgtCcy quote_ccy
  • If margin cost → use --tgtCcy margin

When user specifies contracts (e.g. "2 张", "5 contracts"): → First verify ctVal via market_get_instruments, then use --sz with the contract count. Confirm with user: "X contracts = X × ctVal underlying, total value ≈ $Y".

When user gives a plain number with no unit (for swap/futures): → AMBIGUOUS — You MUST ask the user to clarify before proceeding:

  • contract count: X contracts (each worth ctVal of underlying)
  • USDT notional value: position value in USDT
  • USDT margin cost: margin amount (actual position = X × leverage)

Wait for the user's answer before continuing.

⚠ Inverse contracts (*-USD-SWAP, *-USD-YYMMDD): tgtCcy=quote_ccy and tgtCcy=margin also work (note: quote_ccy = USD, not USDT, for inverse instruments). Always warn: "This is an inverse contract. Margin and P&L are settled in BTC, not USDT."

Option orders

When the user specifies a USDT amount for options, use --tgtCcy quote_ccy (notional) or --tgtCcy margin (margin cost) and pass the amount as --sz. The system automatically converts to contracts. Note: option contracts typically have large face values (e.g. ctVal=1 BTC ≈ $84,000), so the minimum USDT amount for 1 contract is high. For option sellers (cross/isolated tdMode), margin mode accounts for leverage automatically.

Quickstart

bash
# Market buy 0.01 BTC (spot)
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
# Buy $10 worth of SOL (spot, USDT amount)
okx spot place --instId SOL-USDT --side buy --ordType market --sz 10 --tgtCcy quote_ccy
# Limit sell 0.01 BTC at $100,000 (spot)
okx spot place --instId BTC-USDT --side sell --ordType limit --sz 0.01 --px 100000
# Long 1 contract BTC perp (cross margin)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long
# Long 1000 USDT notional value of BTC perp (auto-convert to contracts)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1000 \
--tgtCcy quote_ccy --tdMode cross --posSide long
# Long with 500 USDT margin at current leverage (e.g. 10x → 5000 USDT notional)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 500 \
--tgtCcy margin --tdMode cross --posSide long
# Long 1 contract with attached TP/SL (one step)
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 \
--tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx=-1 --slTriggerPx 88000 --slOrdPx=-1
# Close BTC perp long position entirely at market
okx swap close --instId BTC-USDT-SWAP --mgnMode cross --posSide long
# Set 10x leverage on BTC perp (cross)
okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross
# Set TP/SL on a spot BTC position
okx spot algo place --instId BTC-USDT --side sell --ordType oco --sz 0.01 \
--tpTriggerPx 105000 --tpOrdPx=-1 \
--slTriggerPx 88000 --slOrdPx=-1
# Place trailing stop on BTC perp long (callback 2%)
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 1 \
--tdMode cross --posSide long --callbackRatio 0.02
# View open spot orders
okx spot orders
# View open swap positions
okx swap positions
# Cancel a spot order
okx spot cancel --instId BTC-USDT --ordId <ordId>
# --- Event Contract ---
# List event series
okx event series
# Browse live markets in a series
okx event markets BTC-ABOVE-DAILY --state live
# Place event contract order
okx event place --instId BTC-ABOVE-DAILY-260224-1600-70000 --side buy --outcome YES --sz 10

Command Index

Spot Orders (12 commands)
#CommandTypeDescription
1okx spot placeWRITEPlace spot order (market/limit/post_only/fok/ioc)
2okx spot cancelWRITECancel spot order
3okx spot amendWRITEAmend spot order price or size
4okx spot algo placeWRITEPlace spot TP/SL algo order
5okx spot algo amendWRITEAmend spot TP/SL levels
6okx spot algo cancelWRITECancel spot algo order
7okx spot algo trailWRITEPlace spot trailing stop order
8okx spot ordersREADList open or historical spot orders
9okx spot getREADSingle spot order details
10okx spot fillsREADSpot trade fill history
11okx spot algo ordersREADList spot TP/SL algo orders
12okx spot leverageWRITESet leverage for spot margin (borrowing). Pair-level (--instId) or currency-level cross (--ccy, required for borrow-enabled / multi-ccy / portfolio margin)

For full command syntax, parameter tables, and edge cases, read {baseDir}/references/spot-commands.md.

Swap / Perpetual Orders (15 commands)

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

Security

  • Security scanPassed, 90 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
43
Repository forks
6
7-day trend score
19

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 7 months ago.

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/okx/agent-skills/okx-cex-trade/badge)](https://verified-skill.com/skills/okx/agent-skills/okx-cex-trade)

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