test: add SENSEX hardening unit tests and fix market close exit window - #108
Merged
kunalrbhatia merged 2 commits intoAug 20, 2026
Merged
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 Summary & Hardening Review
This PR adds unit tests, closes remaining operational and code gaps, and provides regression verification for the 20-Aug-2026 SENSEX expiry launch incident.
Key Gaps Closed & Improvements Made:
Market Close Exit Window Bug (
isMarketClosed):isMarketClosed()previously hardcoded{ hours: 15, minutes: 30 }as market close cutoff.EXIT_TIMEwas set past 15:30 (e.g. 15:35),isMarketClosed()evaluated totrue, causingisTradeAllowed()to fail withConditions not right... Reasons: Market closed. BecauseexecuteTrade()was gated behindisTradeAllowed(),closeTrade()never ran automatically.isMarketClosed()now evaluates upper bound usingappConfig.exitTime(defaulting to 15:40 F&O close bound).checkMarketConditionsAndExecuteTradealso allows execution if past exit time so trade close is never blocked by market entry gates.Roll Decision Logging & Strikeprice Data-Integrity Guard (
repeatShortStraddle):difference,strikeDiff,isSameStrikeAlreadyTraded,cepe_present,previousTradeStrikePrice,atmStrike) before any branching decisions.strikeprice === '0'or unparseable strike, or ifpreviousTradeStrikePrice === 0, the roll decision is skipped with a warning.updateLivePositionsso existing positions also refreshstrikepriceandoptiontypeif previously invalid.NODE_ENV/ Jest Execution Gate for File Writes:writeToFileinsrc/helpers/logger.tsand scrip master cache file writes insrc/helpers/apiService/marketData.tsonprocess.env.NODE_ENV !== 'test'.scripMaster.json.Exchange Resolution & Code Commenting:
doOrderexchange resolution (exchange || getExchangeForIndex(...)) is applied only as fallback whenexchangeis omitted.NIFTYFPI25AUG261320PEparsing strike as 61320 in FPI segment) in code comments.NIFTY Regression Evidence
OPTIDXsymbols starting withNIFTY(excluding FPI) againstscripMaster.json(156,812 scrips):/^([A-Z]+)(\d{2}[A-Z]{3}\d{2})(\d+\.?\d*)([CP]E)$/and the new suffix regex/(\d{5})([CP]E)$/.getExchangeForIndex('NIFTY')returns'NFO'.straddleOpenedTodayasfalseto enable retry on the next tick.pnpm verifysuite (pnpm format; pnpm lint; pnpm typecheck; pnpm test; pnpm build) runs 100% green (24 test suites, 277 tests passing).Collector Throttling (Ops / Deployment Note)
optionchain-liveandsensex-livePM2 daemons poll SmartAPI every 10s using API keyK94372, causing rate limit 403 HTTP errors during live algo order placement.src/live.jsandsrc/sensex-live.jsfrom 10s (10000) to 5 minutes (300000), or rely on the 5-minutecollect-once.jscron during expiry day trading windows (9:15–15:40 IST).