Unknown symbol after socket reconnection

Every once in a while, the WebSocket reconnection results into a strange behaviour, returning an object like below,

msg:{'ltp': 24965.0, 'vol_traded_today': 2671275, 'last_traded_time': 1759477197, 'exch_feed_time': 1759477198, 'bid_size': 75, 'ask_size': 1950, 'bid_price': 24961.1, 'ask_price': 24965.0, 'last_traded_qty': 150, 'tot_buy_qty': 392700, 'tot_sell_qty': 375750, 'avg_trade_price': 24926.07, 'low_price': 24878.6, 'high_price': 24972.2, 'lower_ckt': 0, 'upper_ckt': 0, 'open_price': 24950.4, 'prev_close_price': 24967.2, 'type': 4, 'symbol': 8, 'ch': -2.2, 'chp': -0.0088}

I had similar issue in past but this time around the symbol names are integers, not some strange values.

Hello @aewitoADpV, a member of our team has reached out and resolved your query. Please let us know if you need any further assistance.

FYI, I’m subscribing to DepthUpdate and SymbolUpdate data types together as suggested in the answer from the post below.
https://fyers.in/community/t/question-is-it-possible-to-subscribe-to-depthupdate-and-symbolupdate-data-type-togather/13591
Can this setup create any issues, similar to those mentioned above?

Not resolved yet, but they’ve asked me to observe using a sample script. I’ll do that and report back.

@aewitoADpV, a member from our team confirmed and verified that there is no such issue with symbol even after several reconnects. Please, check with the sample code and verify once.

Hi @DO4oDGcq5n ,

I faced this issue today as well, I’ll put here exactly how to recreate it.

on_connect call back

## self.data_types = ["SymbolUpdate", "DepthUpdate"]
## self.symbol = ['NSE:NIFTY25O1425300CE', 'NSE:NIFTY25O2025250PE', 'NSE:NIFTY25O1425300PE', 'NSE:NIFTY25O2025150CE', 'NSE:NIFTY25O1425150CE', 'NSE:NIFTY25O2025300CE', 'NSE:NIFTY25OCTFUT', 'NSE:NIFTY25O2025250CE', 'NSE:NIFTY25O1425350CE', 'NSE:NIFTY25O2025350PE', 'NSE:NIFTY25O2025150PE', 'NSE:NIFTY25O1425200CE', 'NSE:NIFTY25O1425150PE', 'NSE:NIFTY25O1425250CE', 'NSE:NIFTY25O1425250PE', 'NSE:NIFTY25O1425350PE', 'NSE:NIFTY25O2025200CE', 'NSE:NIFTY25O2025200PE', 'NSE:NIFTY25O1425200PE', 'NSE:NIFTY25O2025350CE', 'NSE:NIFTY25O2025300PE', 'NSE:NIFTY50-INDEX', 'NSE:INDIAVIX-INDEX']

@handle_exception(svc=service)
    def on_connect(self):
        for data_type in self.data_types:
            c_symbol = self.symbol
            if data_type == 'DepthUpdate' and 'NSE:NIFTY50-INDEX' in c_symbol:
                c_symbol.remove('NSE:NIFTY50-INDEX')
                c_symbol.remove('NSE:INDIAVIX-INDEX')

            self.data_socket.subscribe(data_type=data_type, symbols=c_symbol)
            self.logger.trace(f"subscribed symbols: {self.data_socket.symbols}, scrips: {self.data_socket.scrips}")

        # Keep the socket running to receive real-time data
        self.data_socket.keep_running()

I understand that sample script doesn’t get this error, but real-world implementations are much complex.

The only reason I have to subscribe to “SymbolUpdate”, “DepthUpdate” both is because the symbol update socket doesn’t provide depth data.

can we please take a look into it?

for now, I’ve added a fix that mitigates it by forceful reconnection.

# self.ff_rebalance_limit = 6
# in on_message callback after checking for all expected types
                # symbol and type come as integers
                elif isinstance(msg['symbol'], int) and isinstance(msg['type'], int):
                    self.logger.warn(f"Fyers issue:{msg}")
                    if self.ff_rebalance_limit > 0:
                        self.invoke_rebalance() # my custom function to unsubscribe and resubscribe
                        self.ff_rebalance_limit -= 1
                else:
                    self.logger.info(f"msg:{msg}")

I hope this helps recreating the issue on your side.

Hi @DO4oDGcq5n ,

I was finally able to recreate the issue in the sample script.

I’ve already sent all the details to the API-support email chain, which includes Vinith.

Thanks,

Parth

Last verdict on this from Fyers is not to use multiple data type subscriptions (refer to my comments below). As of now, there is no way to subscribe to depth and symbol update together.

@Fyers, I would highly recommend having at least 5 recent depth updates with Full mode for every supported symbol.