fix: hedge-walk infinite retry for SENSEX caused duplicate hedges - #118
Merged
Merged
Conversation
…ent) SENSEX had strikeVariance=0 in shortStraddle hedge walk → when the far PE hedge LTP was > 3, the retry loop re-attempted the SAME strike forever. The SELL legs never placed → straddleOpenedToday never set → every cron tick spawned a new process that bought ANOTHER CE hedge before blocking again. Result: 500 qty (25 lots) of CE hedges instead of 100 (5 lots). Fix: walk hedge strikes in 100-point steps for SENSEX (50 for NIFTY) and cap hedge attempts at 5 — proceed with the straddle SELLs even if a hedge can't be placed, so straddleOpenedToday gets set and duplicate entries are prevented. Live hotfix applied 09:55 IST (dist rebuilt); excess hedges flattened via manual SELLs (broker-verified 0 open). Formalized per PR #104 pattern.
This was referenced Sep 3, 2026
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
Fix the SENSEX hedge-walk infinite retry loop that caused duplicate hedge buys on 3-Sep.
Incident (3-Sep 2026, SENSEX expiry)
At 09:30 the algo entered
shortStraddle(true)(ATM 76800). The CE hedge (78300, +1500) filled, but the PE hedge (75300) had LTP ~3.5 > 3 →doOrderByStrikereturned false → the retry loop re-attempted the SAME strike forever because SENSEXstrikeVariancewas 0 (only NIFTY had 50). The straddle SELL legs never placed →straddleOpenedTodaynever set → every 5-min cron tick spawned a NEW process that ranshortStraddle(true)again → each bought ANOTHER CE hedge before blocking again. By 09:50: 5 CE-hedge BUY orders (78300 ×200, 78400 ×300 = 500 qty / 25 lots) instead of 100 qty / 5 lots.Fix
straddleOpenedTodayis set → duplicate entries prevented.strikeIncrementfor the PE loop (was cumulatively inherited from CE).Verification
MAX_HEDGE_ATTEMPTS+ walk logging present.Notes