Automated stop-loss management for Interactive Brokers positions, built for diagonal spreads (PMCC), naked LEAPS, and stock. It calculates stop prices at a configurable loss threshold (default 40%), detects existing conditional orders to avoid duplicates, and places atomic combo orders that close both legs of a spread simultaneously. Dry-run by default, which is the right call for anything that cancels orphan orders. The early-warning alerts (at half your stop threshold) and short premium decay tracking are genuinely useful for active option portfolios. Requires TWS or IB Gateway running locally with API enabled. All the analytics live in testable functions separate from the broker calls, so you can verify the stop logic without connecting to IB.

GitHub stars
248
last updated
Jun 11, 2026

Install

$ npx -y skills add staskh/trading_skills --skill ib-stop-loss --agent claude-code

Installs into .claude/skills of the current project.

Files

IB Stop-Loss Manager

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.

IB Connection

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

  • Paper trading — port 7497
  • Live trading — port 7496
  • IB_PORT env var — default port when --port is omitted (e.g. IB_PORT=4001 for a Gateway container). Precedence: --port flag > IB_PORT > built-in default. Set it in the shell or a .env file.

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.

Instructions

Step 1: Run the script

Dry-run (default — no orders placed):

uv run python .claude/skills/ib-stop-loss/scripts/stop_loss.py

Sponsors

Details

Repository
github.com/staskh/trading_skills
Categories
Backend & APIs, Finance & Trading
License
MIT
First seen
Jun 11, 2026

More from staskh/trading_skills

All 28
1telagod avatardesigning-architecturestelagod/code-abyssArchitecture knowledge reference covering API design, security architecture, cloud-native patterns, caching strategies, message queues, and data security. Use w0skills.sh installs
2teng-lin avatarnotebooklmteng-lin/notebooklm-pyComplete API for Google NotebookLM - full programmatic access including features not in the web UI. Create notebooks, add sources, generate all artifact types, 0skills.sh installs
3ThinkInAIXYZ avataradd-providerThinkInAIXYZ/deepchatAdd a DeepChat LLM provider through explicit reviewed source changes. Use when a developer asks Codex to add a provider, provider profile, upstream provider con0skills.sh installs
4tinyplex avatarbuild-with-tinybasetinyplex/tinybaseScaffold, extend, and verify reactive local-first JavaScript or TypeScript applications with TinyBase. Use when choosing TinyBase for in-memory tabular or key-v0skills.sh installs
5tzachbon avatarMCP Integrationtzachbon/smart-ralphThis handles MCP server integration for Claude Code plugins, covering all four connection types: stdio for local processes, SSE for...0skills.sh installs
6inference-sh avatartwitter-automationinference-sh/skillsAutomate Twitter/X with posting, engagement, and user management via inference.sh CLI. Apps: x/post-tweet, x/post-create (with media), x/post-like, x/post-retwe1.7Mskills.sh installs