
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). Use when user asks about their trades, executions, or transaction history. Requires TWS or IB Gateway running locally.
- Installs
- 40
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/staskh/trading_skills --skill ib-trades-history- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads ib-trades-history automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
FAQ
What does the ib-trades-history skill do?
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.
How do I install ib-trades-history?
Run npx skills add https://github.com/staskh/trading_skills --skill ib-trades-history in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/ib-trades-history/ (personal) or .claude/skills/ib-trades-history/ (project).
Which AI agents can use ib-trades-history?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is ib-trades-history safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains ib-trades-history?
It is published by staskh in staskh/trading_skills. It has 40 recorded installs.
More from staskh/trading_skills
technical-analysis
staskh/trading_skills
Compute technical indicators like RSI, MACD, Bollinger Bands, SMA, EMA for a stock. Use when user asks about technical analysis, indicators, RSI, MACD, moving averages, overbought/oversold, or chart analysis.
news-sentiment
staskh/trading_skills
Get recent news and sentiment for a stock. Use when user asks about news, headlines, sentiment, what's happening with a stock, or recent developments.
fundamentals
staskh/trading_skills
Open the skill to read its SKILL.md instructions.
stock-quote
staskh/trading_skills
Open the skill to read its SKILL.md instructions.
greeks
staskh/trading_skills
Open the skill to read its SKILL.md instructions.
report-stock
staskh/trading_skills
Open the skill to read its SKILL.md instructions.
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.