微算力 · API 导航与自营网关
API 接入 EN
未登录登录
📈

一键聚合多券商,自动追踪总资产

SnapTrade · v1.0.0
效率 安全 A 级 作者 brendanwood 公开目录收录
1.2k 下载 0 安装 2.4k 收藏 15 浏览

简介

通过 SnapTrade SDK 安全连接主流券商(Webull、E*TRADE 等),自动化生成投资组合日报,支持下单交易与实时监控

原始描述

Connect to a user's investment accounts via SnapTrade SDK and generate portfolio reports (e.g., daily total value). Use when the user wants SnapTrade-based brokerage connectivity (Webull, E*TRADE, etc.), connection portal links, account registration, or automated portfolio summaries.

通过你的 Agent 添加

点「快速安装」复制一段指令,粘给你正在用的 Agent(Claude Code、Codex、OpenClaw 等),它会自己完成安装。

或者手动安装

Claude Codeunzip -o skill.zip -d ~/.claude/skills/snaptrade/
其它 Agent解压到它自己的 skills 目录,目录名用 snaptrade

包里是 SKILL.md 加作者附带的文件,解压后目录名就是技能名。 技能申请的权限由作者决定,装之前请确认它能读什么、能执行什么。

中文使用说明 来自收录源

核心用法

SnapTrade Portfolio 是一款面向个人投资者的投资账户聚合与自动化报告工具,基于 SnapTrade 官方 Python SDK 构建,支持与北美主流券商(如 Webull、E*TRADE、Alpaca 等)的安全连接。

主要功能流程

1. 账户初始化与配置

  • 在 snaptrade.com 注册免费账户,获取 Client ID 与 Consumer Key
  • 本地配置存储于 ~/.openclaw/workspace/secrets/snaptrade.json,权限设置为 600
  • 首次运行自动生成 UUID 作为 user_id

2. 券商账户连接

  • snaptrade_portal.py:生成专属连接门户链接,用户授权后自动完成 OAuth 绑定
  • snaptrade_reconnect.py:处理失效连接的重连
  • snaptrade_brokers.py:查询当前支持的券商列表

3. 投资组合监控

  • snaptrade_total.py:聚合所有授权账户持仓,计算总资产(处理多币种时以首个币种为准)
  • 智能检测连接状态:对失效连接保留最后已知余额并标记,避免同步阻塞
  • 支持 cron 定时任务生成日报,格式化后推送至 WhatsApp

4. 交易执行(进阶)

  • snaptrade_order.py:支持市价/限价单,可设 Day/GTC/IOC/FOK 时效,附带 10 秒轮询的订单状态监控(默认 120 秒)
  • snaptrade_watch_order.py:按订单 ID 追踪成交状态

显著优点

维度 优势
覆盖广度 单一 SDK 对接 20+ 北美主流券商,避免各平台独立开发
安全机制 请求签名由 SDK 自动处理(request_after_hook + consumer_key),密钥本地加密存储
容错设计 失效连接不阻断整体流程,保留历史数据并显式报告
自动化友好 纯 CLI 工具链,天然适配 cron/systemd 定时任务
合规基础 基于 SnapTrade 官方 SDK,非爬虫方案,降低账户风控风险

潜在缺点与局限性

  1. 地域限制:SnapTrade 主要覆盖北美券商,对 A 股、港股、欧洲券商支持有限
  2. 货币处理简化:多币种场景下仅以首个币种输出,未做实时汇率换算
  3. 时效性依赖:持仓同步需等待券商端数据刷新,极端行情下可能存在分钟级延迟
  4. 权限粒度:需一次性授权较大范围的数据读取权限,无法细分子账户隔离
  5. API 稳定性:依赖 SnapTrade 第三方服务,存在上游服务变更或 rate limit 风险

适合人群

  • 多账户投资者:在 2 家以上券商分散持仓,需统一视图的用户
  • 量化爱好者:希望用 Python 脚本自动化生成净值报告、定时推送
  • 北美市场专注者:主要交易美股、ETF 的长期投资者
  • 隐私敏感用户:偏好本地密钥存储,不接受纯云端资管工具

常规风险

风险类型 说明 缓释建议
密钥泄露 Client ID / Consumer Key 本地存储,若设备失陷可能被滥用 配置文件权限 600,考虑使用系统密钥环(keyring)替代 JSON
连接失效 券商 OAuth token 过期或用户改密导致同步中断 配置监控告警,结合 snaptrade_reconnect.py 主动修复
误操作交易 CLI 参数错误导致非预期下单 生产环境添加 --dry-run 模式,或设置交易密码二次确认
数据延迟 极端行情下净值计算滞后于实际市值 日报场景可接受;实时交易需结合券商原生 App 复核
第三方依赖 SnapTrade 服务终止或涨价导致功能中断 定期评估替代方案(Plaid、Yodlee 等),保持持仓数据本地备份

