Skip to content

Commit 1380f69

Browse files
juntaoclaude
andcommitted
feat: add OKX CLI binary with spot/perp trading, deposits, withdrawals
New `okx` binary supporting: - Spot trading (buy/sell with cash mode, BTC-USDT instrument format) - Perpetual futures (buy/sell with cross margin, BTC-USDT-SWAP format) - Leverage control, funding rate queries - Orderbook, quote (public, no auth needed) - Balance (trading + funding accounts), positions, orders, cancel - Deposit address lookup, withdrawal with auto fee detection - Funding ↔ trading account transfers - Full --json mode for programmatic use HMAC-SHA256 + base64 authentication matching OKX API spec. Configurable base URL (okx_base_url) for OKX US support. Signed-off-by: Michael Yuan <michael@secondstate.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 22efa45 commit 1380f69

20 files changed

Lines changed: 2696 additions & 68 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
./target/release/binance --help
4141
./target/release/coinbase --help
4242
./target/release/polymarket --help
43+
./target/release/okx --help
4344
4445
- name: Smoke test - init
4546
run: |

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99
contents: write
1010

1111
env:
12-
BINARIES: fintool hyperliquid binance coinbase polymarket
12+
BINARIES: fintool hyperliquid binance coinbase polymarket okx
1313

1414
jobs:
1515
build:

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ path = "src/bin/coinbase.rs"
3131
name = "polymarket"
3232
path = "src/bin/polymarket.rs"
3333

34+
[[bin]]
35+
name = "okx"
36+
path = "src/bin/okx.rs"
37+
3438
[dependencies]
3539
clap = { version = "4", features = ["derive"] }
3640
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
@@ -60,3 +64,4 @@ hmac = "0.12"
6064
rmp-serde = "1"
6165
sha2 = "0.10"
6266
uuid = { version = "1", features = ["v4"] }
67+
base64 = "0.22"

README.md

Lines changed: 140 additions & 44 deletions
Large diffs are not rendered by default.

config.toml.default

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ testnet = false
4141
# coinbase_api_key = "..."
4242
# coinbase_api_secret = "..."
4343

44+
# OKX API credentials — enables spot/perp trading on OKX
45+
# Sign up at https://www.okx.com/
46+
# okx_api_key = "..."
47+
# okx_secret_key = "..."
48+
# okx_passphrase = "..."
49+
# Custom base URL (default: https://www.okx.com)
50+
# For OKX US: https://app.okx.com
51+
# okx_base_url = "https://www.okx.com"
52+
4453
# Polymarket — prediction market trading on Polygon
4554
# Uses the [wallet] private_key for signing. Only signature_type is configurable.
4655
# [polymarket]

skills/SKILL.md

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: fintool
3-
description: "Financial trading CLIs — spot and perp trading on Hyperliquid, Binance, Coinbase. Prediction markets on Polymarket. Deposit and withdraw across chains. LLM-enriched price quotes with trend analysis. News and SEC filings. Use when: user asks about stock/crypto prices, wants to trade, deposit, withdraw, or check portfolio."
3+
description: "Financial trading CLIs — spot and perp trading on Hyperliquid, Binance, Coinbase, OKX. Prediction markets on Polymarket. Deposit and withdraw across chains. LLM-enriched price quotes with trend analysis. News and SEC filings. Use when: user asks about stock/crypto prices, wants to trade, deposit, withdraw, or check portfolio."
44
homepage: https://github.com/second-state/fintool
55
metadata: { "openclaw": { "emoji": "📈", "requires": { "bins": ["curl"] } } }
66
---
@@ -17,6 +17,7 @@ A suite of CLI tools for market intelligence and trading across multiple exchang
1717
| `hyperliquid` | Hyperliquid trading (spot, perp, HIP-3, deposits) | `{baseDir}/scripts/hyperliquid` |
1818
| `binance` | Binance trading (spot, perp, deposits) | `{baseDir}/scripts/binance` |
1919
| `coinbase` | Coinbase trading (spot, deposits) | `{baseDir}/scripts/coinbase` |
20+
| `okx` | OKX trading (spot, perp, deposits, withdrawals) | `{baseDir}/scripts/okx` |
2021
| `polymarket` | Polymarket prediction markets | `{baseDir}/scripts/polymarket` |
2122

