Communitygithub.com

fintool — 金融交易技能

一套用于多交易所市场情报和交易的 CLI 工具。每个交易所都有独立的二进制文件。

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

fintool 是一个面向开发者和交易者的 AI Agent 技能,提供跨多个交易所(Hyperliquid、Binance、Coinbase、OKX、Polymarket)的金融交易和预测市场功能。它支持现货、永续合约交易,以及跨链充值和提现。通过集成的 LLM(需要 OpenAI API 密钥),它可以提供带有趋势、动量和成交量分析的价格报价。该技能还包含一个回测模块(`backtest`),无需任何 API 密钥或钱包配置即可使用历史数据(来自 Yahoo Finance 和 CoinGecko)进行模拟交易,并计算未来 PnL。所有交互都通过结构化 JSON 进行,并带有标准的错误处理模式。支持的平台包括 Claude Code、Cursor、Codex 等 AI 编码工具。工作流程包括研究(报价、新闻、SEC 文件)、检查订单簿流动性,以及执行交易。配置存储在 `~/.fintool/config.toml` 中,首次使用前必须检查该文件。

兼容平台~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现货 ↔ 期货—资金 ↔ 交易——
余额余额余额余额余额余额模拟
未成交订单订单订单订单订单——
撤单撤单撤单撤单撤单——
持仓持仓持仓—持仓持仓模拟
资金费率———永续合约资金费率——
历史报价—————报价
未来 PnL—————+1天/+2天/+4天/+7天
SEC 文件(含日期)—————报告列表/年度/季度

错误处理

  • 所有错误都作为 {"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 使用产品 ID:现货 = 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。
  • 使用市场 slug(来自 list)或条件 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"}

// 模拟现货交易 — 返回 +1/+2/+4/+7 天的未来 PnL
{"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"}'

返回:价格、24小时/7天/30天变化、趋势(看涨/看跌/中性)、动量、成交量分析、摘要。

步骤 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 — 检查新闻:

...

[已截断以供翻译]

相关技能