Add single-leg option order support (buy-to-open, sell-to-close)#59
Merged
Conversation
Adds two methods on SafeCashBot: - place_option_buy_limit_order(symbol, expiration, strike, option_type, quantity, price, dry_run=True, time_in_force='gtc') - place_option_sell_limit_order(...) -- close-only, validates that the contract is currently held before sending. Both wrap robin-stocks order_buy_option_limit / order_sell_option_limit and follow the existing dry_run / banner / account-isolation pattern from place_cash_buy_order. Buy validates against buying power; sell validates against open option positions. Single-leg only (no spreads). Adds a CLI scripts/place_option_order.py mirroring scripts/place_single_order.py: python scripts/place_option_order.py XLY 2026-09-18 120 put 1 4.50 buy python scripts/place_option_order.py XLY 2026-09-18 120 put 1 4.50 buy --live python scripts/place_option_order.py XLY 2026-09-18 120 put 1 6.75 sell --live Motivated by buy-and-bracket (entry buy-limit + take-profit sell-limit) workflows for the variance-Kelly strategies in allocation-gym.
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
Adds option-order placement to allocation-engine. Until now,
SafeCashBotonly placed stock orders; option support was read-only. This PR adds two single-leg methods plus a CLI wrapper, so the engine can run buy-and-bracket workflows (entry buy-limit + take-profit sell-limit) on equity options through Robinhood (robin-stocks).New methods on
SafeCashBotBoth follow the existing
place_cash_buy_order/place_sell_orderpattern: dry-run default, account-locked toRH_AUTOMATED_ACCOUNT_NUMBER, banner logging, and pre-trade validation.quantity * price * 100chain_symbol,expiration_date,strike_price,type)New CLI
Motivation
The
allocation-gymvariance-Kelly framework recommends 3M ATM option overlays (see allocation-gym docs/12 buy_recommendations_2026_05). Without programmatic option entry, all option trades had to be placed manually in the RH app. This unlocks scripted execution of the same buy-and-bracket pattern that produced the +57% / +103% IWN-put round-trips in docs/9/ytd_performance.Test plan
python -m py_compileclean on both filesscripts/place_single_order.py)