okx/agent-skills/okx-cex-trade
Claude Code and agent skill by okx/agent-skills
- community
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-tradeSKILL.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 inreferences/<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
- Install
okxCLI:
``bash npm install -g @okx_ai/okx-trade-cli ``
- Configure credentials:
``bash okx config init # select site -> follow browser OAuth flow ``
- Test with demo mode (simulated trading, no real funds):
``bash okx --demo spot orders ``
Security: NEVER accept credentials in chat. Guide users tookx config initfor 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.
Apply in this order — first match wins:
config show --jsonhas any profile with a non-emptyapi_keyfield → API Key mode. Proceed to Step B.- No API-key profile AND
auth status --jsonreturns"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, loadokx-cex-authskill and follow login steps, wait for completion.
Step B — Confirm trading mode
Resolution rules:
- Current message intent is clear (e.g. "real" / "实盘" / "live" → live; "test" / "模拟" / "demo" → demo) → use it and inform the user
- 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 method | Live (实盘) | Demo (模拟盘) | |
|---|---|---|---|
| API Key | --profile <live-profile> | --profile <demo-profile> | |
| OAuth | (no flag needed, live is default) | --demo |
- API Key users: run
okx config show --jsonto discover available profile names and theirdemosettings. Use--profile <name>to select the correct one. - OAuth users: omit flags for live trading; add
--demofor simulated trading. Do not use--profileto switch modes.
Handling Authentication Errors
Authentication error (error contains "401", "Session expired", or "Run okx auth login first"):
- Stop immediately — do not retry the same command
- Inform the user: "Authentication failed. Your session may have expired."
- Load
okx-cex-authskill and follow the re-authentication steps - After successful re-authentication, retry the original command
Demo vs Live Mode
| Mode | Funds | API Key param | OAuth param | |
|---|---|---|---|---|
| 实盘 (live) | Real money — irreversible | --profile <live-profile> | (default, no flag) | |
| 模拟盘 (demo) | Simulated — no real funds | --profile <demo-profile> | --demo |
Rules:
- Trading mode is required on every authenticated command — determined in "Credential & Profile Check" Step B
- 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-tradewithokx event browse/okx event series - For trading event contracts (place/cancel/amend prediction market orders) → use
okx-cex-tradewithokx 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 tookx-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:
--tgtCcy | sz meaning | Conversion formula | Example: "500U" at 10x lever | |
|---|---|---|---|---|
base_ccy (default) | contract count | no conversion | 500 contracts | |
quote_ccy | USDT notional value | floor(sz / (ctVal * lastPx)) | 500 USDT notional | |
margin | USDT margin cost | floor(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
Command Index
Spot Orders (12 commands)
| # | Command | Type | Description | |
|---|---|---|---|---|
| 1 | okx spot place | WRITE | Place spot order (market/limit/post_only/fok/ioc) | |
| 2 | okx spot cancel | WRITE | Cancel spot order | |
| 3 | okx spot amend | WRITE | Amend spot order price or size | |
| 4 | okx spot algo place | WRITE | Place spot TP/SL algo order | |
| 5 | okx spot algo amend | WRITE | Amend spot TP/SL levels | |
| 6 | okx spot algo cancel | WRITE | Cancel spot algo order | |
| 7 | okx spot algo trail | WRITE | Place spot trailing stop order | |
| 8 | okx spot orders | READ | List open or historical spot orders | |
| 9 | okx spot get | READ | Single spot order details | |
| 10 | okx spot fills | READ | Spot trade fill history | |
| 11 | okx spot algo orders | READ | List spot TP/SL algo orders | |
| 12 | okx spot leverage | WRITE | Set 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
- SKILL.md in the repositoryCheckingskills/okx-cex-trade/SKILL.md
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
[](https://verified-skill.com/skills/okx/agent-skills/okx-cex-trade)