[QUESTION] is it possible to subscribe to DepthUpdate and SymbolUpdate data type togather?

HI Fyers Team,

I recently tested my Fyers socket implementation with SymbolUpdate and DepthUpdate data types together.

It appears that the WebSocket ignores the data type DepthUpdate when it’s accompanied by SymbolUpdate or any other data type. Here, running the socket with the DepthUpdate data type with the same set of symbols works.

Is this possible? Am I doing something wrong here? (My code implementation below)

    @handle_exception(svc=service)
    def on_connect(self):
        """
        Callback function to subscribe to data type and symbols upon WebSocket connection.

        """
        # Specify the data type and symbols you want to subscribe to
        data_type = "SymbolUpdate,DepthUpdate"

        # data_type = "OnOrders"
        # data_type = "OnPositions"
        # data_type = "OnGeneral"
        # data_type = "OnOrders,OnTrades,OnPositions,OnGeneral"

        self.dataSocket.subscribe(data_type=data_type, symbols=self.symbol)

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

In the on_message function, I am just printing the message object,

            elif msg['type'] == 'dp': # here type='dp' is depth update
                print(msg)

Thanks,

Parth

Hello @aewitoADpV, you can create only one WebSocket connection instance at a time. This approach ensures stability and prevents issues that might arise from multiple concurrent connections. For more details, please refer to the following link: https://myapi.fyers.in/docsv3#tag/Web-Socket

I think you misunderstood my question, here I am using one WSS instance running multiple data types.

Documentation for general socket has code below that suggest subscription for multiple data type subscription.

https://myapi.fyers.in/docsv3#tag/Web-Socket/paths/~1GeneralSocket/patch

I’m trying similar thing with SymbolUpdate and DepthUpdate data types.

The question is, are they incompatible with each other?

Hi @aewitoADpV ,
Please find the code snippet below. Also, based on the data types, the onmessage should handle the socket messages accordingly.

# Initialize additional data types

data_type = "SymbolUpdate"

data_type2 = "DepthUpdate"

# Subscribe again different data types

symbols = ['NSE:SBIN-EQ', 'NSE:ADANIENT-EQ']

fyers.subscribe(symbols=symbols, data_type=data_type)

fyers.subscribe(symbols=symbols, data_type=data_type2)

Great, thanks for this. I’ll try this tomorrow and report back.

Thanks @BTlqgYCtY9, This worked!

FYI, who might stumble upon this in future, don’t use this method since it’s error-prone and Fyers don’t recommend using it.

https://fyers.in/community/t/unknown-symbol-after-socket-reconnection/13620