Communitygithub.com

fintool — 金融交易技能

一套用於智慧市場分析與跨交易所交易的 CLI 工具組,支援現貨、合約、預測市場、跨鏈轉帳與歷史回測。

fintool — 金融交易技能 是什麼?

fintool 是一個專為 AI 代理設計的金融交易技能套件,提供統一的 JSON 驅動 CLI 介面,可直接操作多個主要交易所。它涵蓋 Hyperliquid、Binance、Coinbase、OKX 的現貨與永續合約交易,Polymarket 的預測市場,以及基於 Yahoo Finance 和 CoinGecko 公開資料的歷史回測。每個交易所對應單獨的二進位檔案,輸入輸出均為結構化 JSON,適合 AI 代理自動化執行。技能亮點包括 LLM 增強的價格報價(含趨勢、動能分析)、跨鏈充值與提現、多種訂單簿查詢,以及回測的未來 PnL 分析。設定透過 `~/.fintool/config.toml` 管理,支援 OpenAPI 金鑰與多種交易所憑證。此外,回測工具無需任何金鑰即可使用,非常適合策略驗證。此技能適合用於回答股價/加密貨幣價格查詢、執行交易、管理資產組合或歷史策略回測。

相容平台~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/second-state/fintool/tree/HEAD/skills

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

fintool — 金融交易技能 是做什麼的?

一套用於智慧市場分析與跨交易所交易的 CLI 工具組。每個交易所對應一個單獨的二進位檔案。

工具

二進位檔案用途路徑
fintool市場情報(報價、新聞、SEC 文件){baseDir}/scripts/fintool
hyperliquidHyperliquid 交易(現貨、合約、HIP-3、充值){baseDir}/scripts/hyperliquid
binanceBinance 交易(現貨、合約、充值){baseDir}/scripts/binance
coinbaseCoinbase 交易(現貨、充值){baseDir}/scripts/coinbase
okxOKX 交易(現貨、合約、充值、提現){baseDir}/scripts/okx
polymarketPolymarket 預測市場{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"}'

檢查以下需求:

  1. OpenAI API 金鑰 — 用於增強報價(趨勢/動能分析)。

    • 尋找 [api_keys] 區段中未被註解的 openai_api_key = "sk-..."
    • 如果遺失:要求使用者提供 OpenAI API 金鑰,或告知將其加入 ~/.fintool/config.toml 的 [api_keys] 區段
  2. 至少一個交易所 — 交易指令需要。

    • 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 相同)進行預測市場交易
    • 如果未設定任何交易所:詢問使用者想使用哪個交易所,並要求提供憑證。

例外情況 — backtest:回測二進位檔案 不需任何設定 — 無 API 金鑰、無錢包。它使用公開的 Yahoo Finance 與 CoinGecko 資料。可以立即使用。

如果使用者提供憑證,直接編輯 ~/.fintool/config.toml 將其加入。

交易所功能對照表

功能hyperliquidbinancecoinbaseokxpolymarketbacktest
現貨訂單買、賣買、賣買、賣買、賣—模擬買/賣
合約訂單合約買/賣合約買/賣—合約買/賣—模擬合約買/賣
預測市場————買、賣、清單、報價—
訂單簿現貨 + 合約現貨 + 合約現貨現貨 + 合約——
充值Unit + AcrossAPIAPIAPI跨鏈橋—
提現Bridge2 + Unit + AcrossAPIAPIAPI跨鏈橋—
轉帳現貨 ↔ 合約 ↔ dex現貨 ↔ 期貨—資金帳戶 ↔ 交易帳戶——
餘額balancebalancebalancebalancebalance模擬
未成交訂單ordersordersordersorders——
取消訂單cancelcancelcancelcancel——
持倉positionspositions—positionspositions模擬
資金費率———合約 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 — 檢查新聞:

…(此處為截斷內容)

相關技能