fintool — 金融交易技能 是做什麼的?
一套用於智慧市場分析與跨交易所交易的 CLI 工具組。每個交易所對應一個單獨的二進位檔案。
工具
| 二進位檔案 | 用途 | 路徑 |
|---|---|---|
fintool | 市場情報(報價、新聞、SEC 文件) | {baseDir}/scripts/fintool |
hyperliquid | Hyperliquid 交易(現貨、合約、HIP-3、充值) | {baseDir}/scripts/hyperliquid |
binance | Binance 交易(現貨、合約、充值) | {baseDir}/scripts/binance |
coinbase | Coinbase 交易(現貨、充值) | {baseDir}/scripts/coinbase |
okx | OKX 交易(現貨、合約、充值、提現) | {baseDir}/scripts/okx |
polymarket | Polymarket 預測市場 | {baseDir}/scripts/polymarket |
backtest | 歷史模擬 + 未來 PnL(無需金鑰) | {baseDir}/scripts/backtest |
- 設定檔:
~/.fintool/config.toml - 模式: 一律使用 JSON 模式 —
<binary> --json '<JSON>'。所有輸入與輸出均為結構化 JSON。 - 無
exchange欄位: 每個二進位檔案處理一個交易所,不需"exchange"參數。
設定檢查(必做 — 請先執行此步驟)
執行任何指令前,請確認使用者的設定:
cat ~/.fintool/config.toml 2>/dev/null
如果檔案不存在,請執行:
{baseDir}/scripts/fintool --json '{"command":"init"}'
檢查以下需求:
-
OpenAI API 金鑰 — 用於增強報價(趨勢/動能分析)。
- 尋找
[api_keys]區段中未被註解的openai_api_key = "sk-..." - 如果遺失:要求使用者提供 OpenAI API 金鑰,或告知將其加入
~/.fintool/config.toml的[api_keys]區段
- 尋找
-
至少一個交易所 — 交易指令需要。
- Hyperliquid:
[wallet]中的private_key或wallet_json+wallet_passcode(現貨 + 合約) - Binance:
[api_keys]中的binance_api_key+binance_api_secret(現貨 + 合約) - Coinbase:
[api_keys]中的coinbase_api_key+coinbase_api_secret(僅現貨) - OKX:
[api_keys]中的okx_api_key+okx_secret_key+okx_passphrase(現貨 + 合約) - Polymarket: 使用
wallet.private_key(與 Hyperliquid 相同)進行預測市場交易 - 如果未設定任何交易所:詢問使用者想使用哪個交易所,並要求提供憑證。
- Hyperliquid:
例外情況 — backtest:回測二進位檔案 不需任何設定 — 無 API 金鑰、無錢包。它使用公開的 Yahoo Finance 與 CoinGecko 資料。可以立即使用。
如果使用者提供憑證,直接編輯 ~/.fintool/config.toml 將其加入。
交易所功能對照表
| 功能 | hyperliquid | binance | coinbase | okx | polymarket | backtest |
|---|---|---|---|---|---|---|
| 現貨訂單 | 買、賣 | 買、賣 | 買、賣 | 買、賣 | — | 模擬買/賣 |
| 合約訂單 | 合約買/賣 | 合約買/賣 | — | 合約買/賣 | — | 模擬合約買/賣 |
| 預測市場 | — | — | — | — | 買、賣、清單、報價 | — |
| 訂單簿 | 現貨 + 合約 | 現貨 + 合約 | 現貨 | 現貨 + 合約 | — | — |
| 充值 | Unit + Across | API | API | API | 跨鏈橋 | — |
| 提現 | Bridge2 + Unit + Across | API | API | API | 跨鏈橋 | — |
| 轉帳 | 現貨 ↔ 合約 ↔ dex | 現貨 ↔ 期貨 | — | 資金帳戶 ↔ 交易帳戶 | — | — |
| 餘額 | balance | balance | balance | balance | balance | 模擬 |
| 未成交訂單 | orders | orders | orders | orders | — | — |
| 取消訂單 | cancel | cancel | cancel | cancel | — | — |
| 持倉 | positions | positions | — | positions | positions | 模擬 |
| 資金費率 | — | — | — | 合約 funding_rate | — | — |
| 歷史報價 | — | — | — | — | — | quote |
| 未來 PnL | — | — | — | — | — | +1d/+2d/+4d/+7d |
| SEC 文件(日期查詢) | — | — | — | — | — | report list/annual/quarterly |
錯誤處理
- 所有錯誤都以
{"error": "..."}格式回傳。請檢查每個回應中是否有error鍵。 - 如果指令因 餘額不足 或 無效的產品代碼 而失敗,請清楚轉達錯誤訊息。
- 如果交易所 未設定,請告知使用者需要哪些憑證,並提供將其加入設定檔的選項。
JSON 指令參考
市場資料(fintool)
// fintool --json '<JSON>'
{"command": "quote", "symbol": "BTC"}
{"command": "news", "symbol": "AAPL"}
{"command": "report_list", "symbol": "AAPL", "limit": 5}
{"command": "report_annual", "symbol": "AAPL"}
{"command": "report_quarterly", "symbol": "AAPL"}
{"command": "report_get", "symbol": "AAPL", "accession": "0000320193-24-000123"}
Hyperliquid 交易(hyperliquid)
// hyperliquid --json '<JSON>'
{"command": "address"}
{"command": "buy", "symbol": "ETH", "amount": 0.1, "price": 3800}
{"command": "sell", "symbol": "ETH", "amount": 0.1, "price": 4000}
{"command": "orderbook", "symbol": "HYPE"}
{"command": "orderbook", "symbol": "BTC", "levels": 10}
{"command": "quote", "symbol": "ETH"}
{"command": "perp_orderbook", "symbol": "BTC"}
{"command": "perp_buy", "symbol": "ETH", "amount": 0.5, "price": 3800}
{"command": "perp_sell", "symbol": "BTC", "amount": 0.01, "price": 100000}
{"command": "perp_buy", "symbol": "ETH", "amount": 0.5, "price": 3900, "close": true}
{"command": "perp_sell", "symbol": "BTC", "amount": 0.01, "price": 95000, "close": true}
{"command": "perp_leverage", "symbol": "ETH", "leverage": 5, "cross": true}
{"command": "perp_set_mode", "mode": "unified"}
{"command": "balance"}
{"command": "positions"}
{"command": "orders"}
{"command": "orders", "symbol": "BTC"}
{"command": "cancel", "order_id": "BTC:91490942"}
{"command": "deposit", "asset": "ETH", "amount": 0.01}
{"command": "deposit", "asset": "ETH", "amount": 0.05, "dry_run": true}
{"command": "deposit", "asset": "BTC", "amount": 0.001}
{"command": "deposit", "asset": "USDC", "amount": 100, "from": "base"}
{"command": "deposit", "asset": "USDC", "amount": 100, "from": "ethereum", "dry_run": true}
{"command": "withdraw", "asset": "USDC", "amount": 100}
{"command": "withdraw", "asset": "USDC", "amount": 100, "to": "base"}
{"command": "withdraw", "asset": "ETH", "amount": 0.5}
{"command": "transfer", "asset": "USDT0", "amount": 50, "from": "spot", "to": "cash"}
{"command": "transfer", "asset": "USDT0", "amount": 50, "from": "cash", "to": "spot"}
{"command": "bridge_status"}
Binance 交易(binance)
// binance --json '<JSON>'
{"command": "buy", "symbol": "BTC", "amount": 0.01, "price": 95000}
{"command": "sell", "symbol": "BTC", "amount": 0.01, "price": 100000}
{"command": "orderbook", "symbol": "BTC"}
{"command": "perp_buy", "symbol": "ETH", "amount": 0.5, "price": 3800}
{"command": "perp_sell", "symbol": "ETH", "amount": 0.5, "price": 4000, "close": true}
{"command": "perp_leverage", "symbol": "ETH", "leverage": 5}
{"command": "balance"}
{"command": "positions"}
{"command": "orders"}
{"command": "cancel", "order_id": "binance_spot:BTCUSDT:123"}
{"command": "deposit", "asset": "USDC", "from": "ethereum"}
{"command": "withdraw", "asset": "USDC", "amount": 100, "to": "0x...", "network": "ethereum"}
OKX 交易(okx)
// okx --json '<JSON>'
{"command": "quote", "symbol": "BTC"}
{"command": "buy", "symbol": "ETH", "amount": 0.01, "price": 2000}
{"command": "sell", "symbol": "ETH", "amount": 0.01, "price": 2100}
{"command": "orderbook", "symbol": "BTC"}
{"command": "perp_orderbook", "symbol": "ETH"}
{"command": "perp_buy", "symbol": "ETH", "amount": 0.1, "price": 2000}
{"command": "perp_sell", "symbol": "ETH", "amount": 0.1, "price": 2100, "close": true}
{"command": "perp_leverage", "symbol": "ETH", "leverage": 5, "cross": true}
{"command": "perp_funding_rate", "symbol": "BTC"}
{"command": "balance"}
{"command": "positions"}
{"command": "orders"}
{"command": "cancel", "inst_id": "BTC-USDT", "order_id": "12345"}
{"command": "deposit", "asset": "USDC", "network": "base"}
{"command": "deposit", "asset": "ETH", "network": "ethereum"}
{"command": "withdraw", "asset": "USDC", "amount": 100, "network": "base"}
{"command": "withdraw", "asset": "USDC", "amount": 100, "to": "0x...", "network": "ethereum"}
{"command": "transfer", "asset": "USDT", "amount": 100, "from": "funding", "to": "trading"}
{"command": "transfer", "asset": "USDT", "amount": 100, "from": "trading", "to": "funding"}
OKX 備註:
quote和orderbook為公開端點 — 無需 API 金鑰。- OKX 使用產品代碼:現貨為
BTC-USDT,合約為BTC-USDT-SWAP。CLI 會自動從符號進行格式化。 - OKX 有
funding(用於充值/提現)和trading(統一帳戶)帳戶。使用transfer在兩者之間移動。 - 如果未指定
--fee,提現費用會自動取得。 - 取消訂單需要同時提供
inst_id(例如BTC-USDT)和order_id。
Coinbase 交易(coinbase)
// coinbase --json '<JSON>'
{"command": "buy", "symbol": "ETH", "amount": 0.1, "price": 3800}
{"command": "sell", "symbol": "ETH", "amount": 0.1, "price": 4000}
{"command": "orderbook", "symbol": "BTC"}
{"command": "balance"}
{"command": "orders"}
{"command": "cancel", "order_id": "coinbase:uuid-here"}
{"command": "deposit", "asset": "ETH"}
{"command": "withdraw", "asset": "USDC", "amount": 100, "to": "0x..."}
Polymarket 預測市場(polymarket)
// polymarket --json '<JSON>'
{"command": "list", "query": "bitcoin"}
{"command": "list", "query": "election", "limit": 5}
{"command": "list", "query": "bitcoin", "min_end_days": 7}
{"command": "list", "query": "bitcoin", "min_end_days": 0}
{"command": "quote", "market": "will-bitcoin-hit-100k"}
{"command": "buy", "market": "will-bitcoin-hit-100k", "outcome": "yes", "amount": 10, "price": 0.65}
{"command": "sell", "market": "will-bitcoin-hit-100k", "outcome": "yes", "amount": 10, "price": 0.70}
{"command": "positions"}
{"command": "balance"}
{"command": "deposit", "amount": 100, "from": "base"}
{"command": "withdraw", "amount": 50}
備註:
list預設min_end_days: 3,會過濾掉 3 天內結束的市場(該類市場賠率通常接近 1:0)。設為0可查看所有市場。list和quote為唯讀操作,不需 Polymarket 憑證。- 交易指令(
buy、sell、deposit、withdraw)需要設定檔中的wallet.private_key。 - 使用從
list取得的市場 slug 或條件 ID 作為market值。
回測(backtest)
重要:backtest 二進位檔案需要以 --at YYYY-MM-DD 作為 CLI 參數(不在 JSON 主體中)。無需 API 金鑰或錢包。
# backtest --at <DATE> --json '<JSON>'
// 歷史價格
{"command": "quote", "symbol": "BTC"}
{"command": "quote", "symbol": "AAPL"}
{"command": "quote", "symbol": "GOLD"}
// 模擬現貨交易 — 回傳未來 PnL(+1/+2/+4/+7 天)
{"command": "buy", "symbol": "ETH", "amount": 0.5}
{"command": "buy", "symbol": "AAPL", "amount": 10, "price": 237}
{"command": "sell", "symbol": "BTC", "amount": 0.01, "price": 105000}
// 模擬合約交易 — 回傳槓桿後的未來 PnL
{"command": "perp_leverage", "symbol": "ETH", "leverage": 5}
{"command": "perp_buy", "symbol": "ETH", "amount": 0.5, "price": 3300}
{"command": "perp_sell", "symbol": "BTC", "amount": 0.01, "price": 100000}
// 依日期篩選的 SEC 文件
{"command": "report_list", "symbol": "AAPL", "limit": 5}
{"command": "report_annual", "symbol": "TSLA"}
{"command": "report_quarterly", "symbol": "AAPL"}
// 資產組合管理
{"command": "balance"}
{"command": "positions"}
{"command": "reset"}
// 新聞存根(歷史新聞不可用)
{"command": "news", "symbol": "BTC"}
備註:
- 如果買/賣時省略
price,會自動使用--at日期的歷史收盤價。 - 資產組合狀態會持久化到
~/.fintool/backtest_portfolio.json。使用reset清除。 balance會回傳cashBalance(僅現貨交易)、positions、totalTrades、leverageSettings。- 交易輸出包含一個
pnl陣列,其中有每個偏移時間點的未來價格、美元 PnL 與百分比 PnL。 - 資料來源:Yahoo Finance(股票、加密貨幣、大宗商品、指數),加密貨幣會以 CoinGecko 作為備援。
工作流程
工作流程 1:現貨交易
目標:研究某個產品代碼並執行現貨交易。
步驟 1 — 含分析的報價:
{baseDir}/scripts/fintool --json '{"command":"quote","symbol":"BTC"}'
回傳:價格、24h/7d/30d 變化、趨勢(看漲/看跌/中性)、動能、成交量分析、摘要。
步驟 1b — 檢查訂單簿深度與價差:
{baseDir}/scripts/hyperliquid --json '{"command":"orderbook","symbol":"BTC"}'
回傳:買入報價、賣出報價、價差、價差百分比、中間價。用於在交易前評估流動性。
步驟 2 — 查看近期新聞:
{baseDir}/scripts/fintool --json '{"command":"news","symbol":"BTC"}'
步驟 3 — 執行交易:
# 在 Hyperliquid 以最高價格 $95000 買入 0.01 BTC
{baseDir}/scripts/hyperliquid --json '{"command":"buy","symbol":"BTC","amount":0.01,"price":95000}'
# 或在 Binance
{baseDir}/scripts/binance --json '{"command":"buy","symbol":"BTC","amount":0.01,"price":95000}'
# 或在 Coinbase
{baseDir}/scripts/coinbase --json '{"command":"buy","symbol":"BTC","amount":0.01,"price":95000}'
# 或在 OKX
{baseDir}/scripts/okx --json '{"command":"buy","symbol":"BTC","amount":0.01,"price":95000}'
步驟 4 — 確認:
{baseDir}/scripts/hyperliquid --json '{"command":"orders"}'
{baseDir}/scripts/hyperliquid --json '{"command":"balance"}'
工作流程 2:永續合約交易
目標:研究並透過永續合約建立槓桿部位。
步驟 1 — 取得含資金費率/未平倉量的報價:
{baseDir}/scripts/hyperliquid --json '{"command":"quote","symbol":"ETH"}'
步驟 1b — 檢查合約訂單簿深度與價差:
{baseDir}/scripts/hyperliquid --json '{"command":"perp_orderbook","symbol":"ETH"}'
步驟 2 — 查看現貨價格以獲取背景資訊:
{baseDir}/scripts/fintool --json '{"command":"quote","symbol":"ETH"}'
步驟 3 — 檢查新聞:
…(此處為截斷內容)