Okx Cex Trade
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).
- Skill ID
- okx/agent-skills/okx-cex-trade
- Publisher
- okx
- Repository
- agent-skills
- Installs
- 0
- Files
- 9
- License
- MIT
- Synced
- Sep 23, 2026
Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.
okx/agent-skills/okx-cex-tradeInstalls these files- SKILL.md
- references/event-commands.md
- references/event-workflows.md
- references/futures-commands.md
- references/options-commands.md
- references/spot-commands.md
- references/swap-commands.md
- references/templates.md
- references/workflows.md
What this skill tells the agent
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 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.
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 --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 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:
--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
More from okx
Use this skill in a project
Open any RiverX project, search the Skills panel for okx/agent-skills/okx-cex-trade, and install it in one click.
