test: add exchange, strike, and session-flag unit tests - #105
Merged
kunalrbhatia merged 2 commits intoAug 20, 2026
Conversation
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.
Incident & Hardening Summary
PR #104 (
f395f7a) addressed three core issues encountered during the 20-Aug SENSEX launch:doOrderdefaultedexchange = 'NFO'while SENSEX options trade on BFO. Angel rejected orders withAB4046 Symbol token not found in scrip master cache for the given exchange. Fixed by resolving exchange from the trading symbol viagetExchangeForIndex(getIndexFromSymbol(tradingsymbol)).updateLivePositionsandpaperTradeused anchored regex matching only NIFTY-style symbols. SENSEX numeric dates (SENSEX2682077400CE) failed to match, setting strike to'0'and triggering continuous straddle rolls every tick. Fixed with regex/(\d{5})([CP]E)$/.shortStraddle()marked the session opened unconditionally even on rejected orders. Fixed by guardingsetStraddleOpenedTodayto require both SELL legs to returntypeof result === 'object' && result.status === true.This PR adds complete unit tests, regression verification, code comments, and operational documentation.
Part A — Review PR #104 & Unit Test Coverage
Added robust unit tests in
__tests__/helpers/apiService/:orders.test.ts):doOrderwithout explicit exchange + SENSEX symbol (SENSEX2682077400CE) -> resolvesBFO.doOrderwithout explicit exchange + NIFTY symbol (NIFTY26AUG24200CE) -> resolvesNFO.doOrderwith explicit exchange (CUSTOM_EXCH) -> preserves explicit exchange.closeParticularTradefor SENSEX position -> sends close BUY order toBFO.positions.test.ts+positions.ts&paperTrade.ts):NIFTY26AUG24200CE-> 24200 / CESENSEX2682077400CE-> 77400 / CESENSEX26AUG76800PE-> 76800 / PEBANKNIFTY26AUG50000CE-> 50000 / CENIFTYFPI25AUG261320PEparses as 61320 instead of 1320; algo never trades FPI segment).strategy.test.ts):{ status: true }->setStraddleOpenedTodaycalled.{ status: false }-> flag NOT set.undefined-> flag NOT set, no error thrown.Part B — NIFTY Tuesday Regression Evidence
OPTIDXscrips starting withNIFTY(excludingFPI) inscripMaster.json.strikefield (strike / 100).getExchangeForIndex('NIFTY')remains strictly'NFO'(BFO returned only for SENSEX).expiry-reports/backtest-2026-02-to-2026-08.md): ₹40,188.75 across expiry Tuesdays, 65.2% WR.Part C — Code Gap Verification
shortStraddle(false)does NOT callsetStraddleOpenedToday(flag is entry-only).placeStoplossForAllSells: Confirmed no hardcodedexchange: 'NFO'remains;doOrderresolves exchange dynamically from symbol.closeTrade:closeParticularTradepasses trade position todoOrderwhich resolves SENSEX symbols toBFO. Tested and verified.'0'.Part D — Gateway Collector Throttling (OPS Note)
Incident Root Cause: The gateway PM2 daemons
optionchain-liveandsensex-livepoll SmartAPI every 10 seconds24/7using the same API key (K94372) as the algo, causing rate limit 403 errors during the first trading hour.Recommended Ops Fix (Gateway Deployment):
src/live.jsandsrc/sensex-live.jssleep duration on gateway server from10000(10s) to300000(5 minutes).collect-once.jscron.Verification Checklist
pnpm verifypassed cleanly (prettier, eslint, tsc --noEmit, jest276/276tests).fix/sensex-hardening-and-regression-tests.