2223
- **Config**: `~/.fintool/config.toml`
@@ -46,25 +47,28 @@ cat ~/.fintool/config.toml 2>/dev/null
4647
- **Hyperliquid**: `private_key` or `wallet_json` + `wallet_passcode` in `[wallet]` (spot + perps)
4748
- **Binance**: `binance_api_key` + `binance_api_secret` in `[api_keys]` (spot + perps)
4849
- **Coinbase**: `coinbase_api_key` + `coinbase_api_secret` in `[api_keys]` (spot only)
50+
- **OKX**: `okx_api_key` + `okx_secret_key` + `okx_passphrase` in `[api_keys]` (spot + perps)
4951
- **Polymarket**: Uses `wallet.private_key` (same as Hyperliquid) for prediction market trading
5052
- If none configured: Ask the user which exchange they want to use and request the credentials.
5153

5254
**If the user provides credentials**, edit `~/.fintool/config.toml` directly to add them.
5355

5456
## Exchange Capabilities
5557

56-
| Feature | `hyperliquid` | `binance` | `coinbase` | `polymarket` |
57-
|---------|---------------|-----------|------------|--------------|
58-
| Spot orders | buy, sell | buy, sell | buy, sell ||
59-
| Perp orders | perp buy/sell | perp buy/sell |||
60-
| Prediction markets |||| buy, sell, list, quote |
61-
| Orderbook | spot + perp | spot + perp | spot ||
62-
| Deposit | Unit + Across | API | API | bridge |
63-
| Withdraw | Bridge2 + Unit + Across | API | API | bridge |
64-
| Balance | balance | balance | balance | balance |
65-
| Open orders | orders | orders | orders ||
66-
| Cancel | cancel | cancel | cancel ||
67-
| Positions | positions | positions || positions |
58+
| Feature | `hyperliquid` | `binance` | `coinbase` | `okx` | `polymarket` |
59+
|---------|---------------|-----------|------------|-------|--------------|
60+
| Spot orders | buy, sell | buy, sell | buy, sell | buy, sell ||
61+
| Perp orders | perp buy/sell | perp buy/sell || perp buy/sell ||
62+
| Prediction markets ||||| buy, sell, list, quote |
63+
| Orderbook | spot + perp | spot + perp | spot | spot + perp ||
64+
| Deposit | Unit + Across | API | API | API | bridge |
65+
| Withdraw | Bridge2 + Unit + Across | API | API | API | bridge |
66+
| Transfer | spot ↔ perp ↔ dex | spot ↔ futures || funding ↔ trading ||
67+
| Balance | balance | balance | balance | balance | balance |
68+
| Open orders | orders | orders | orders | orders ||
69+
| Cancel | cancel | cancel | cancel | cancel ||
70+
| Positions | positions | positions || positions | positions |
71+
| Funding rate |||| perp funding_rate ||
6872

6973
## Error Handling
7074

@@ -139,6 +143,38 @@ cat ~/.fintool/config.toml 2>/dev/null
139143
{"command": "withdraw", "asset": "USDC", "amount": 100, "to": "0x...", "network": "ethereum"}
140144
```
141145

146+
### OKX Trading (`okx`)
147+
148+
```json
149+
// okx --json '<JSON>'
150+
{"command": "quote", "symbol": "BTC"}
151+
{"command": "buy", "symbol": "ETH", "amount": 0.01, "price": 2000}
152+
{"command": "sell", "symbol": "ETH", "amount": 0.01, "price": 2100}
153+
{"command": "orderbook", "symbol": "BTC"}
154+
{"command": "perp_orderbook", "symbol": "ETH"}
155+
{"command": "perp_buy", "symbol": "ETH", "amount": 0.1, "price": 2000}
156+
{"command": "perp_sell", "symbol": "ETH", "amount": 0.1, "price": 2100, "close": true}
157+
{"command": "perp_leverage", "symbol": "ETH", "leverage": 5, "cross": true}
158+
{"command": "perp_funding_rate", "symbol": "BTC"}
159+
{"command": "balance"}
160+
{"command": "positions"}
161+
{"command": "orders"}
162+
{"command": "cancel", "inst_id": "BTC-USDT", "order_id": "12345"}
163+
{"command": "deposit", "asset": "USDC", "network": "base"}
164+
{"command": "deposit", "asset": "ETH", "network": "ethereum"}
165+
{"command": "withdraw", "asset": "USDC", "amount": 100, "network": "base"}
166+
{"command": "withdraw", "asset": "USDC", "amount": 100, "to": "0x...", "network": "ethereum"}
167+
{"command": "transfer", "asset": "USDT", "amount": 100, "from": "funding", "to": "trading"}
168+
{"command": "transfer", "asset": "USDT", "amount": 100, "from": "trading", "to": "funding"}
169+
```
170+
171+
**OKX Notes:**
172+
- `quote` and `orderbook` are public endpoints — no API keys needed.
173+
- OKX uses instrument IDs: spot = `BTC-USDT`, perp = `BTC-USDT-SWAP`. The CLI auto-formats from symbol.
174+
- OKX has `funding` (for deposits/withdrawals) and `trading` (unified) accounts. Use `transfer` to move between them.
175+
- Withdrawal fee is auto-fetched if `--fee` is not specified.
176+
- Cancel requires both `inst_id` (e.g. `BTC-USDT`) and `order_id`.
177+
142178
### Coinbase Trading (`coinbase`)
143179

144180
```json
@@ -209,6 +245,9 @@ Returns: bids, asks, spread, spreadPct, midPrice. Use to assess liquidity before
209245

