OKX CEX Earn CLI
Prerequisites
- Install CLI:
bash
npm install -g @okx_ai/okx-trade-cli
- Configure credentials:
bash
okx config add-profile AK=<your_api_key> SK=<your_secret_key> PP=<your_passphrase> name=live
# or interactive wizard:
okx config init
- Verify:
okx --profile live earn savings balance
Credential & Profile Check
Run
before any authenticated command.
- Error or no configuration → stop, guide user to run , wait for completion.
- Credentials configured → proceed.
OKX Earn does not support demo mode. Always use
silently — don't mention it unless there's an error.
On 401 errors: stop immediately, tell the user their credentials may be invalid or expired, guide them to update
(do NOT ask them to paste credentials into chat), then verify with
and retry.
Skill Routing
| User intent | Route to skill |
|---|
| Market prices, tickers, candles | |
| Spot / swap / futures / options orders | |
| Account balance, positions, transfers | |
| Grid / DCA trading bots | |
| Simple Earn, On-chain Earn, or Dual Investment (双币赢) | This skill |
Command Index
earn savings — Simple Earn (7 commands)
| Command | Type | Auth | Description |
|---|
earn savings balance [ccy]
| READ | Required | Savings balance (all or specific currency) |
earn savings purchase --ccy --amt
| WRITE | Required | Subscribe funds to Simple Earn |
earn savings redeem --ccy --amt
| WRITE | Required | Redeem funds from Simple Earn |
earn savings set-rate --ccy --rate
| WRITE | Required | Set minimum lending rate |
earn savings lending-history
| READ | Required | Lending records with earnings detail |
earn savings rate-summary [ccy]
| READ | Required | Market lending rate summary |
earn savings rate-history
| READ | Required | Historical lending rates |
For full command syntax, rate field semantics, and confirmation templates, read
{baseDir}/references/savings-commands.md
.
earn dcd — Dual Investment / 双币赢 (10 commands)
| Command | Type | Auth | Description |
|---|
| READ | Required | Available DCD currency pairs |
| READ | Required | Active products with filters |
earn dcd quote --productId --sz --notionalCcy
| READ | Required | Request real-time quote (TTL 30s) |
| WRITE | Required | Execute an existing quote |
earn dcd quote-and-buy --productId --sz --notionalCcy
| WRITE | Required | Quote + execute in one step (AI preferred) |
| READ | Required | Quick state check for a single order |
| READ | Required | Full order list / history |
earn dcd redeem-quote --ordId
| READ | Required | Early redemption preview (TTL 15s) |
earn dcd redeem-execute --ordId
| WRITE | Required | Re-quote + execute redemption (AI preferred) |
earn dcd redeem --ordId --quoteId
| WRITE | Required | Execute redemption with existing quoteId (low-level) |
DCD does
not support demo/simulated trading mode. Always use
.
For full command syntax, product concepts, and error codes, read
{baseDir}/references/dcd-commands.md
.
earn onchain — On-chain Earn (6 commands)
| Command | Type | Auth | Description |
|---|
| READ | Required | Available staking/DeFi products |
earn onchain purchase --productId --ccy --amt
| WRITE | Required | Subscribe to on-chain product |
earn onchain redeem --ordId --protocolType
| WRITE | Required | Redeem on-chain investment |
earn onchain cancel --ordId --protocolType
| WRITE | Required | Cancel pending on-chain order |
| READ | Required | Active on-chain orders |
| READ | Required | Historical on-chain orders |
For full command syntax and parameters, read
{baseDir}/references/onchain-commands.md
.
Operation Flow
Step 0 — Credential & Profile Check
Before any authenticated command: see
Credential & Profile Check. Always use
silently.
Step 1 — Identify earn intent
Simple Earn / On-chain Earn:
- Query balance / history / rates → READ command, proceed directly.
- Subscribe / redeem / set-rate / on-chain purchase → WRITE command, go to Step 2.
When user asks to view "earn positions" or "赚币持仓" (regardless of whether they mention DCD explicitly), query all three simultaneously:
bash
okx --profile live earn savings balance --json # Simple Earn
okx --profile live earn onchain orders --json # On-chain Earn
okx --profile live earn dcd orders --json # Dual Investment (双币赢)
Only present sections that have actual holdings. For DCD: translate state codes using the table in
{baseDir}/references/dcd-commands.md
.
Dual Investment (DCD / 双币赢):
- Browse products / pairs → READ; when user specifies a currency, read
{baseDir}/references/workflows.md
(DCD browse flow) for the mandatory parallel pre-fetch before rendering the product table
- Subscribe (quote-and-buy) → WRITE → see
{baseDir}/references/workflows.md
(DCD subscribe flow)
- Early redeem → WRITE → see
{baseDir}/references/workflows.md
(DCD early redeem flow)
For multi-step workflows (idle fund analysis, subscribe + verify, redeem + transfer, on-chain subscribe), read
{baseDir}/references/workflows.md
.
Step 2 — Confirm write operation
For all WRITE commands, present a summary and wait for explicit confirmation.
"just do it" / "直接搞" is NOT valid confirmation — the user must see the summary first.
For Simple Earn confirmation dialog format, read
{baseDir}/references/savings-commands.md
. For On-chain confirmation, read
{baseDir}/references/onchain-commands.md
.
Step 3 — Execute and verify
After any purchase, verify based on product type:
- DCD succeeded → run , show only the matching order.
- On-chain purchase (response contains ) → run
earn onchain orders --json
, show only the matching order.
- Simple Earn purchase (no in response) → run
earn savings balance --ccy <ccy> --json
.
Simple Earn purchase: Run in parallel —
earn savings balance --ccy <ccy>
and
earn savings rate-history --ccy <ccy> --limit 1 --json
. For output format, read
{baseDir}/references/savings-commands.md
.
Simple Earn redeem: Run
earn savings balance --ccy <ccy>
to confirm updated balance. Inform user funds returned to funding account.
On-chain redeem: Query
to confirm state. Show
as estimated arrival time.
On-chain cancel: Query
after submission:
- Order gone from list → inform user: cancellation complete, funds returned to funding account.
- (cancelling) → inform user: cancellation in progress, funds will return to funding account shortly.
Global Notes
- Security: Never ask users to paste API keys or secrets into chat.
- Output: Always pass to list/query commands and render results as a Markdown table — never paste raw terminal output.
- Network errors: If commands fail with a connection error, prompt user to check VPN:
curl -I https://www.okx.com
- Language: Always respond in the user's language.
For number/time formatting and response structure conventions, read
{baseDir}/references/templates.md
.