with one click
ib-stop-loss
// Downside stop-loss management for PMCC, naked LEAPS, and stock positions in IB. Computes stop prices, detects alerts, and places conditional combo orders. Dry-run by default. Requires TWS or IB Gateway running locally.
// Downside stop-loss management for PMCC, naked LEAPS, and stock positions in IB. Computes stop prices, detects alerts, and places conditional combo orders. Dry-run by default. Requires TWS or IB Gateway running locally.
Scan stocks for Poor Man's Covered Call (PMCC) suitability. Analyzes LEAPS and short call options for delta, liquidity, spread, IV, yield, trend direction, and earnings proximity. Use when user asks about PMCC candidates, diagonal spreads, or LEAPS strategies.
Convert a markdown file to PDF using mistune + reportlab. Use when the user wants to convert a .md file to PDF, or when another skill needs to produce a PDF from markdown output.
Generate comprehensive stock analysis report (PDF or markdown) with trend, PMCC, and fundamental analysis
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.
Analyze PMCC (Poor Man's Covered Call / diagonal spread) positions from IB portfolio. For each diagonal spread, reports short leg risk (delta, IV, assignment probability), daily P&L projections, top-3 roll candidates, and a side-by-side comparison table. Requires TWS or IB Gateway running locally.
Get upcoming earnings dates with timing (before/after market) and EPS estimates. Use when user asks about earnings dates, earnings calendar, when a company reports, or upcoming earnings.
| name | ib-stop-loss |
| description | Downside stop-loss management for PMCC, naked LEAPS, and stock positions in IB. Computes stop prices, detects alerts, and places conditional combo orders. Dry-run by default. Requires TWS or IB Gateway running locally. |
| dependencies | ["trading-skills"] |
Analyzes PMCC (diagonal call spread), naked LEAPS, and stock positions in the IB portfolio and manages conditional stop-loss orders.
Default mode is dry-run โ no orders are placed unless --execute is in the request.
TWS or IB Gateway running locally with API enabled:
Dry-run (default โ no orders placed):
uv run python .claude/skills/ib-stop-loss/scripts/stop_loss.py --port 7496
Execute (cancel orphan orders + place SL_ conditional orders):
uv run python .claude/skills/ib-stop-loss/scripts/stop_loss.py --port 7496 --execute
Execute forced (basis = current mid price, can lower existing stops):
uv run python .claude/skills/ib-stop-loss/scripts/stop_loss.py --port 7496 --execute --forced
Format JSON output as a markdown report with four sections:
List symbols in alert_soon prominently โ these are past the early-warning threshold.
Show all_conditional_orders.module (SL_ orders) and all_conditional_orders.manual (manually placed).
If orphan_orders is non-empty, warn that these were cancelled (execute mode) or need manual cancellation (dry-run).
For each entry in positions, show a table:
| Field | Value |
|---|---|
| Symbol | NVDA โ pmcc (3 contracts) |
| Spot | $219.05 |
| LEAPS | 200C 20270115 ยท avg cost $44.27 ยท current $44.23 ยท basis $44.27 |
| Stop price | $22.14 (40% stop) โ action: place_new |
| LEAPS loss | 0.1% |
| Shorts | 235C 20260515 ยท received $0.61 ยท current $0.56 ยท 9.5% decayed |
Show preserve_existing when a more-protective stop already exists.
Show overwrite (red) when forced=true lowers an existing stop.
Group alerts by symbol. Types:
| Type | Meaning |
|---|---|
leaps_early_warning | LEAPS down โฅ stop_pct/2% from basis |
short_premium_decay | 90%+ of short premium captured โ close or roll |
short_near_strike | Spot at/above or within X% of short strike |
alert_soon symbols.| Flag | Default | Description |
|---|---|---|
--port | 7496 | IB Gateway/TWS port |
--account | all | Specific account ID |
--symbols | all | Analyze only these symbols |
--legs | none | Specific option legs: SYMBOL:STRIKE[C|P]:EXPIRY (e.g. IBKR:70C:20270115 IBKR:100C:20260918). Right defaults to C. Takes precedence over --symbols. Use when multiple PMCC/LEAPS coexist on the same symbol and only one pairing should get a stop. |
--stop-pct | 40 | Loss % that triggers exit |
--short-near-strike-pct | 5 | Near-strike alert threshold |
--price-mode | mid | Option pricing: mid or last |
--execute | off | Cancel orphans + place SL_ orders |
--forced | off | Use current mid as basis (requires --execute) |
{
"generated_at": "2026-05-12 10:00 ET",
"dry_run": true,
"forced": false,
"stop_pct": 40.0,
"short_near_strike_pct": 5.0,
"accounts": ["U1234567"],
"symbols_filter": null,
"all_conditional_orders": {"module": [], "manual": []},
"orphan_orders": [],
"alert_soon": ["PFE"],
"positions": [
{
"symbol": "NVDA",
"type": "pmcc",
"account": "U1234567",
"qty": 3,
"underlying_price": 219.05,
"leaps": {
"strike": 200.0, "expiry": "20270115", "avg_cost": 44.27,
"current_price": 44.23, "stop_basis": 44.27,
"stop_price": 22.14, "loss_pct": 0.1
},
"shorts": [
{"strike": 235.0, "expiry": "20260515",
"premium_received": 0.61, "current_price": 0.56, "decay_pct": 9.5}
],
"stop_loss": {"stop_price": 22.14, "action": "place_new", "existing_stop": null},
"alert_soon": false,
"alerts": []
},
{
"symbol": "AAPL",
"type": "stock",
"account": "U1234567",
"qty": 100,
"underlying_price": 189.50,
"stock": {
"avg_cost": 175.00, "stop_basis": 189.50,
"stop_price": 94.75, "loss_pct": 0.0
},
"stop_loss": {"stop_price": 94.75, "action": "place_new", "existing_stop": null},
"alert_soon": false,
"alerts": []
}
]
}
alert_soon โ top-level list of symbols where loss โฅ stop_pct/2%position.type โ pmcc | leaps | stockstop_loss.action โ place_new | preserve_existing | overwritestop_loss.existing_stop โ price of the existing SL_FALL_ order if presentSL_FALL_{SYM}_{STRIKE}_{EXPIRY} โ options (PMCC or naked LEAPS)SL_FALL_{SYM}_STK โ stock positionsAll analytics live in src/trading_skills/broker/stop_loss.py:
Analytics (no IBKR โ testable in isolation):
calc_stop_basis โ max(mid, avg_cost) normally; current_mid if forcedcalc_stop_price โ basis ร (1 - stop_pct/100)calc_short_premium_decay_pct โ % of short premium capturedidentify_positions โ classify normalized positions into pmcc/leaps/stockbuild_position_analysis โ full per-position output dictdetect_orphan_orders โ SL_FALL_ orders for gone positionssummarize_all_conditional_orders โ splits IB orders into module vs manualData layer (IBKR):
get_stop_loss_data โ main entry point_cancel_orphan_orders โ cancel stale SL_ orders_place_combo_stop_order โ BAG order for PMCC (atomic LEAPS + shorts)_place_simple_stop_order โ single order for naked LEAPS or stock_execute_position_stop โ dispatch per position type