ClawBack
Mirror congressional stock trades with automated broker execution
Agent Instructions
When the user invokes /clawback, execute the appropriate command based on the argument:
Commands
When the user invokes /clawback with any arguments, execute the corresponding command:
| Command | Action |
|---|
| INLINECODE2 | Run the setup wizard: Execute INLINECODE3 |
| INLINECODE4 |
Check system status: Execute
{baseDir}/bin/clawback.py status |
|
/clawback run | Start trading bot: Execute
{baseDir}/bin/clawback.py run |
|
/clawback daemon | Run as background service: Execute
{baseDir}/bin/clawback.py daemon |
|
/clawback test | Test notifications: Execute
{baseDir}/bin/clawback.py test |
|
/clawback (no args) | Show help: Execute
{baseDir}/bin/clawback.py --help |
How to Execute Commands
Option 1: Using the wrapper script (recommended)
When executing ClawBack commands, always:
- 1. Use the wrapper script at INLINECODE14
- Pass the command as an argument (e.g.,
{baseDir}/bin/clawback.py status) - Capture and display the output to the user
Option 2: Direct Python execution (if wrapper doesn't work)
If the wrapper script fails, you can run ClawBack directly:
- 1. Change to the skill directory: INLINECODE16
- Activate the virtual environment: INLINECODE17
- Run the CLI: INLINECODE18
- Capture and display the output
Important: Always check if the virtual environment exists at {baseDir}/venv. If not, you may need to run the setup first.
/clawback setup - Interactive Setup Flow
When user runs /clawback setup, follow these steps:
Step 1: Install dependencies (if needed)
Check if {baseDir}/venv exists. If not, run:
CODEBLOCK0
Step 2: Prompt for E*TRADE credentials
Ask the user for each value:
- 1. Environment: Ask "Do you want to use sandbox (testing) or production (real money)?"
- Default: sandbox
- 2. Consumer Key: Ask "Enter your E*TRADE Consumer Key (from developer.etrade.com):"
- Required field
- 3. Consumer Secret: Ask "Enter your E*TRADE Consumer Secret:"
- Required field
- 4. Account ID: Ask "Enter your E*TRADE Account ID (or leave blank to get it after OAuth):"
- Optional - can be obtained later
Step 3: Save configuration
Create/update ~/.clawback/config.json with the provided values:
CODEBLOCK1
Step 4: Confirm setup
Tell the user: "Configuration saved to ~/.clawback/config.json. Run /clawback status to verify."
Getting E*TRADE API Credentials
Direct user to: https://developer.etrade.com
- 1. Create a developer account
- Create a new app (sandbox first for testing)
- Copy the Consumer Key and Consumer Secret
Configuration Location
- - Config file: INLINECODE25
- Skill directory: INLINECODE26
Reading Saved Configuration
To check if the user has configured credentials, read ~/.clawback/config.json:
- - If file doesn't exist or credentials are empty → prompt for setup
- If credentials exist → can proceed with status/run commands
The CLI automatically reads from ~/.clawback/config.json for all operations.
Checking Setup Status
Before running /clawback status or /clawback run, verify:
- 1.
{baseDir}/venv exists (dependencies installed) - INLINECODE32 exists with non-empty INLINECODE33
If either is missing, suggest running /clawback setup first.
ClawBack tracks stock trades disclosed by members of Congress (House and Senate) and executes scaled positions in your E*TRADE brokerage account. Built on the premise that congressional leaders consistently outperform the market due to informational advantages.
Default Target Politicians
ClawBack monitors these politicians by default (configurable):
| Politician | Chamber | Priority |
|---|
| Nancy Pelosi | House | 1 (highest) |
| Dan Crenshaw |
House | 2 |
| Tommy Tuberville | Senate | 2 |
| Marjorie Taylor Greene | House | 3 |
Trading Strategy Defaults
| Parameter | Default | Description |
|---|
| Trade Delay | 3 days | Wait after disclosure before trading |
| Holding Period |
30 days | Target hold time for positions |
| Position Size | 5% | Max allocation per trade |
| Stop-Loss | 8% | Per-position stop-loss |
| Portfolio Drawdown | 15% | Max portfolio loss before halt |
| Disclosure Checks | 10:00, 14:00, 18:00 ET | Daily check times |
Features
- - Real-time disclosure tracking from official House Clerk and Senate eFD sources
- Automated trade execution via E*TRADE API (only supported broker)
- Smart position sizing - scales trades to your account size
- Trailing stop-losses - lock in profits, limit losses
- Risk management - drawdown limits, consecutive loss protection
- Telegram notifications - get alerts for new trades and stop-losses
- Backtesting engine - test strategies on historical data
Performance (Backtest Results)
| Strategy | Win Rate | Return | Sharpe |
|---|
| 3-day delay, 30-day hold | 42.9% | +6.2% | 0.39 |
| 9-day delay, 90-day hold |
57.1% | +4.7% | 0.22 |
Congressional leaders have outperformed the S&P 500 by 47% annually according to NBER research.
Installation via ClawHub
CODEBLOCK2
Troubleshooting
Common Issues
- 1. Skill not executing: If
/clawback doesn't work in OpenClaw:
- Check if the skill is in the correct location:
{baseDir}/
- Verify the wrapper script is executable:
chmod +x {baseDir}/bin/clawback.py
- Check if virtual environment exists: INLINECODE38
- 2. Authentication issues: If E*TRADE authentication fails:
- Run the authentication utility:
python {baseDir}/scripts/auth_utility.py --auth
- Run
{baseDir}/bin/clawback.py setup to reconfigure
- Check credentials in
~/.clawback/config.json
- Verify E*TRADE API keys are valid
- 3. Token expiration: If tokens expire (30-day lifespan):
- Run:
python {baseDir}/scripts/auth_utility.py --refresh
- Or start new authentication: INLINECODE43
- 4. Python import errors: If you see "ModuleNotFoundError":
- Ensure virtual environment is activated
- Run
pip install -e . in
{baseDir}/
- Check Python path includes INLINECODE46
Debug Mode
To debug skill execution, add DEBUG=1 environment variable:
CODEBLOCK3
This will show additional information about the execution context.
Post-Installation Setup
After installation via ClawHub, the install.sh script runs automatically:
- 1. Python Environment Setup - Creates virtual environment
- Package Installation - Installs ClawBack via pip
- Directory Structure - Creates logs/, data/, config/ directories
- Setup Prompt - Asks if you want to run the setup wizard
If you skip setup during installation, run it manually:
CODEBLOCK4
Improved Setup Features
- - Better input handling - Works in both interactive and non-interactive modes
- Input validation - Validates E*TRADE API key formats
- Timeout handling - Automatically uses defaults if no input
- Error recovery - Fallback to manual setup if CLI fails
- Configuration check - Detects existing config and offers options
Interactive Setup Wizard
The setup wizard guides you through configuration:
Step 1: Environment Selection
- - Sandbox (recommended for testing): No real trades, uses E*TRADE developer sandbox
- Production: Real trading with real money
Step 2: E*TRADE API Credentials
- - Consumer Key: From ETRADE developer portal
- Consumer Secret: From ETRADE developer portal
Step 3: Authentication
- - Automatic OAuth flow with E*TRADE
- Opens browser for authorization
- Returns verification code
Step 4: Account Selection
- - Lists all available E*TRADE accounts
- Choose which account to trade with
Step 5: Telegram Setup (Optional)
- - Configure notifications via Telegram bot
- Uses OpenClaw's built-in Telegram channel if available
Environment Variables
After setup, credentials are stored in .env:
CODEBLOCK5
Usage
CODEBLOCK6
Automated Trading
The clawback daemon command runs continuously with:
- - Disclosure checks at 10:00, 14:00, 18:00 ET (when filings are typically released)
- Trade execution at 9:35 AM ET (5 min after market open)
- Token refresh every 90 minutes (keeps E*TRADE session alive)
- Market hours enforcement (9:30 AM - 4:00 PM ET)
Data Sources
- - House Clerk: https://disclosures-clerk.house.gov (PDF parsing)
- Senate eFD: https://efdsearch.senate.gov (web scraping)
- Financial Modeling Prep: Enhanced financial data (optional)
Supported Brokers
ClawBack currently only supports ETRADE. The adapter pattern allows for future broker support, but only ETRADE is implemented and tested.
| Broker | Adapter | Status |
|---|
| E*TRADE | INLINECODE51 | Supported |
Risk Management
- - Position limits: 5% max per symbol, 20 positions max
- Stop-losses: 8% per position, 15% portfolio drawdown
- Daily limits: 3% max daily loss
- PDT compliance: Conservative 2 trades/day limit
Authentication Helpers
For manual E*TRADE authentication outside the main CLI:
CODEBLOCK7
This generates an authorization URL, prompts for the verification code, and completes authentication.
File Locations
| File | Purpose |
|---|
| INLINECODE52 | Main configuration |
| INLINECODE53 |
E*TRADE OAuth tokens |
|
~/.clawback/data/trading.db | SQLite database |
Security
- - No hardcoded credentials in source code
- Environment variable based configuration
- Encrypted token storage for E*TRADE
- Git-ignored
.env file - Optional production encryption
Support
- - Documentation: See README.md for detailed setup
- Issues: https://github.com/mainfraame/clawback/issues
- Community: https://discord.com/invite/clawd
Disclaimer
Trading involves substantial risk of loss. This software is for educational purposes only. Past congressional trading performance does not guarantee future results. Always test with E*TRADE sandbox accounts before live trading.
回拨
通过自动化券商执行,镜像国会股票交易
代理指令
当用户调用 /clawback 时,根据参数执行相应命令:
命令
当用户调用带参数的 /clawback 时,执行对应命令:
| 命令 | 操作 |
|---|
| /clawback setup | 运行设置向导:执行 {baseDir}/bin/clawback.py setup |
| /clawback status |
检查系统状态:执行 {baseDir}/bin/clawback.py status |
| /clawback run | 启动交易机器人:执行 {baseDir}/bin/clawback.py run |
| /clawback daemon | 作为后台服务运行:执行 {baseDir}/bin/clawback.py daemon |
| /clawback test | 测试通知:执行 {baseDir}/bin/clawback.py test |
| /clawback(无参数) | 显示帮助:执行 {baseDir}/bin/clawback.py --help |
如何执行命令
选项 1:使用包装脚本(推荐)
执行 ClawBack 命令时,始终:
- 1. 使用位于 {baseDir}/bin/clawback.py 的包装脚本
- 将命令作为参数传递(例如 {baseDir}/bin/clawback.py status)
- 捕获并显示输出给用户
选项 2:直接 Python 执行(如果包装脚本无效)
如果包装脚本失败,可以直接运行 ClawBack:
- 1. 切换到技能目录:cd {baseDir}
- 激活虚拟环境:source venv/bin/activate
- 运行 CLI:python -m clawback.cli [command]
- 捕获并显示输出
重要:始终检查虚拟环境是否存在于 {baseDir}/venv。如果不存在,可能需要先运行设置。
/clawback setup - 交互式设置流程
当用户运行 /clawback setup 时,请遵循以下步骤:
步骤 1:安装依赖(如需要)
检查 {baseDir}/venv 是否存在。如果不存在,运行:
bash
cd {baseDir} && python3 -m venv venv && source venv/bin/activate && pip install -e .
步骤 2:提示输入 E*TRADE 凭证
向用户询问每个值:
- 1. 环境:询问您想使用 沙盒(测试)还是 生产(真实资金)?
- 默认:沙盒
- 2. 消费者密钥:询问请输入您的 E*TRADE 消费者密钥(来自 developer.etrade.com):
- 必填字段
- 3. 消费者密钥密文:询问请输入您的 E*TRADE 消费者密钥密文:
- 必填字段
- 4. 账户 ID:询问请输入您的 E*TRADE 账户 ID(或留空以在 OAuth 后获取):
- 可选 - 可稍后获取
步骤 3:保存配置
使用提供的值创建/更新 ~/.clawback/config.json:
json
{
broker: {
adapter: etrade,
environment: ,
credentials: {
apiKey: ,
apiSecret:
}
},
trading: {
accountId: ,
initialCapital: 50000,
tradeScalePercentage: 0.01,
maxPositionPercentage: 0.05,
dailyLossLimit: 0.02
},
notifications: {
telegram: {
enabled: true,
useOpenClaw: true
}
},
congress: {
dataSource: official,
pollIntervalHours: 24,
minimumTradeSize: 10000
}
}
步骤 4:确认设置
告知用户:配置已保存至 ~/.clawback/config.json。运行 /clawback status 进行验证。
获取 E*TRADE API 凭证
引导用户访问:https://developer.etrade.com
- 1. 创建开发者账户
- 创建新应用(先使用沙盒进行测试)
- 复制消费者密钥和消费者密钥密文
配置文件位置
- - 配置文件:~/.clawback/config.json
- 技能目录:{baseDir}
读取已保存的配置
要检查用户是否已配置凭证,读取 ~/.clawback/config.json:
- - 如果文件不存在或凭证为空 → 提示进行设置
- 如果凭证存在 → 可以继续执行状态/运行命令
CLI 会自动从 ~/.clawback/config.json 读取所有操作所需信息。
检查设置状态
在运行 /clawback status 或 /clawback run 之前,验证:
- 1. {baseDir}/venv 存在(依赖已安装)
- ~/.clawback/config.json 存在且 broker.credentials.apiKey 非空
如果缺少任一条件,建议先运行 /clawback setup。
ClawBack 追踪国会议员(众议院和参议院)披露的股票交易,并在您的 E*TRADE 经纪账户中执行按比例调整的头寸。其前提是国会领导人因信息优势而持续跑赢市场。
默认目标政客
ClawBack 默认监控以下政客(可配置):
| 政客 | 议院 | 优先级 |
|---|
| 南希·佩洛西 | 众议院 | 1(最高) |
| 丹·克伦肖 |
众议院 | 2 |
| 汤米·图伯维尔 | 参议院 | 2 |
| 玛乔丽·泰勒·格林 | 众议院 | 3 |
交易策略默认值
| 参数 | 默认值 | 描述 |
|---|
| 交易延迟 | 3 天 | 披露后等待再交易 |
| 持有期 |
30 天 | 头寸目标持有时间 |
| 头寸规模 | 5% | 每笔交易最大分配 |
| 止损 | 8% | 每头寸止损 |
| 投资组合回撤 | 15% | 暂停前最大投资组合损失 |
| 披露检查 | 美国东部时间 10:00、14:00、18:00 | 每日检查时间 |
功能特点
- - 实时披露追踪,来自众议院书记官和参议院 eFD 官方来源
- 自动交易执行,通过 E*TRADE API(唯一支持的券商)
- 智能头寸规模调整 - 根据您的账户规模调整交易
- 追踪止损 - 锁定利润,限制损失
- 风险管理 - 回撤限制,连续亏损保护
- Telegram 通知 - 获取新交易和止损提醒
- 回测引擎 - 在历史数据上测试策略
表现(回测结果)
| 策略 | 胜率 | 回报率 | 夏普比率 |
|---|
| 3 天延迟,30 天持有 | 42.9% | +6.2% | 0.39 |
| 9 天延迟,90 天持有 |
57.1% | +4.7% | 0.22 |
根据 NBER 研究,国会领导人年化表现超过标普 500 指数 47%。
通过 ClawHub 安装
bash
从 ClawHub 注册表安装
clawhub install clawback
或从本地目录安装
clawhub install ./clawback
故障排除
常见问题
- 1. 技能未执行:如果 /clawback 在 OpenClaw 中不起作用:
- 检查技能是否位于正确位置:{baseDir}/
- 验证包装脚本是否可执行:chmod +x {baseDir}/bin/clawback.py
- 检查虚拟环境是否存在:{baseDir}/venv/
- 2. 认证问题:如果 E*TRADE 认证失败:
- 运行认证工具:python {baseDir}/scripts/auth_utility.py --auth
- 运行 {baseDir}/bin/clawback.py setup 重新配置
- 检查 ~/.clawback/config.json 中的凭证
- 验证 E*TRADE API 密钥是否有效
- 3. 令牌过期:如果令牌过期(30 天有效期):
- 运行:python {baseDir}/scripts/auth_utility.py --refresh
- 或开始新的认证:python {baseDir}/scripts/auth_utility.py --auth
- 4. Python 导入错误:如果看到