OKX CEX Trading CLI
Spot, perpetual swap, delivery futures, and options order management on OKX exchange. Place, cancel, amend, and monitor orders; query option chains and Greeks; set take-profit/stop-loss and trailing stops; manage leverage and positions. Requires API credentials.
Prerequisites
- Install CLI:
bash
npm install -g @okx_ai/okx-trade-cli
- Configure credentials:
Or set environment variables:
bash
export OKX_API_KEY=your_key
export OKX_SECRET_KEY=your_secret
export OKX_PASSPHRASE=your_passphrase
- Test with demo mode (simulated trading, no real funds):
Demo vs Live Mode
CRITICAL: Always confirm demo vs live before any write command (place, cancel, amend, close, leverage, algo).
How to check current mode
bash
okx config show # shows current profile settings
How to switch mode per command
Prepend
to run in simulated trading mode (no real funds affected):
bash
okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
okx --demo swap close --instId BTC-USDT-SWAP --mgnMode cross
Omit
to execute on the live account (real funds).
Rules for this skill
- Before every write command, explicitly ask or confirm: "Execute on live account or demo (simulated)?" — do not assume.
- Read commands (orders, positions, fills, get, algo orders): run immediately; note which mode was used.
- When executing demo, prefix the response summary with and state no real funds were affected.
- When executing live, prefix the response summary with and flag that real funds are involved.
- If the user says "try it" / "test it" / "simulate" / "paper trade" → use .
- If the user says "real" / "actual" / "go live" / "execute" → confirm once more before running without .
Example
User: "Buy 0.01 BTC"
Agent: "Execute on live account (real funds) or demo (simulated)?"
User: "Demo"
Agent runs: okx --demo spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
Agent replies: "[DEMO] Order placed: 7890123456 (OK) — simulated, no real funds used."
Skill Routing
- For market data (prices, charts, depth, funding rates) → use
- For account balance, P&L, positions, fees, transfers → use
- For regular spot/swap/futures/options/algo orders → use (this skill)
- For grid and DCA trading bots → use
Quickstart
bash
# Market buy 0.01 BTC (spot)
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.01
# 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
# 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 (sell when price hits $105k, SL at $88k)
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>
Command Index
Spot Orders
| # | Command | Type | Description |
|---|
| 1 | | WRITE | Place spot order (market/limit/post_only/fok/ioc) |
| 2 | | WRITE | Cancel spot order |
| 3 | | WRITE | Amend spot order price or size |
| 4 | | WRITE | Place spot TP/SL algo order |
| 5 | | WRITE | Amend spot TP/SL levels |
| 6 | | WRITE | Cancel spot algo order |
| 7 | | READ | List open or historical spot orders |
| 8 | | READ | Single spot order details |
| 9 | | READ | Spot trade fill history |
| 10 | | READ | List spot TP/SL algo orders |
Swap / Perpetual Orders
| # | Command | Type | Description |
|---|
| 11 | | WRITE | Place perpetual swap order |
| 12 | | WRITE | Cancel swap order |
| 13 | | WRITE | Amend swap order price or size |
| 14 | | WRITE | Close entire position at market |
| 15 | | WRITE | Set leverage for an instrument |
| 16 | | WRITE | Place swap TP/SL algo order |
| 17 | | WRITE | Place swap trailing stop order |
| 18 | | WRITE | Amend swap algo order |
| 19 | | WRITE | Cancel swap algo order |
| 20 | | READ | Open perpetual swap positions |
| 21 | | READ | List open or historical swap orders |
| 22 | | READ | Single swap order details |
| 23 | | READ | Swap trade fill history |
| 24 | | READ | Current leverage settings |
| 25 | | READ | List swap algo orders |
Futures / Delivery Orders
| # | Command | Type | Description |
|---|
| 26 | | WRITE | Place delivery futures order |
| 27 | | WRITE | Cancel delivery futures order |
| 28 | | READ | List delivery futures orders |
| 29 | | READ | Open delivery futures positions |
| 30 | | READ | Delivery futures fill history |
| 31 | | READ | Single delivery futures order details |
Options Orders
| # | Command | Type | Description |
|---|
| 32 | | READ | Option chain: list available contracts for an underlying |
| 33 | | READ | Implied volatility + Greeks (delta/gamma/theta/vega) by underlying |
| 34 | | WRITE | Place option order (call or put, buyer or seller) |
| 35 | | WRITE | Cancel unfilled option order |
| 36 | | WRITE | Amend option order price or size |
| 37 | | WRITE | Batch cancel up to 20 option orders |
| 38 | | READ | List option orders (live / history / archive) |
| 39 | | READ | Single option order details |
| 40 | | READ | Open option positions with live Greeks |
| 41 | | READ | Option trade fill history |
Cross-Skill Workflows
Spot market buy
User: "Buy $500 worth of ETH at market"
1. okx-cex-market okx market ticker ETH-USDT → get current price to estimate sz
2. okx-cex-portfolio okx account balance USDT → confirm available funds ≥ $500
↓ user approves
3. okx-cex-trade okx spot place --instId ETH-USDT --side buy --ordType market --sz <sz>
4. okx-cex-trade okx spot fills --instId ETH-USDT → confirm fill price and size
Open long BTC perp with TP/SL
User: "Long 5 contracts BTC perp at market, TP at $105k, SL at $88k"
1. okx-cex-portfolio okx account balance USDT → confirm margin available
2. okx-cex-portfolio okx account max-size --instId BTC-USDT-SWAP --tdMode cross → confirm size ok
↓ user approves
3. okx-cex-trade okx swap place --instId BTC-USDT-SWAP --side buy \
--ordType market --sz 5 --tdMode cross --posSide long
4. okx-cex-trade okx swap algo place --instId BTC-USDT-SWAP --side sell \
--ordType oco --sz 5 --tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx -1 \
--slTriggerPx 88000 --slOrdPx -1
5. okx-cex-trade okx swap positions → confirm position opened
Adjust leverage then place order
User: "Set BTC perp to 5x leverage then go long 10 contracts"
1. okx-cex-trade okx swap get-leverage --instId BTC-USDT-SWAP --mgnMode cross → check current lever
↓ user approves change
2. okx-cex-trade okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross
3. okx-cex-trade okx swap place --instId BTC-USDT-SWAP --side buy \
--ordType market --sz 10 --tdMode cross --posSide long
4. okx-cex-trade okx swap positions → confirm position + leverage
Place trailing stop on open position
User: "Set a 3% trailing stop on my BTC perp long"
1. okx-cex-trade okx swap positions → confirm size of open long
2. okx-cex-market okx market ticker BTC-USDT-SWAP → current price reference
↓ user approves
3. okx-cex-trade okx swap algo trail --instId BTC-USDT-SWAP --side sell \
--sz <pos_size> --tdMode cross --posSide long --callbackRatio 0.03
4. okx-cex-trade okx swap algo orders --instId BTC-USDT-SWAP → confirm trail order placed
Cancel all open spot orders
User: "Cancel all my open BTC spot orders"
1. okx-cex-trade okx spot orders → list open orders
2. okx-cex-trade (for each ordId) okx spot cancel --instId BTC-USDT --ordId <id>
3. okx-cex-trade okx spot orders → confirm all cancelled
Buy a BTC call option
User: "Buy 2 BTC call options at strike 95000 expiring end of March"
1. okx-cex-trade okx option instruments --uly BTC-USD --expTime 250328
→ find exact instId (e.g. BTC-USD-250328-95000-C)
2. okx-cex-trade okx option greeks --uly BTC-USD --expTime 250328
→ check IV, delta, and markPx to assess fair value
3. okx-cex-portfolio okx account balance → confirm enough USDT/BTC for premium
↓ user approves
4. okx-cex-trade okx option place --instId BTC-USD-250328-95000-C \
--side buy --ordType limit --tdMode cash --sz 2 --px 0.005
5. okx-cex-trade okx option orders → confirm order is live
Check option portfolio Greeks
User: "What's my total delta exposure from options?"
1. okx-cex-trade okx option positions → live positions with per-contract Greeks
2. okx-cex-market okx market ticker BTC-USD → current spot price for context
Operation Flow
Step 1: Identify instrument type and action
- Place/cancel/amend order →
okx spot place/cancel/amend
- TP/SL conditional →
okx spot algo place/amend/cancel
- Query →
okx spot orders/get/fills/algo orders
Swap/Perpetual (instId format:
):
- Place/cancel/amend order →
okx swap place/cancel/amend
- Close position →
- Leverage → /
- TP/SL conditional →
okx swap algo place/amend/cancel
- Trailing stop →
- Query →
okx swap positions/orders/get/fills/get-leverage/algo orders
Futures/Delivery (instId format:
):
- Place/cancel order →
- Query →
okx futures orders/positions/fills/get
Options (instId format:
or
):
- Step 1 (required): find valid instId →
okx option instruments --uly BTC-USD
- Step 2 (recommended): check IV and Greeks →
okx option greeks --uly BTC-USD
- Place/cancel/amend order →
okx option place/cancel/amend
- Batch cancel →
okx option batch-cancel --orders '[...]'
- Query →
okx option orders/get/positions/fills
- tdMode: for buyers (full premium upfront, no liquidation risk); or for sellers (margin required)
Step 2: Confirm demo vs live, then confirm write parameters
Read commands (orders, positions, fills, get, get-leverage, algo orders): run immediately; note the mode used.
- flag: defaults to active/open; use only if user explicitly asks for history
- for algo: = single TP or SL; = both TP and SL together
- for swap/futures: or ; spot always uses (set automatically)
- for hedge mode: or ; omit in net mode
Write commands (place, cancel, amend, close, leverage, algo): two confirmations required:
- Demo or live? — Ask the user before the first write in any session. If unclear, default to asking.
- Demo → prepend to every write command; label result
- Live → execute without ; label result
- Confirm parameters — confirm the key order details once before executing:
- Spot place: confirm , , , ; price () required for limit orders
- Swap place: confirm , , , ; confirm if in hedge mode
- Swap close: confirm , , ; closes the entire position at market
- Swap leverage: confirm new leverage and impact on existing positions; cannot exceed exchange max
- Algo place (TP/SL): confirm trigger prices; use for market execution at trigger
- Algo trail: confirm (e.g., = 2%) or (fixed price spread)
Step 3: Verify after writes
- After : run to confirm order is live or if market order
- After : run or to confirm
- After : run to confirm position size is 0
- After algo place: run or to confirm algo is active
- After cancel: run / to confirm order is gone
CLI Command Reference
Order Type Reference
| Description | Requires |
|---|
| Fill immediately at best price | No |
| Fill at specified price or better | Yes |
| Limit order; cancelled if it would be a taker | Yes |
| Fill entire order immediately or cancel | Yes |
| Fill what's available immediately, cancel rest | Yes |
| Algo: single TP or SL trigger | No (set trigger px) |
| Algo: TP + SL together (one cancels other) | No (set both trigger px) |
| Trailing stop (swap only) | No (set callback) |
Spot — Place Order
bash
okx spot place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
[--px <price>] [--json]
| Param | Required | Default | Description |
|---|
| Yes | - | Spot instrument (e.g., ) |
| Yes | - | or |
| Yes | - | , , , , |
| Yes | - | Order size in base currency (e.g., BTC amount) |
| Cond. | - | Price — required for , , , |
Spot — Cancel Order
bash
okx spot cancel --instId <id> --ordId <id> [--json]
Spot — Amend Order
bash
okx spot amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of
or
.
Spot — Place Algo (TP/SL)
bash
okx spot algo place --instId <id> --side <buy|sell> --ordType <oco|conditional> --sz <n> \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--json]
| Param | Required | Default | Description |
|---|
| Cond. | - | Take-profit trigger price |
| Cond. | - | TP order price; use for market execution |
| Cond. | - | Stop-loss trigger price |
| Cond. | - | SL order price; use for market execution |
For
: provide both TP and SL params. For
: provide only TP or only SL.
Spot — Amend Algo
bash
okx spot algo amend --instId <id> --algoId <id> \
[--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
[--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]
Spot — Cancel Algo
bash
okx spot algo cancel --instId <id> --algoId <id> [--json]
Spot — List Orders
bash
okx spot orders [--instId <id>] [--history] [--json]
| Flag | Effect |
|---|
| (default) | Open/pending orders |
| Historical (filled, cancelled) orders |
Spot — Get Order
bash
okx spot get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns:
,
,
,
,
,
,
,
,
,
.
Spot — Fills
bash
okx spot fills [--instId <id>] [--ordId <id>] [--json]
Spot — Algo Orders
bash
okx spot algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
Returns:
,
, type,
,
,
,
,
.
Swap — Place Order
bash
okx swap place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--px <price>] [--json]
| Param | Required | Default | Description |
|---|
| Yes | - | Swap instrument (e.g., ) |
| Yes | - | or |
| Yes | - | , , , , |
| Yes | - | Number of contracts |
| Yes | - | or |
| Cond. | - | or — required in hedge mode |
| Cond. | - | Price — required for limit orders |
Swap — Cancel Order
bash
okx swap cancel --instId <id> --ordId <id> [--json]
Swap — Amend Order
bash
okx swap amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
Swap — Close Position
bash
okx swap close --instId <id> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--autoCxl] [--json]
| Param | Required | Default | Description |
|---|
| Yes | - | Swap instrument |
| Yes | - | or |
| Cond. | - | or — required in hedge mode |
| No | false | Auto-cancel pending orders before closing |
Closes the entire position at market price.
Swap — Set Leverage
bash
okx swap leverage --instId <id> --lever <n> --mgnMode <cross|isolated> \
[--posSide <long|short>] [--json]
| Param | Required | Default | Description |
|---|
| Yes | - | Swap instrument |
| Yes | - | Leverage multiplier (e.g., ) |
| Yes | - | or |
| Cond. | - | or — required for isolated mode in hedge mode |
Swap — Get Leverage
bash
okx swap get-leverage --instId <id> --mgnMode <cross|isolated> [--json]
Swap — Place Algo (TP/SL)
bash
okx swap algo place --instId <id> --side <buy|sell> --ordType <oco|conditional> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--reduceOnly] \
[--tpTriggerPx <p>] [--tpOrdPx <p|-1>] \
[--slTriggerPx <p>] [--slOrdPx <p|-1>] \
[--json]
: close-only; will not open a new position if one doesn't exist.
Swap — Place Trailing Stop
bash
okx swap algo trail --instId <id> --side <buy|sell> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--reduceOnly] \
[--callbackRatio <ratio>] [--callbackSpread <spread>] \
[--activePx <price>] \
[--json]
| Param | Required | Default | Description |
|---|
| Cond. | - | Trailing callback as a ratio (e.g., = 2%); use this or |
| Cond. | - | Trailing callback as fixed price distance |
| No | - | Price at which trailing stop becomes active |
Swap — Amend Algo
bash
okx swap algo amend --instId <id> --algoId <id> \
[--newSz <n>] [--newTpTriggerPx <p>] [--newTpOrdPx <p>] \
[--newSlTriggerPx <p>] [--newSlOrdPx <p>] [--json]
Swap — Cancel Algo
bash
okx swap algo cancel --instId <id> --algoId <id> [--json]
Swap — List Orders
bash
okx swap orders [--instId <id>] [--history] [--json]
Swap — Get Order
bash
okx swap get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns:
,
,
,
,
,
,
,
,
,
,
.
Swap — Positions
bash
okx swap positions [<instId>] [--json]
Returns:
,
,
,
,
,
,
. Only non-zero positions.
Swap — Fills
bash
okx swap fills [--instId <id>] [--ordId <id>] [--archive] [--json]
: access older fills beyond the default window.
Swap — Algo Orders
bash
okx swap algo orders [--instId <id>] [--history] [--ordType <type>] [--json]
Futures — Place Order
bash
okx futures place --instId <id> --side <buy|sell> --ordType <type> --sz <n> \
--tdMode <cross|isolated> \
[--posSide <long|short>] [--px <price>] [--reduceOnly] [--json]
format:
(delivery date suffix).
Futures — Cancel Order
bash
okx futures cancel --instId <id> --ordId <id> [--json]
Futures — List Orders
bash
okx futures orders [--instId <id>] [--status <open|history|archive>] [--json]
| Effect |
|---|
| Active/pending orders (default) |
| Recent completed/cancelled |
| Older history |
Futures — Positions
bash
okx futures positions [<instId>] [--json]
Futures — Fills
bash
okx futures fills [--instId <id>] [--ordId <id>] [--archive] [--json]
Futures — Get Order
bash
okx futures get --instId <id> [--ordId <id>] [--json]
Option — Get Instruments (Option Chain)
bash
okx option instruments --uly <underlying> [--expTime <YYMMDD>] [--json]
| Param | Required | Description |
|---|
| Yes | Underlying, e.g. or |
| No | Filter by expiry date, e.g. |
Returns:
,
,
,
(strike),
(C/P),
.
Run this
before placing any option order to get the exact
.
Option — Get Greeks
bash
okx option greeks --uly <underlying> [--expTime <YYMMDD>] [--json]
Returns IV (
) and BS Greeks (
,
,
,
) plus
for each contract.
Option — Place Order
bash
okx option place --instId <id> --side <buy|sell> --ordType <type> \
--tdMode <cash|cross|isolated> --sz <n> \
[--px <price>] [--reduceOnly] [--clOrdId <id>] [--json]
| Param | Required | Default | Description |
|---|
| Yes | - | e.g. (call) or (put) |
| Yes | - | or |
| Yes | - | , , , , |
| Yes | - | = buyer (full premium); / = seller (margin) |
| Yes | - | Number of contracts |
| Cond. | - | Required for , , , |
| No | false | Close-only; do not open a new position |
tdMode rules:
- Buyer (): always use — pay full premium, no margin call risk
- Seller (): use or — margin required, liquidation risk
Option — Cancel Order
bash
okx option cancel --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Option — Amend Order
bash
okx option amend --instId <id> [--ordId <id>] [--clOrdId <id>] \
[--newSz <n>] [--newPx <p>] [--json]
Must provide at least one of
or
.
Option — Batch Cancel
bash
okx option batch-cancel --orders '<JSON>' [--json]
is a JSON array of up to 20 objects, each
{"instId":"...","ordId":"..."}
:
bash
okx option batch-cancel --orders '[{"instId":"BTC-USD-250328-95000-C","ordId":"123"},{"instId":"BTC-USD-250328-90000-P","ordId":"456"}]'
Option — List Orders
bash
okx option orders [--instId <id>] [--uly <underlying>] [--history] [--archive] [--json]
| Flag | Effect |
|---|
| (default) | Live/pending orders |
| Historical (7d) |
| Older archive (3mo) |
Option — Get Order
bash
okx option get --instId <id> [--ordId <id>] [--clOrdId <id>] [--json]
Returns:
,
,
,
,
,
,
,
,
,
.
Option — Positions
bash
okx option positions [--instId <id>] [--uly <underlying>] [--json]
Returns:
,
,
,
,
,
,
,
,
. Only non-zero positions shown.
Option — Fills
bash
okx option fills [--instId <id>] [--ordId <id>] [--archive] [--json]
: access fills beyond the default 3-day window (up to 3 months).
MCP Tool Reference
| Tool | Description |
|---|
| Place spot order |
| Cancel spot order |
| Amend spot order |
| Place spot TP/SL algo |
| Amend spot algo |
| Cancel spot algo |
| List spot orders |
| Get single spot order |
| Spot fill history |
| List spot algo orders |
| Place swap order |
| Cancel swap order |
| Amend swap order |
| Close swap position |
| Set swap leverage |
| Place swap TP/SL algo |
swap_place_move_stop_order
| Place swap trailing stop |
| Amend swap algo |
| Cancel swap algo |
| Swap positions |
| List swap orders |
| Get single swap order |
| Swap fill history |
| Get swap leverage |
| List swap algo orders |
| Place futures order |
| Cancel futures order |
| List futures orders |
| Futures positions |
| Futures fill history |
| Get single futures order |
| Option chain (list available contracts) |
| IV and Greeks by underlying |
| Place option order |
| Cancel option order |
| Amend option order |
| Batch cancel up to 20 option orders |
| List option orders |
| Get single option order |
| Option positions with live Greeks |
| Option fill history |
Input / Output Examples
"Buy 0.05 BTC at market"
bash
okx spot place --instId BTC-USDT --side buy --ordType market --sz 0.05
# → Order placed: 7890123456 (OK)
"Set a limit sell for 0.1 ETH at $3500"
bash
okx spot place --instId ETH-USDT --side sell --ordType limit --sz 0.1 --px 3500
# → Order placed: 7890123457 (OK)
"Show my open spot orders"
bash
okx spot orders
# → table: ordId, instId, side, type, price, size, filled, state
"Long 10 contracts BTC perp at market (cross margin)"
bash
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 10 \
--tdMode cross --posSide long
# → Order placed: 7890123458 (OK)
"Set take profit at $105k and stop loss at $88k on BTC perp long"
bash
okx swap algo place --instId BTC-USDT-SWAP --side sell --ordType oco --sz 10 \
--tdMode cross --posSide long \
--tpTriggerPx 105000 --tpOrdPx -1 \
--slTriggerPx 88000 --slOrdPx -1
# → Algo order placed: ALGO456789 (OK)
"Close my ETH perp position"
bash
okx swap close --instId ETH-USDT-SWAP --mgnMode cross --posSide long
# → Position closed: ETH-USDT-SWAP long
"Set BTC perp leverage to 5x (cross)"
bash
okx swap leverage --instId BTC-USDT-SWAP --lever 5 --mgnMode cross
# → Leverage set: 5x BTC-USDT-SWAP
"Place a 2% trailing stop on my BTC perp long"
bash
okx swap algo trail --instId BTC-USDT-SWAP --side sell --sz 10 \
--tdMode cross --posSide long --callbackRatio 0.02
# → Trailing stop placed: TRAIL123 (OK)
"Show my open swap positions"
bash
okx swap positions
# → table: instId, side, size, avgPx, upl, uplRatio, lever
"What are my recent fill trades for BTC spot?"
bash
okx spot fills --instId BTC-USDT
# → table: instId, side, fillPx, fillSz, fee, ts
"Show me the BTC option chain expiring March 28"
bash
okx option instruments --uly BTC-USD --expTime 250328
# → table: instId, expTime, stk, optType (C/P), state
"What's the IV and delta for BTC options expiring March 28?"
bash
okx option greeks --uly BTC-USD --expTime 250328
# → table: instId, delta, gamma, theta, vega, iv (markVol), markPx
"Buy 1 BTC call at strike 95000 expiring March 28, limit at 0.005 BTC"
bash
okx option place --instId BTC-USD-250328-95000-C \
--side buy --ordType limit --tdMode cash --sz 1 --px 0.005
# → Order placed: 7890123460 (OK)
"Show my open option positions"
bash
okx option positions
# → table: instId, posSide, pos, avgPx, upl, delta, gamma, theta, vega
Edge Cases
Spot
- Market order size: is in base currency (e.g., BTC amount), not USDT
- Insufficient balance: check
okx-cex-portfolio account balance
before placing
- Price not required: orders don't need ; / / / do
- Algo oco: provide both and ; price means market execution at trigger
- Fills vs orders: shows executed trades; shows all orders including cancelled
Swap / Perpetual
- posSide: required in hedge mode (); omit in net mode. Check for
- tdMode: use for cross-margin, for isolated margin
- Close position: closes the entire position; to partial close, use with a reduce-only algo
- Leverage: max leverage varies by instrument and account level; exchange rejects if exceeded
- Trailing stop: use either (relative, e.g., ) or (absolute price), not both
- Algo on close side: always set opposite to position (e.g., long position → sell algo)
Futures / Delivery
- instId format: delivery futures use date suffix: for March 28, 2025 expiry
- Expiry: futures expire on the delivery date — all positions auto-settle; do not hold through expiry unless intended
- No swap-specific features: futures don't have trailing stops or — use + for adjustments
Options
- instId format:
{uly}-{YYMMDD}-{strike}-{C|P}
— e.g. ; always run okx option instruments --uly BTC-USD
first to confirm the exact contract exists
- tdMode: buyers always use (full premium paid upfront, no liquidation); sellers use or (margin required, liquidation risk)
- sz unit: number of contracts (1 BTC option contract = 0.1 BTC on OKX); is quoted in BTC (e.g. = 0.005 BTC premium per contract)
- Expiry: options expire at 08:00 UTC on the expiry date; in-the-money options are auto-exercised; do not hold through expiry unless intended
- No TP/SL algo on options: the / commands do not apply to option positions; manage risk by cancelling/amending option orders directly
- Greeks in positions: returns live portfolio Greeks (, , etc.) from the account's position-level calculation, while returns BS model Greeks per contract
Global Notes
- All write commands require valid credentials in or env vars
- switches between multiple account configurations
- returns raw OKX API v5 response
- flag enables simulated trading with paper funds
- Rate limit: 60 order operations per 2 seconds per UID
- Batch operations (batch cancel, batch amend) are available via MCP tools directly if needed
- Position mode ( vs ) affects whether is required
- Spot is base currency; swap/futures is number of contracts