技能正文


name: snaptrade-portfolio description: Connect to a user's investment accounts via SnapTrade SDK and generate portfolio reports (e.g., daily total value). Use when the user wants SnapTrade-based brokerage connectivity (Webull, E*TRADE, etc.), connection portal links, account registration, or automated portfolio summaries.

SnapTrade Portfolio

Overview

Connect brokerage accounts through SnapTrade and generate a daily total-value report. This skill uses the official SnapTrade Python SDK (snaptrade_client) with request signing handled automatically.

Workflow

2d) Place buy/sell orders (stocks/ETFs)

Run:

python3 scripts/snaptrade_order.py buy|sell TICKER UNITS --account-id <ACCOUNT_ID> [--order-type market|limit] [--limit-price <PRICE>] [--tif Day|GTC|IOC|FOK]

Defaults:

  • order type: market
  • time in force: Day
  • limit price: only required for limit orders

Optional monitoring (poll recent orders):

python3 scripts/snaptrade_order.py buy|sell TICKER UNITS --account-id <ACCOUNT_ID> --watch
  • polls every 10s for up to 120s by default
  • adjust with --watch-interval and --watch-seconds

Watch an existing order by ID:

python3 scripts/snaptrade_watch_order.py --account-id <ACCOUNT_ID> --order-id <BROKERAGE_ORDER_ID>
  • same 10s/120s defaults, adjustable with --watch-interval and --watch-seconds

Use account orders endpoint to confirm fills and report open orders to the user when asked.

0) Create a SnapTrade account + API keys

You need a SnapTrade account to connect brokerages. Create a free account at https://snaptrade.com, generate your Client ID and Consumer Key, then add them to the skill config.

1) Install dependencies

pip3 install -r requirements.txt

2) Configure credentials (one-time)

Store credentials in a local config file (not committed). user_id is generated automatically on first run:

/home/openclaw/.openclaw/workspace/secrets/snaptrade.json

Example:

{
  "client_id": "YOUR_CLIENT_ID",
  "consumer_key": "YOUR_CONSUMER_KEY",
  "user_id": "<auto-generated-uuid>"
}

2) Register user + generate connection portal link

Run:

python3 scripts/snaptrade_portal.py

This will:

  • register the user if user_secret is missing
  • store user_secret back into the config file
  • print a connection portal URL the user must open to link accounts

2b) Reconnect a disabled connection

Run:

python3 scripts/snaptrade_reconnect.py [brokerage-name]

This will:

  • list disabled connections
  • generate a reconnect link (optionally match by brokerage name)
  • print a reconnect URL for the user to re‑enable the connection

2c) List available brokerages (allowed connections)

Run:

python3 scripts/snaptrade_brokers.py

This calls /snaptrade/partners and returns the allowed_brokerages list (display names).

3) Pull total portfolio value

Run:

python3 scripts/snaptrade_total.py

Output is JSON like:

{"total_value": 123456.78, "currency": "CAD"}

Implementation notes: The script first lists brokerage authorizations to detect disabled connections. It skips refresh and sync-wait for disabled ones (but still reports their last-known balances), then waits for updated sync timestamps on enabled connections. It then enumerates all current non-closed accounts via list_user_accounts and uses get_user_holdings to read each account’s account.balance.total. Disabled connections are included in the output under disabled_connections for reporting.

4) Schedule daily report

Use cron to call snaptrade_total.py, format a concise WhatsApp message, then send it to the user. Only the total value is required.

Scripts

  • scripts/snaptrade_common.py — config load/save + client creation
  • scripts/snaptrade_portal.py — register user + generate connection portal link
  • scripts/snaptrade_reconnect.py — generate reconnect link for disabled connections
  • scripts/snaptrade_brokers.py — list allowed brokerages for this client
  • scripts/snaptrade_order.py — place buy/sell orders (market/limit) with optional monitoring
  • scripts/snaptrade_watch_order.py — watch an existing order by ID for fills
  • scripts/snaptrade_total.py — compute total value across all accounts

Notes

  • Request signing is handled by the SDK via request_after_hook using consumer_key.
  • The total is computed by summing each account’s account.balance.total from holdings; this avoids errors when accounts are added or removed.
  • If multiple currencies are present, the script uses the first currency encountered.
  • Keep secrets in the local config file with chmod 600 permissions.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

investmentportfoliobrokerageautomationtradingsnaptradewealth-managementcli-tooletl

同类 Skill