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 | 现货 ↔ 期货 | — | 资金 ↔ 交易 | — | — |
| 余额 | 余额 | 余额 | 余额 | 余额 | 余额 | 模拟 |
| 未成交订单 | 订单 | 订单 | 订单 | 订单 | — | — |
| 撤单 | 撤单 | 撤单 | 撤单 | 撤单 | — | — |
| 持仓 | 持仓 | 持仓 | — | 持仓 | 持仓 | 模拟 |
| 资金费率 | — | — | — | 永续合约资金费率 | — | — |
| 历史报价 | — | — | — | — | — | 报价 |
| 未来 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 — 检查新闻:
...
[已截断以供翻译]