Get the FREE Ultimate OpenClaw Setup Guide →

ib-create-consolidated-report

npx machina-cli add skill staskh/trading_skills/ib-create-consolidated-report --openclaw
Files (1)
SKILL.md
2.0 KB

IB Create Consolidated Report

Reads all CSV files from a given directory (excluding subdirectories), consolidates trade data by key fields, and generates both markdown and CSV reports.

Instructions

uv run python scripts/consolidate.py <directory> [--port PORT] [--output-dir OUTPUT_DIR]

Arguments

  • directory - Path to directory containing IBRK trade CSV files
  • --port - IB port to fetch unrealized P&L (7497=paper, 7496=live). If not specified, auto-probes both ports (tries 7496 first, then 7497).
  • --output-dir - Output directory for reports (default: sandbox/)

Consolidation Logic

Groups trades by:

  • UnderlyingSymbol - The underlying ticker (e.g., GOOG, CAT)
  • Symbol - Full option symbol
  • TradeDate - Date of the trade
  • Strike - Strike price
  • Put/Call - Option type (C or P)
  • Buy/Sell - Trade direction
  • Open/CloseIndicator - Whether opening or closing

Aggregates:

  • Quantity - Sum of quantities
  • Proceeds - Sum of proceeds
  • NetCash - Sum of net cash
  • IBCommission - Sum of commissions
  • FifoPnlRealized - Sum of realized P&L

Adds column:

  • Position - SHORT (Sell+Open), LONG (Buy+Open), CLOSE_SHORT (Buy+Close), CLOSE_LONG (Sell+Close)

Output

Generates two files in the output directory:

  • consolidated_trades_YYYY-MM-DD_HHMM.md - Markdown report with summary tables
  • consolidated_trades_YYYY-MM-DD_HHMM.csv - CSV with all consolidated data

Example Usage

# Consolidate trades from IBRK reports directory
uv run python scripts/consolidate.py "C:\Users\avrah\OneDrive\Business\Trading\IBRK reports\2stastrading2025"

# Specify custom output directory
uv run python scripts/consolidate.py "C:\path\to\reports" --output-dir "C:\output"

Source

git clone https://github.com/staskh/trading_skills/blob/main/.claude/skills/ib-create-consolidated-report/SKILL.mdView on GitHub

Overview

Reads all CSVs in a directory (excluding subdirectories), consolidates trade data by key fields, and generates both markdown and CSV reports. It groups by underlying symbol, full option symbol, trade date, strike, put/call, buy/sell, and open/close, then outputs aggregated totals.

How This Skill Works

The tool scans the input directory for CSVs, buckets trades by the consolidation keys, and sums metrics such as Quantity, Proceeds, NetCash, IBCommission, and FifoPnlRealized. It adds a Position descriptor (SHORT, LONG, CLOSE_SHORT, CLOSE_LONG) and writes two outputs in the specified directory: a markdown report and a CSV file with the consolidated rows.

When to Use It

  • You have multiple IBRK trade CSVs in a folder and need a single consolidated summary.
  • You want per-symbol and per-underlying grouping with a clear view of PnL and cash flows.
  • You need both a human-friendly markdown report and a machine-readable CSV for processing.
  • You require grouping by date and open/close status to analyze position activity.
  • You want a reproducible automation to consolidate trades across days or sessions.

Quick Start

  1. Step 1: uv run python scripts/consolidate.py "<directory>" [--port PORT] [--output-dir OUTPUT_DIR]
  2. Step 2: Open the generated MD report in the output directory to review the summary tables
  3. Step 3: Use the CSV file in the output directory for downstream processing or BI imports

Best Practices

  • Put all IBRK CSVs you want consolidated into one directory before running.
  • Run in a stable Python environment with necessary dependencies installed.
  • Ensure the CSVs share consistent column names and data formats (e.g., TradeDate, Strike, Symbol).
  • Verify the generated Position labels align with your trading conventions (LONG/SHORT, CLOSE_...).
  • Check the output-dir after execution for the two files named consolidated_trades_YYYY-MM-DD_HHMM.*

Example Use Cases

  • Consolidate a folder of GOOG option trades into consolidated_trades_2026-03-08_1330.md and consolidated_trades_2026-03-08_1330.csv.
  • Merge several days of IBRK CSVs into a weekly summary with per-symbol and per-underlying grouping.
  • Generate a marketing-friendly Markdown report and a data-ready CSV for finance teams.
  • Auto-fetch unrealized PnL using --port (7496 or 7497) when port is not specified.
  • Produce a consolidated view across multiple underlying symbols showing open vs close activity.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers