ib-trades-history
Fetch trade executions from Interactive Brokers filtered by account, date range, or symbol. Supports live API (~7 days history) and FlexReport (full history)
Install / Use
npx skills add staskh/trading_skills --skill ib-trades-historyInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Customer SupportSupported Platforms
Our assessment of ib-trades-history
ib-trades-history scores 86/100 on our quality scale, 204th of 320 Customer Support skills we index.
Its SKILL.md is 7.3 KB long, well organised into 16 sections with 1 code example: a thorough specification that gives an agent plenty to work with.
It has 369 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated 17 days ago, so ib-trades-history is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands.
Automated pattern scan on 2026-10-05. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
ib-trades-history compared with similar skills
All 4 of these similar skills score higher than ib-trades-history; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| ib-trades-history (this skill)by staskh | 86 | 369 | 17d ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 90.8k | 19d ago | CLAUDE.md |
| headroomby headroomlabs-ai | 100 | 74.4k | today | CLAUDE.md |
| Scraplingby D4Vinci | 100 | 85.7k | today | MCP Server |
| crawl4aiby unclecode | 100 | 84.8k | 9d ago | MCP Server |
Frequently asked questions
- How do I install ib-trades-history?
- Run
npx skills add staskh/trading_skills --skill ib-trades-history. The install tabs above show the steps for each supported agent. - Which AI agents does ib-trades-history work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is ib-trades-history safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is ib-trades-history still maintained?
- The repository was last updated 17 days ago, so ib-trades-history is actively maintained.
Skill content
View source on GitHubname: 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
IB_PORTenv var — default port when--portis omitted (e.g.IB_PORT=4001for a Gateway container). Precedence:--portflag >IB_PORT> built-in default. Set it in the shell or a.envfile.
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
uvis not installed orpyproject.tomlis not found, replaceuv run pythonwithpythonin 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
# Group option fills into vertical spreads (credit, width, max risk, capture %, RoR)
uv run python .claude/skills/ib-trades-history/scripts/trades.py --file exports/2026.xml --symbol NDX --group-spreads
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--group-spreads- Consolidate fills into legs and pair them into vertical spreads. FlexReport sources only
Default behavior (no flags): fetches trades for the first managed account from the live API.
Always use --all-accounts unless the user asks for a specific account.
--flex-token / --flex-query-id may be omitted when IB_FLEX_TOKEN / IB_FLEX_QUERY_ID
are set in the environment or .env (see env.template). Flags win over env vars.
Data Sources
| Scenario | Source | Date Range |
|---|---|---|
| No flex args | reqExecutionsAsync | Current session only |
| --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.
The live API returns only the current TWS session, despite the "~7 days" the API
docs imply — it yields 0 executions on a weekend or for any prior-day lookback, which
looks identical to "no trades." Setting ExecutionFilter.time does not widen it. For
anything beyond today, use FlexReport. The web service is also aggressively
rate-limited ("Statement could not be generated at this time" = throttled, roughly one
generation per query per 10–15 min); for large lookbacks prefer a manual XML export
via --file.
Spread Grouping (--group-spreads)
Turns raw fills into the trade-level view: a 10-lot order routed across five exchanges is one leg, and its opening and closing legs are one spread.
Requires the openCloseIndicator field, which only FlexReport sources provide. On
the live API path the output carries spread_grouping.supported = false with a reason
rather than guessing which fills opened versus closed.
Legs are keyed on (account, symbol, expiry, right) — deliberately not trade date, so
a spread opened one session and settled the next keeps its closing legs.
Anything that is not an unambiguous two-strike vertical is left in ungrouped_legs with
a reason in spread_grouping.warnings, never force-fit into a bogus spread:
rolls, ratio spreads, multiple verticals on one expiry/right, single legs, positions
still open, and closes whose open predates the window.
spread_grouping.reconciled asserts that spread P&L plus ungrouped P&L equals the raw
execution P&L — check it before trusting a report.
Output
Returns JSON with:
connected- Whether connection succeededsource- Data source used (reqExecutionsAsyncorFlexReport)filters- Applied filters (dates, symbol, account)data_limitation- Warning about API date limits (only when using live API)execution_count- Total number of executions returnedexecutions- List of individual trade executionssummary- Aggregated stats per symbol (bought, sold, commission, realized P&L)
With --group-spreads, also:
legs/leg_count- Partial fills consolidated into ordersspreads/spread_count- Paired verticals, each withtype(Bear call / Bull put / Bull call / Bear put),short_strike,long_strike,width,lots,credit,max_credit,max_risk,entry_date/entry_time,exit_date/exit_time,realizedPnL,commission,netPnL,capture_pct,return_on_risk_pct,settled_at_expiry,same_dayungrouped_legs- Legs that are not a clean vertical (only when non-empty)spread_grouping-supported,warnings,ungrouped_leg_count, and thereconciled/execution_pnl/spread_pnl/ungrouped_pnlcheck
max_risk assumes a defined-risk vertical: (width − credit) × lots × multiplier.
capture_pct is realized P&L as a share of max credit; return_on_risk_pct is realized
P&L over max risk. On an iron condor the two wings are separate spreads — summing their
max_risk overstates true exposure, since only one side can lose at expiry.
If not connected, explain that TWS/Gateway needs to be running.
Dependencies
ib-async
Related Skills
Agent-Reach
90.8kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
headroom
74.4kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Scrapling
85.7k🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
crawl4ai
84.8kOpen-source web crawler and scraper for LLMs and AI agents: any website into clean, LLM-ready Markdown. Run it yourself, or use Crawl4AI Cloud with one key.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