210246
# Or on Coinbase
211247
{baseDir}/scripts/coinbase --json '{"command":"buy","symbol":"BTC","amount":0.01,"price":95000}'
248+
249+
# Or on OKX
250+
{baseDir}/scripts/okx --json '{"command":"buy","symbol":"BTC","amount":0.01,"price":95000}'
212251
```
213252

214253
**Step 4 — Verify:**
@@ -260,7 +299,7 @@ Returns: bids, asks, spread, spreadPct, midPrice. Use to assess liquidity before
260299
```
261300
Use `"close": true` to ensure the order only reduces an existing position.
262301

263-
**Note**: Perps are available on `hyperliquid` and `binance`. Coinbase does not support perps.
302+
**Note**: Perps are available on `hyperliquid`, `binance`, and `okx`. Coinbase does not support perps.
264303

265304
### Workflow 3: Portfolio Overview
266305

@@ -279,6 +318,11 @@ Use `"close": true` to ensure the order only reduces an existing position.
279318
# Coinbase
280319
{baseDir}/scripts/coinbase --json '{"command":"balance"}'
281320

321+
# OKX
322+
{baseDir}/scripts/okx --json '{"command":"balance"}'
323+
{baseDir}/scripts/okx --json '{"command":"positions"}'
324+
{baseDir}/scripts/okx --json '{"command":"orders"}'
325+
282326
# Polymarket
283327
{baseDir}/scripts/polymarket --json '{"command":"balance"}'
284328
{baseDir}/scripts/polymarket --json '{"command":"positions"}'
@@ -311,10 +355,11 @@ Sends ETH from your wallet on Ethereum L1 to a Unit bridge deposit address. Mini
311355
```
312356
BTC and SOL cannot be bridged automatically. The command returns a Unit deposit address for manual transfer.
313357

314-
**Binance / Coinbase — get deposit address:**
358+
**Binance / Coinbase / OKX — get deposit address:**
315359
```bash
316360
{baseDir}/scripts/binance --json '{"command":"deposit","asset":"USDC","from":"ethereum"}'
317361
{baseDir}/scripts/coinbase --json '{"command":"deposit","asset":"ETH"}'
362+
{baseDir}/scripts/okx --json '{"command":"deposit","asset":"USDC","network":"base"}'
318363
```
319364

320365
**Polymarket — deposit USDC:**
@@ -333,10 +378,11 @@ BTC and SOL cannot be bridged automatically. The command returns a Unit deposit
333378
{baseDir}/scripts/hyperliquid --json '{"command":"withdraw","asset":"ETH","amount":0.5}'
334379
```
335380

336-
**Binance / Coinbase:**
381+
**Binance / Coinbase / OKX:**
337382
```bash
338383
{baseDir}/scripts/binance --json '{"command":"withdraw","asset":"USDC","amount":100,"to":"0x...","network":"ethereum"}'
339384
{baseDir}/scripts/coinbase --json '{"command":"withdraw","asset":"USDC","amount":100,"to":"0x..."}'
385+
{baseDir}/scripts/okx --json '{"command":"withdraw","asset":"USDC","amount":100,"network":"base"}'
340386
```
341387

