We’re building market-data analytics for NIFTY options at OptionsLab (https://optionslab.in), and we’ve been working with Fyers TBT 50-level depth for order book / flow visualization.
Two things we’d like to hear other people’s experience on:
Opening a second WebSocket session on the same token gives error -300. How do you handle multiple consumers (option chain, depth, stocks) with a single session?
How do you handle reconnects and book resync after a TBT drop?
Also curious whether anyone is subscribing only to the strikes currently on screen to stay within symbol limits.
Note: this is about market-data engineering only, not trading advice or signals.
I run several WebSocket connections on one access token without trouble. Four separate programs each have their own data socket, and another program runs a price socket and a depth socket side by side. -300 isn’t a server-side “second session” error. It’s the Python SDK’s catch-all client-side code, raised for an invalid symbol, an index symbol in a depth subscription (“Index does not have market depth”), a failed symbol lookup, or a token it can’t decode. Check the message that comes with it.
The trap with more than one socket in one Python program is that FyersDataSocket, FyersOrderSocket and FyersTbtSocket are singletons. Creating a “second” socket hands you back the first one, with its callbacks overwritten. I set FyersDataSocket._instance = None before constructing each one. The other way is to run one socket per program and pass the data to the rest of your program yourself. As far as I can tell, all your connections share one symbol limit. Over it, the whole subscribe is refused (11011, or 51001 on SDK 3.2.0), not just the extra symbols.
On TBT reconnects, the SDK reconnects but doesn’t resubscribe. In on_open I call subscribe and switchChannel(resume) again. Use on_open, not on_connect, because the SDK overwrites on_connect. The SDK’s merged book is never cleared, so I use diff_only=True, keep my own book, and reset it when snapshot=True arrives. Expect the previous session’s closing book on connect, and snapshots with exchange time 0. Order by seqNo, and use SDK 3.1.19 or later, because earlier versions placed deep levels out of order. The SDK stops after 50 failed reconnects without telling you, so watch the age of the last message.
On strikes on screen: yes, I subscribe a window of strikes around ATM within a fixed symbol budget and move it as the market moves. I unsubscribe the old strikes before subscribing the new ones, so a request never goes over the limit.
One correction to my last point, for the Python SDK. FyersDataSocket.unsubscribe only works for symbols from the channel’s most recent subscribe call. The SDK replaces its record of a channel’s symbols on every subscribe instead of adding to it. So unsubscribing a symbol from an earlier call fails with -300 “Please provide a valid symbol”, and the symbol stays subscribed and keeps counting against your limit. It was reported in topic 13378 in 2024 and is still in 3.2.0. Watch on_error for that -300 after an unsubscribe. The safe way to move a strike window is to reconnect with the new set. The TBT socket doesn’t have this problem.