MarketDataStreamerV3 connects then disconnects with 1000 when subscribing programmatically

I’m using MarketDataStreamerV3 (Java SDK) to stream Mode.FULL option feeds (I need option Greeks/delta). The streamer connects successfully and I can subscribe & receive live updates if I call subscribe(...) from one code path (e.g., after my evaluateAndPlace()), but when I call the same subscribe(...) from another method (e.g., findStrikePrices() where I compute a list of instrument keys and call subscribeNew(key)), the socket connects then immediately disconnects with close code 1000 (normal closure). I don’t see an explicit error — just a close with code 1000 and reason blank.

What I expect

  • streamer.connect()onOpenstreamer.subscribe(keys, Mode.FULL) → continuous onMarketUpdate messages with fullFeed.marketFF.optionGreeks.delta.

  • No unexpected disconnects (or a clear error/ack if subscribe is rejected).

What I see

  • onOpen fires and logs show subscription attempt succeeded.

  • I receive one marketUpdate with many Feed entries (option data + Greeks).

  • Immediately afterwards the WS onClose is invoked with statusCode=1000 and empty reason.

  • This behavior depends on where I call subscribeNew(key) from: one caller works fine; another causes the disconnect.

Minimal relevant logs
INFO UpstoxMarketAdapterImpl ensureStreamerStarted [UPSTOX] Connecting streamer…
INFO DeltaTradingService init DeltaTradingService initialized - waiting for Nifty open price…
INFO UpstoxMarketAdapterImpl lambda$0 [UPSTOX-WS] Connected
INFO UpstoxMarketAdapterImpl lambda$0 [UPSTOX] subscribing pending keys (FULL): [NSE_INDEX:NIFTY_50]
INFO UpstoxMarketAdapterImpl lambda$0 [UPSTOX] subscribed pending keys: [NSE_INDEX:NIFTY_50]
INFO OptionChainService lambda$7 Update: MarketUpdateV3{ type=null, feeds={NSE_FO|53023=Feed{ fullFeed=FullFeed{ marketFF={ ltpc={ltp=75.8}, optionGreeks={delta=0.3302, …} }}} … }, requestMode=full_d5 }
INFO OptionChainService lambda$9 statusCode :1000, reason:

Another run where I subscribe many FO keys at once:
INFO OptionChainService subscribeNew Keys: [NSE_FO|52851, NSE_FO|52855, …, NSE_FO|53027]
INFO OptionChainService lambda$7 Update: MarketUpdateV3{ type=null, feeds={NSE_FO|53023=Feed{ fullFeed=FullFeed{marketFF={optionGreeks=OptionGreeks{delta=0.3302,…}}}}, …}, requestMode=full_d5 }
INFO OptionChainService lambda$9 statusCode :1000, reason:

Relevant code excerpts (subscription / connect)
// create streamer
final ApiClient defaultClient = Configuration.getDefaultApiClient();
final OAuth oauth = (OAuth) defaultClient.getAuthentication(“OAUTH2”);
oauth.setAccessToken(tokenService.getAccessToken());
streamer = new MarketDataStreamerV3(defaultClient);

streamer.setOnOpenListener(() → {
log.info(“[UPSTOX-WS] Connected”);
if (!keys.isEmpty()) {
streamer.subscribe(keys, Mode.FULL);
log.info(“subscribed keys : {}”, keys);
}
});

streamer.setOnMarketUpdateListener(marketUpdate → {
log.info(“Update: {}”, marketUpdate);
// process feeds…
});

streamer.setOnCloseListener((statusCode, reason) → {
log.info(“statusCode :{}, reason:{}”, statusCode, reason);
disconnect();
});

streamer.connect();

Hi @Manish_Khodaliya, In the first case you’re using the wrong instrument key — you passed NSE_INDEX:NIFTY_50; use NSE_INDEX|Nifty 50instead.

Also check whether your code is calling streamer.disconnect() anywhere, and also verify your internet connection is stable.

If the problem persists, please share the full code so we can investigate further.

Thanks

Sure, I will check. Thank you @Anand_Sajankar