Options Flow Trading Bot in Python: The 4 Greek Gates
>This is one strategy of seven. Use Claude to Build 7 AI Trading Bots wires the Greek-aware flow bot into a multi-bot allocator with risk-parity sizing and drawdown circuit breakers.

Use Claude to Build 7 AI Trading Bots
Stocks, Options, Crypto. The Multi-Strategy Playbook for Backtest to Live Trade
Summary:
- Mirroring whale flow without managing Greeks bleeds premium to theta even when the entry was right.
- Four Greek gates cascade over every flow event: delta budget ≤ 0.20 per $100K, gamma cap |γ| ≤ 50 per $100K, IV-percentile < 80, theta sweep at -0.5 per day.
- Worked example: a 5,000 SPY 600C @ $4.20 whale event sizes to four contracts on a $10K account at 0.50 delta. Fail any gate, the trade dies.
- Copy-paste position-size and theta-sweep functions, ready to drop into your bot.
Most options flow trading bot Python tutorials stop at the detector. The bot mirrors the whale’s print and quietly bleeds every dollar of premium to theta over the next three days. The entry was right. The Greeks discipline was missing.

How do you size an options flow trade so it doesn’t blow up?
You run the flow event through four Greek gates in order and only place the trade when all four pass. Delta budget caps directional exposure per position. Gamma cap caps convexity at the portfolio level. IV-percentile filter refuses to pay for already-rich vega. Theta sweep closes the position when the daily bleed exceeds the directional thesis.
The gates are not optional. The gates are not a “best practices” suggestion. They are the discipline that separates a flow mirror that pays you from one that bleeds you. The whale who bought 5,000 of the SPY 600 calls at $4.20 was probably hedged, possibly playing vol, and definitely sized at a level your account cannot replicate. The four gates are your substitute for the hedge you cannot see.
If you have not touched options in a year, the four Greeks in one paragraph: delta is the option’s price sensitivity to a one-dollar move in the underlying. Gamma is the rate of change of delta. Theta is the dollar bleed per day from time decay. Vega is the option’s sensitivity to a one-percent change in implied volatility. All four show up in the gates below.
Gate 1: What is a delta budget and how do I compute mine?
A delta budget is your portfolio’s directional exposure ceiling per dollar of capital. The rule used here is 0.20 delta points per $10,000 of capital, allocated to a single position. On a $10K account, the per-position cap is 20 delta points. A 0.50-delta-per-contract call cleans out at four contracts. The math:
def position_size_by_delta(
account_equity: float,
delta_per_contract: float,
delta_budget_per_10k: float = 0.20,
) -> int:
"""Max contracts under the per-position delta budget.
delta_per_contract is the chain-quoted value (e.g. 0.50), not the multiplied form."""
delta_points_budget = (account_equity / 10000.0) * delta_budget_per_10k * 100.0
max_contracts = int(delta_points_budget / (delta_per_contract * 100.0))
return max_contracts
# Worked example: $10K account, 0.50-delta SPY call
size = position_size_by_delta(10000, 0.50)
# size == 4
Four contracts. Not 100. Not 30. The cap feels small because it is supposed to. Options blow up faster than equities; a 1 percent intraday move on the underlying produces roughly a 5 to 15 percent option-position move. Any larger size and the underlying’s normal noise wipes out a meaningful chunk of the account.
For 0.20-delta out-of-the-money calls, the $10K account allows five contracts. For 0.80-delta deep-in-the-money calls, two. No exceptions.
Gate 2: Why do I need a portfolio-level gamma cap?
Because positions with high gamma compound on each other. Three 0.50-delta at-the-money calls on three different names sounds diversified. Then the market drops 2 percent, every delta ratchets down to 0.20 simultaneously, and your portfolio’s effective short exposure has tripled in 30 minutes. That is gamma risk at the portfolio level.
The cap: sum of |gamma| across all open options positions, less than 50 per $100,000 of capital. On a $10K account, the cap is 5. On a $100K account, 50. The threshold scales with capital because gamma’s dollar impact does too.
def gamma_cap_ok(open_positions: list, account_equity: float) -> bool:
"""Returns True if a new position can fit under the portfolio gamma cap."""
total_abs_gamma = sum(abs(p.gamma) * p.contracts for p in open_positions)
cap = (account_equity / 100000.0) * 50.0
return total_abs_gamma < cap
When the cap is hit, the bot skips the trade. The temptation to override the cap on the trade you “knew was right” is the temptation that nukes you in the next 2 percent move. The cap is a structural protection, not a soft signal.
Gate 3: How do I avoid getting crushed by IV after a catalyst?
You skip every long-option trade when the underlying’s IV percentile is above 80. The IV is going to mean-revert downward after the catalyst, and the vega component of your option’s price will collapse alongside it. Direction can be right and you still lose money to vol.
A user on r/options put it more concretely than the chapter does (thread):
“Let’s use SPY. Spy starts falling, IV goes up. This makes options more expensive depending on how big the drops are. If you have a BIG drop, let’s be crazy and say 3%, IV is going to shoot up and increase the pricing of options. So near end of day of the 3% drop and you buy an At The Money put for a drop tomorrow. Tomorrow comes and it’s another drop! But it’s only .5% of a drop. Now IV is going to come down, and decrease the price of options. So basically even thought the price went down on the second day, your put may not be profitable because it lost the IV value.”
— u/GetNoobified, r/options “Understanding IV crush” thread
That is the trap, in retail-trader voice. The fix is mechanical:
def iv_filter_ok(iv_percentile_252d: float) -> bool:
"""Skip the trade if IV is in the top 20% of the trailing 12 months."""
return iv_percentile_252d < 80.0
The filter applies symmetrically. Long calls AND long puts get blocked above IVP 80. The whale you are mirroring might be playing vol; you cannot tell from the flow tape. Skip and wait. Expect the filter to reject 30 to 50 percent of would-be entries. That rejection rate is the strategy doing real work.
Gate 4: When should the bot close on theta bleed?
When theta exceeds -0.5 dollars per contract per day AND the underlying has not moved at least 50 percent of the way toward the strike. The option is bleeding faster than the directional thesis is paying. Closing is not because the trade is wrong; it is because the rent has gotten too high.
The close logic plus the days-to-expiry size multiplier in one block:
def theta_sweep_close(position) -> bool:
"""True if the position should close on theta-bleed grounds."""
bled_too_fast = position.theta < -0.5
underlying_dawdling = position.underlying_progress_toward_strike < 0.5
return bled_too_fast and underlying_dawdling
def dte_size_multiplier(dte: int) -> float:
"""Apply on top of the delta-budget cap.
Weeklies (DTE < 14) get sized at 25% to compensate for fast bleed.
Standard expiry and LEAPs run at 100%."""
if dte < 14:
return 0.25
return 1.0
A weekly that does not move in your favor in two trading days is dead. The 25 percent multiplier keeps a weekly from eating its premium before the directional thesis plays out. LEAPs (DTE > 90) have small daily theta and run at full size. Hard time-stop: the contract’s last two trading days, no exceptions, regardless of P&L.
What broke
Three failure modes hit this strategy in the first month of paper trading. Each one feels like the bot is broken. None of them mean the bot is broken.
The bot mirrors a hedge instead of a directional bet. The whale buys 10,000 of the December 600 calls. Your bot mirrors with 4. The whale was actually long 1,000,000 shares of the underlying and using the calls as a downside hedge. Whale’s calls expire worthless, whale is happy. Your calls also expire worthless and you are confused. The IV filter catches most pre-event hedges; the theta sweep catches the rest.
The gamma cap rejects a trade you “knew” was right. Three previous positions are open. A new flow signal arrives that you really like. Do not override the cap. It is the structural protection against a 2 percent adverse market move blowing up your portfolio. Close one of the existing positions or skip the new trade.
Theta sweep closes a position the day before a catalyst. Bot exits at -0.5/day theta. Next day the underlying gaps 8 percent in your direction. The temptation is to lower the theta threshold. Resist. The sweep is your protection against the 80 percent of cases where the underlying does not gap.
How does the bot wire the gates together?
You run them in order. First gate fails, the trade dies; the bot logs the rejection reason and moves on. All four gates pass, the bot places the order, sized by the minimum of the delta budget and the DTE multiplier.
def process_flow_event(event, account, open_positions, chain_quote):
if not iv_filter_ok(chain_quote.iv_percentile_252d):
return "skipped: IVP >= 80"
if not gamma_cap_ok(open_positions, account.equity):
return "skipped: gamma cap"
base_size = position_size_by_delta(account.equity, chain_quote.delta)
sized = int(base_size * dte_size_multiplier(chain_quote.dte))
if sized == 0:
return "skipped: delta budget collapses to zero"
return account.place_paper_order(event.symbol, sized, "buy", "market")
Logging the rejection reason is non-negotiable. After a month of running, the rejection log tells you which gate is doing the most work. If the IV filter is rejecting 60 percent and the delta budget is rejecting 0 percent, the bot is concentrated on a market regime where the IV filter matters most; that is information about the regime, not a bug. If the gamma cap is rejecting 80 percent, the portfolio is over-invested in directional risk; close some positions or fund the strategy harder.
What should you actually do?
- If you are running a flow mirror bot today with no Greek discipline → bolt on the IV-percentile filter first. It is the single highest-impact gate; expect 30-percent of would-be losers to disappear in week one.
- If you have IV crush handled but get whipsawed by theta → ship the theta sweep next. It catches the slow bleeds that the IV filter misses.
- If you are running multiple positions and the portfolio P&L swings violently on small market moves → the gamma cap is your missing piece. Compute the running sum-of-absolute-gammas and refuse new entries above 50 per $100K.
- If you can only afford one gate this weekend → IV percentile. Always IV percentile. Theta and gamma are damage control; IV is the trap that kills retail flow mirrors most often.
- If the bot’s rejection log shows zero rejections after a week → one of your gates is broken. The thresholds in this article reject 30 to 50 percent of inbound events on real flow data; zero rejections means the gates are not running.
bottom_line
- The gates cascade. Fail any one and the trade dies. The discipline is the strategy.
- IV percentile above 80 is not a “risk to manage.” It is a known cost the bot refuses to pay. Treat the filter as a hard skip, not a soft signal.
- Theta is rent. The sweep at -0.5 per day is the rule that says when the rent has gotten too high. There is no “ride the theta because the catalyst is coming.” When you find yourself making that argument, the sweep is correctly trying to save you.
Frequently Asked Questions
Why did my mirrored whale trade lose money even though the underlying moved up?+
Because the whale was probably hedged on the other side, IV got crushed after the catalyst, and your calls bled to theta while the underlying took its time. You mirrored the position, not the Greeks discipline. The four-gate cascade in this article is what closes that gap.
What is a delta budget and how does it cap position size?+
A delta budget is your portfolio's directional sensitivity ceiling per dollar of capital. The rule used here is 0.20 delta points per $10,000 of capital, allocated to a single position. On a $10K account, a 0.50-delta call is capped at four contracts before any other Greek gate runs.
How do I avoid IV crush after earnings?+
Skip every long-option trade when implied volatility percentile is above 80. The IV is mean-reverting downward after the catalyst and the vega component of your option's price collapses. The filter rejects 30 to 50 percent of would-be entries; that rejection rate is the strategy doing real work.
More from this Book
Claude Trading Bot Hallucination: 8-Point Backtest Check
Catch Claude trading bot hallucination before live capital. Walk-forward backtest, 68% win-rate paradox, 8-point checklist, separate-session reproduction.
from: Use Claude to Build 7 AI Trading Bots
Cointegration Pairs Trading Python: Z-Score and Hedge Ratio
Cointegration pairs trading in Python with statsmodels: Engle-Granger test, Z-score entries at ±2.0, hedge-ratio sizing, 20-day time-stop, VIX regime filter.
from: Use Claude to Build 7 AI Trading Bots
Crypto Funding Rate Arbitrage Bot: BTC Cash and Carry
Build a crypto funding rate arbitrage bot in Python. Long spot, short perp, collect funding every 8 hours when the rate exceeds 0.025%. Delta-neutral basis.
from: Use Claude to Build 7 AI Trading Bots
Multi Strategy Trading Bot Python: Risk Parity Allocator
Multi strategy trading bot Python build: risk-parity capital sizing, 90-day correlation drop rule, drawdown circuit breaker, and intent netting at the broker.
from: Use Claude to Build 7 AI Trading Bots