342388
**Polymarket:**

skills/bootstrap.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ esac
4242
echo "Downloading ${ARTIFACT}..."
4343
curl -L -o /tmp/fintool.zip "${RELEASE_BASE}/${ARTIFACT}.zip"
4444
unzip -o /tmp/fintool.zip -d /tmp/fintool-extract
45-
BINARIES="fintool hyperliquid binance coinbase polymarket"
45+
BINARIES="fintool hyperliquid binance coinbase polymarket okx"
4646
for bin in $BINARIES; do
4747
src="/tmp/fintool-extract/${ARTIFACT}/${bin}"
4848
if [ -f "$src" ]; then
@@ -86,9 +86,13 @@ fi
8686
if grep -q '^coinbase_api_key\s*=' "$CONFIG" 2>/dev/null; then
8787
HAS_COINBASE=true
8888
fi
89+
HAS_OKX=false
90+
if grep -q '^okx_api_key\s*=' "$CONFIG" 2>/dev/null; then
91+
HAS_OKX=true
92+
fi
8993

90-
if [ "$HAS_HL" = false ] && [ "$HAS_BINANCE" = false ] && [ "$HAS_COINBASE" = false ]; then
91-
MISSING+=("At least one exchange (Hyperliquid wallet, Binance API keys, or Coinbase API keys)")
94+
if [ "$HAS_HL" = false ] && [ "$HAS_BINANCE" = false ] && [ "$HAS_COINBASE" = false ] && [ "$HAS_OKX" = false ]; then
95+
MISSING+=("At least one exchange (Hyperliquid wallet, Binance API keys, Coinbase API keys, or OKX API keys)")
9296
fi
9397

9498
if [ ${#MISSING[@]} -gt 0 ]; then
@@ -104,6 +108,7 @@ if [ ${#MISSING[@]} -gt 0 ]; then
104108
echo " • Hyperliquid (wallet): spot + perps"
105109
echo " • Binance (API key): spot + perps + options"
106110
echo " • Coinbase (API key): spot only"
111+
echo " • OKX (API key): spot + perps"
107112
else
108113
echo "✅ Configuration looks good!"
109114
fi

skills/install.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rm -rf /tmp/fintool-repo
2323
The bootstrap script will:
2424
1. Clone skill files to `~/.openclaw/skills/fintool/`
2525
2. Detect your platform (Linux x86_64/aarch64, macOS Apple Silicon)
26-
3. Download all binaries (fintool, hyperliquid, binance, coinbase, polymarket) from the latest GitHub release
26+
3. Download all binaries (fintool, hyperliquid, binance, coinbase, polymarket, okx) from the latest GitHub release
2727
4. Run `fintool init` to create `~/.fintool/config.toml` (never overwrites existing)
2828
5. Check config for required keys and tell you what's missing
2929

@@ -36,6 +36,7 @@ After installation, edit `~/.fintool/config.toml` to add your credentials:
3636
- **Hyperliquid**`private_key` or `wallet_json` + `wallet_passcode` in `[wallet]` (spot + perps)
3737
- **Binance**`binance_api_key` + `binance_api_secret` in `[api_keys]` (spot + perps + options)
3838
- **Coinbase**`coinbase_api_key` + `coinbase_api_secret` in `[api_keys]` (spot only)
39+
- **OKX**`okx_api_key` + `okx_secret_key` + `okx_passphrase` in `[api_keys]` (spot + perps)
3940

4041
Verify installation:
4142

@@ -57,7 +58,7 @@ If the bootstrap script fails:
5758
```bash
5859
mkdir -p ~/.openclaw/skills/fintool/scripts
5960
unzip fintool-<platform>.zip
60-
cp fintool-<platform>/{fintool,hyperliquid,binance,coinbase,polymarket} ~/.openclaw/skills/fintool/scripts/
61+
cp fintool-<platform>/{fintool,hyperliquid,binance,coinbase,polymarket,okx} ~/.openclaw/skills/fintool/scripts/
6162
chmod +x ~/.openclaw/skills/fintool/scripts/*
6263
```
6364
4. Copy the skill definition:

0 commit comments

Comments
 (0)