Agent Skillsstaskh/trading_skills › ib-trades-history

ib-trades-history

GitHub

用于从 Interactive Brokers 获取交易执行记录。支持通过 API 查询近期(约7天)数据,或通过 FlexReport 获取完整历史。具备自动端口回退机制,可按账户、日期范围或代码筛选,支持合并多个查询或本地 XML 文件。

.claude/skills/ib-trades-history/SKILL.md staskh/trading_skills

触发场景

用户询问交易历史 用户查询特定股票的交易记录 用户需要导出或分析过往交易明细

安装

npx skills add staskh/trading_skills --skill ib-trades-history -g -y
更多选项

非标准路径

npx skills add https://github.com/staskh/trading_skills/tree/main/.claude/skills/ib-trades-history -g -y

不安装直接使用

npx skills use staskh/trading_skills@ib-trades-history

指定 Agent (Claude Code)

npx skills add staskh/trading_skills --skill ib-trades-history -a claude-code -g -y

安装 repo 全部 skill

npx skills add staskh/trading_skills --all -g -y

预览 repo 内 skill

npx skills add staskh/trading_skills --list

SKILL.md

Frontmatter
{
    "name": "ib-trades-history",
    "description": "Fetch trade executions from Interactive Brokers filtered by account, date range, or symbol. Supports live API (~7 days history) and FlexReport (full history). Use when user asks about their trades, executions, or transaction history. Requires TWS or IB Gateway running locally.",
    "dependencies": [
        "trading-skills"
    ]
}

IB Trades History

Fetch trade executions from Interactive Brokers.

IB Connection

TWS or IB Gateway must be running locally with API enabled:

  • Paper trading — port 7497
  • Live trading — port 7496

Port fallback: If the configured port fails, automatically retry on the other port. If the retry succeeds, save to memory which account type worked (live/paper) and reuse it for all IB skill calls in this and future sessions — until the user explicitly asks for the other account. If both ports fail, ask the user to verify that TWS or IB Gateway is running with API access enabled.

For full trade history beyond ~7 days, the user needs a Flex Web Service token and a pre-configured Trade query in IBKR Account Management.

Instructions

Note: If uv is not installed or pyproject.toml is not found, replace uv run python with python in all commands below.

# Recent trades (last ~7 days via API)
uv run python .claude/skills/ib-trades-history/scripts/trades.py --all-accounts

# Filter by symbol
uv run python .claude/skills/ib-trades-history/scripts/trades.py --all-accounts --symbol AAPL

# Full history via FlexReport
uv run python .claude/skills/ib-trades-history/scripts/trades.py --all-accounts --flex-token YOUR_TOKEN --flex-query-id YOUR_QUERY_ID

# Custom date range (FlexReport)
uv run python .claude/skills/ib-trades-history/scripts/trades.py --all-accounts --flex-token TOKEN --flex-query-id QID --start-date 2025-01-01 --end-date 2025-12-31

# Multiple queries (e.g., one per year to exceed 365-day limit)
uv run python .claude/skills/ib-trades-history/scripts/trades.py --all-accounts --flex-token TOKEN --flex-query-id QID_2025 --flex-query-id QID_2026 --start-date 2025-01-01 --end-date 2026-12-31

# From local FlexReport XML files (no TWS/Gateway needed)
uv run python .claude/skills/ib-trades-history/scripts/trades.py --file trades_2024.xml --file trades_2025.xml --symbol TSLA

# Mix files with date filtering
uv run python .claude/skills/ib-trades-history/scripts/trades.py --file exports/2025.xml --start-date 2025-06-01 --end-date 2025-12-31

Arguments

  • --port - IB port (default: 7497 for paper trading)
  • --account - Specific account ID to filter
  • --all-accounts - Fetch trades for all managed accounts
  • --symbol - Filter trades by symbol (e.g., AAPL)
  • --start-date - Start date in YYYY-MM-DD format (default: Jan 1 of current year)
  • --end-date - End date in YYYY-MM-DD format (default: today)
  • --flex-token - FlexReport token (enables extended history)
  • --flex-query-id - FlexReport query ID (repeatable — pass multiple to merge queries spanning different periods)
  • --file - Local FlexReport XML file path (repeatable — pass multiple to merge files). No TWS/Gateway needed

Default behavior (no flags): fetches trades for the first managed account from the live API (~7 days). Always use --all-accounts unless the user asks for a specific account.

Data Sources

Scenario Source Date Range
No flex args reqExecutionsAsync ~last 7 days
--flex-token + --flex-query-id FlexReport (web) As configured in query
--file file (local XML) Full file contents

When using the live API, a data_limitation warning is included in the output.

Output

Returns JSON with:

  • connected - Whether connection succeeded
  • source - Data source used (reqExecutionsAsync or FlexReport)
  • filters - Applied filters (dates, symbol, account)
  • data_limitation - Warning about API date limits (only when using live API)
  • execution_count - Total number of executions returned
  • executions - List of individual trade executions
  • summary - Aggregated stats per symbol (bought, sold, commission, realized P&L)

If not connected, explain that TWS/Gateway needs to be running.

Dependencies

  • ib-async

版本历史

  • cc30858 当前 2026-07-05 11:04

依赖关系

  • required trading-skills

同 Skill 集合

.claude/skills/earnings-calendar/SKILL.md
.claude/skills/fundamentals/SKILL.md
.claude/skills/greeks/SKILL.md
.claude/skills/ib-account/SKILL.md
.claude/skills/ib-collar/SKILL.md
.claude/skills/ib-create-consolidated-report/SKILL.md
.claude/skills/ib-find-short-roll/SKILL.md
.claude/skills/ib-option-chain/SKILL.md
.claude/skills/ib-pmcc-advisor/SKILL.md
.claude/skills/ib-portfolio-action-report/SKILL.md
.claude/skills/ib-portfolio/SKILL.md
.claude/skills/ib-report-delta-adjusted-notional-exposure/SKILL.md
.claude/skills/ib-stop-loss/SKILL.md
.claude/skills/ib-trailing-stop/SKILL.md
.claude/skills/insider-trading/SKILL.md
.claude/skills/markdown-to-pdf/SKILL.md
.claude/skills/news-sentiment/SKILL.md
.claude/skills/option-chain/SKILL.md
.claude/skills/price-history/SKILL.md
.claude/skills/report-stock/SKILL.md
.claude/skills/risk-assessment/SKILL.md
.claude/skills/scanner-bullish/SKILL.md
.claude/skills/scanner-pmcc/SKILL.md
.claude/skills/spread-analysis/SKILL.md
.claude/skills/stock-quote/SKILL.md
.claude/skills/technical-analysis/SKILL.md
.claude/skills/whale-hunting/SKILL.md

元信息

文件数
0
版本
cc30858
Hash
d54a52ee
收录时间
2026-07-05 11:04

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-13 22:45
浙ICP备14020137号-1 $访客地图$