nifty_fifty_bank_nifty_NodeJS/src/controllers/scheduleOrder.controller.tsFlags:
options.isRecurringSell (options segment only)
What it does
After a completed unsold BUY, the system schedules a SELL, then a trailing loop watches index price and exits when strike-match or target conditions are met. This strategy uses two separate 1-second loops:Loop 1 — Schedule creation (startScheduleOrder)
Per-index interval registered as scheduleOrder_${indexName} (~1s):
- Requires
activeSegment === "options",lastActiveRight, andisRecurringSell. - Skips when exchange is closed or tick data is missing.
- Finds the oldest eligible BUY with status COMPLETE (
isSold: false,isScheduled: false). Orders still inTRIGGER PENDINGare not scheduled yet. - Marks that buy as scheduled and creates a
ScheduleOrderwith:strikeMatchPricefrom index base ± strike match differencetargetPricefrom base ± target sell % of basetimeDurationfromcallSellDuration/putSellDuration
- If there is no open BUY and no pending schedule, it switches leg (CALL ↔ PUT): stops the current recurring buy side and starts the opposite side when that side’s recurring buy flag is enabled. Resets
firstCandleEndTimefor the index on leg switch.
marketSessionManager.startOrderServicesForSymbol.
Loop 2 — Trailing exit (startInterval + trailingSell)
Global 1s loop started/stopped by marketSessionManager.syncTrailingSellInterval() (runs when at least one exchange session is open; stopped on session close):
- Reads latest tick from
latestDataMap[$TickData]for each active symbol. - Uses candle range from
timeDurationto compute min/max of indexbaseValue(fromindexDataModelaggregation plus in-memory tick buffer at candle end). - Tracks
firstCandleEndTimeper index; reset viamarketDataEmitter.resetFirstCandleEndTimeor on leg switch. - Updates trailing
strikeMatchPrice:- First candle: keep initial strike match price
- Later candles: CALL uses candle min, PUT uses candle max
- Price match conditions:
- PUT: exit if
baseValue >= strikeMatchPrice, orbaseValue <= targetPrice(when target is set) - CALL: exit if
baseValue <= strikeMatchPrice, orbaseValue >= targetPrice(when target is set)
- PUT: exit if
- On match,
executeSideSellOnceplaces MARKET SELL for all pending schedules on that right (linked to parent BUY viaparent_order_id). - On failed SELL, rolls back parent
isSoldand schedule status toPending.
Schedule cancellation
PUT /api/scheduleOrder/:id (admin) with status: "Cancelled" cancels the schedule and reverts the parent BUY (isSold: false, status CANCELLED).
Important limits
- Recurring / trailing sell scheduling is options-only today; cash and futures do not use this sell scheduler.
- Sell execution from trailing is MARKET.