Add IBKR broker support via ib_insync#60
Merged
Conversation
Adds Interactive Brokers as an alternate broker for single-leg equity option orders. Mirrors the surface and logging style of SafeCashBot's option methods so call sites can swap brokers without changes. - utils/ibkr_broker.py: IBKRBroker class wrapping ib_insync. Lazy-imports ib_insync so dry-run paths work fully offline (no TWS connection attempted). Banner / [OK] / [ERR] / [WARN] / '='*70 dividers match safe_cash_bot.py. - scripts/place_option_order_ibkr.py: CLI wrapper mirroring the RH script. Defaults to dry-run; --live requires TWS / IB Gateway on 127.0.0.1:7497. - tests/test_ibkr_broker.py: smoke tests with mocked ib_insync. Asserts dry_run=True does not connect or placeOrder; dry_run=False connects exactly once and calls placeOrder once with a LimitOrder of the right action / quantity / lmtPrice. - requirements.txt: add ib_insync>=0.9.86 (only needed for live). - .env.example: add IBKR_HOST / IBKR_PORT / IBKR_CLIENT_ID / IBKR_PAPER. - TRADING_SYSTEM_GUIDE.md: append IBKR setup section covering TWS / Gateway install, paper login, API socket port + read-only flag, trusted IP. Defaults to paper (port 7497). Live (7496) is opt-in via IBKR_PORT and IBKR_PAPER=false. Account is not yet funded; this PR scaffolds the plumbing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scaffolds Interactive Brokers as a second broker for single-leg equity option orders, alongside the existing Robinhood path. Mirrors the surface and logging style of
SafeCashBot.place_option_buy_limit_order/place_option_sell_limit_orderso call sites can swap brokers without changes.utils/ibkr_broker.py:IBKRBrokerwrappingib_insync, lazy-imported so dry-run paths work fully offline.scripts/place_option_order_ibkr.py: CLI mirroringscripts/place_option_order.py.tests/test_ibkr_broker.py: mocksib_insyncend-to-end; assertsdry_run=Truedoes not connect orplaceOrder(), anddry_run=Falseconnects exactly once and callsplaceOrder()once with aLimitOrderof the right action / qty /lmtPrice.requirements.txt:ib_insync>=0.9.86..env.example:IBKR_HOST/IBKR_PORT/IBKR_CLIENT_ID/IBKR_PAPER.TRADING_SYSTEM_GUIDE.md: appended a 10-line "IBKR setup" section.Notes
IBKR_PORTandIBKR_PAPER=false.safe_cash_bot.pyor any RH code.Test plan
pytest tests/test_ibkr_broker.py -v(2 passed)python scripts/place_option_order_ibkr.py XLY 2026-09-18 120 call 1 4.50 buy(dry run, no TWS, prints banner + dry-run gate)python scripts/place_option_order_ibkr.py XLY 2026-09-18 120 call 1 4.50 buy --livewithoutib_insyncinstalled -> clear[ERR]import message127.0.0.1:7497with API socket enabled: end-to-end--livepaper smoke