Instrument metadata is synced from Zerodha Kite into the IndexSetting collection by syncIndexSettings() in indexSettingGenerator.ts. For the full settings lifecycle see Index settings lifecycle.

Sync entry point

When sync runs

After sync, active symbols (isActive: true) emit indexSettingUpdated, which triggers the event processor to reload subscriptions.

Kite API call

syncIndexSettings() calls Kite Connect getInstruments() in parallel for NSE, NFO, MCX, CDS. Requires a valid Zerodha access token via getKiteConnectInstance().

What gets populated

Options

  • optionChainByExpiry — strikes, CE/PE tradingsymbols, tokens, lot sizes per expiry
  • baseDiff per expiry (computed from strike spacing)
  • optionExpiriesByFuturesExpiry when using futures underlying

Futures

  • futuresChainByExpiry — contract symbols per expiry date
  • instrumentToken, lotSize, contractFormat for active expiry

Cash

  • tradingsymbol, instrumentToken, lotSize from NSE EQ instrument master

Auto-detected fields

  • tradingModes — { cash, futures, options } based on available instruments
  • activeSegment — priority: options → futures → cash
  • optionsUnderlyingType — SPOT or FUTURES via detectOptionsUnderlyingType()

Preserved on sync

Admin-controlled fields from the existing document are not overwritten:
  • isActive
  • Recurring/trailing flags, quantities, durations, limits, market protection
  • callDifference, putDifference, strike match values
  • lastActiveRight

Expiry rollover

  • Futures: pickDefaultFuturesExpiry() in optionExpiryMapper.ts
  • Options: resolveOptionExpiryAfterInstrumentSync() in resolveOptionsUnderlying.ts

Supporting modules

Runtime refresh after sync

When indexSettingUpdated fires:
  1. Event processor reloads active settings
  2. Clears cached strikes for affected index
  3. Resubscribes base and option tokens on Kite Ticker

Debug endpoint

GET /zerodha/instruments exposes cached instrument dump for debugging. Production sync uses getInstruments() internally during syncIndexSettings(), not on every admin save.