Tick-by-Tick (TBT) Socket - Channels and Message Types
This guide explains how to group Tick-by-Tick symbols into channels and pause or resume their streams.
USE CASE
Group your Nifty and Bank Nifty symbols into channels and switch each group on or off with one message.
With the Tick-by-Tick (TBT) WebSocket, we are introducing the concept of channels. A channel acts as a logical grouping for different subscribed symbols, making it easier to manage data streams efficiently.
How Channels Work
- When subscribing to market data, you need to specify both the symbols and a channel number.
- Simply subscribing to a channel does not start the data stream—you must also resume the channel to begin receiving updates.
Example Usage
Let's say you organize your subscriptions as follows:
- Channel 1: All Nifty-related symbols
- Channel 2: All BankNifty-related symbols
Now, depending on what data you need, you can control the channels dynamically:
- Receive only Nifty data → Pause Channel 2 and Resume Channel 1
- Receive only BankNifty data → Pause Channel 1 and Resume Channel 2
- Receive both Nifty and BankNifty data → Resume both channels
This approach provides greater flexibility and control over market data streaming, allowing you to filter and manage real-time data efficiently.
Details
- Every subscribe and unsubscribe request carries a channel number. A connection supports 50 channels (1 to 50). See Rate limits for symbol and connection limits by plan.
- Subscribing to a channel does not start the stream. Send a switch-channel request (
type2) with the channel inresumeChannelsto start it. - Use
pauseChannelsandresumeChannelsin the same request to switch between groups. Both lists hold channel numbers as strings; the sample sends an emptypauseChannelslist. - Subscribe uses
subs1 and unsubscribe usessubs-1, both withtype1 andmodedepth. - Responses are protobuf.
snapshotis true for the first full packet and false for diff packets. Whenerroris true,feedsis empty. - Each depth level has
price,qty,nordandnum. For 50 levels,numruns from 0 to 49.
Request Message Types
| Type | Purpose | Encoding Format | Data Format |
|---|---|---|---|
Ping | Ping message to keep connection alive | String | "ping" |
Subscribe | Subscribe to the symbols for which data is required | Json string | {
"type": 1,
"data": {
"subs": 1,
"symbols": [
"NSE:IOC25FEBFUT",
"NSE:NIFTY25FEBFUT",
"NSE:BANKNIFTY25FEBFUT",
"NSE:FINNIFTY25FEBFUT",
"NSE:TCS25FEBFUT"
],
"mode": "depth",
"channel": "1"
}
} |
Unsubscribe | Unsubscribe to the symbols for which data is NOT required | Json string | {
"type": 1,
"data": {
"subs": -1,
"symbols": [
"NSE:IOC25FEBFUT",
"NSE:NIFTY25FEBFUT",
"NSE:BANKNIFTY25FEBFUT",
"NSE:FINNIFTY25FEBFUT",
"NSE:TCS25FEBFUT"
],
"mode": "depth",
"channel": "1"
}
} |
Switch Channel | Switch between active and paused channels | Json string | {
"type": 2,
"data": {
"resumeChannels": ["1"],
"pauseChannels": []
}
} |
Response Message Types
We use Protocol Buffers (protobuf) as the response format for all market data. The .proto file, which defines the data structure, is available at:
Protobuf is a widely used data format, and compilers are available to generate code in different programming languages.
How to install and use Protobuf
- Protobuf Compiler Installation: https://protobuf.dev/getting-started/
- Using Protobuf with Python: https://protobuf.dev/reference/python/python-generated/
- Using Protobuf with Node.js: https://www.npmjs.com/package/protobufjs
We have uploaded the compiled files also for python, nodejs, and golang. Download from: https://public.fyers.in/tbtproto/1.0.0/protogencode.zip
Copy the required file directly in your project and use it.
Proto versions & links
| Proto Version | Proto URL | Compiled files URL | Updated on |
|---|---|---|---|
1.0.0 | https://public.fyers.in/tbtproto/1.0.0/msg.proto | https://public.fyers.in/tbtproto/1.0.0/protogencode.zip | 20-02-2025 |
Response structures
| Type | Data Format | Field Explanation |
|---|---|---|
SocketMessage |
| message SocketMessage {
MessageType type = 1;
map<string, MarketFeed> feeds = 2;
bool snapshot = 3;
string msg = 4;
bool error = 5;
} |
MarketFeed |
| message MarketFeed {
Quote quote = 1;
ExtendedQuote eq = 2;
DailyQuote dq = 3;
OHLCV ohlcv = 4;
Depth depth = 5;
google.protobuf.UInt64Value feed_time = 6;
google.protobuf.UInt64Value send_time = 7;
string token = 8;
uint64 sequence_no = 9;
bool snapshot = 10;
string ticker = 11;
SymDetail symdetail = 12;
} |
Depth |
| message Depth {
google.protobuf.UInt64Value tbq = 1;
google.protobuf.UInt64Value tsq = 2;
repeated MarketLevel asks = 3;
repeated MarketLevel bids = 4;
} |
MarketLevel |
| message MarketLevel {
google.protobuf.Int64Value price = 1;
google.protobuf.UInt32Value qty = 2;
google.protobuf.UInt32Value nord = 3;
google.protobuf.UInt32Value num = 4;
} |
Rate limits
Following ratelimits apply for TBT Websocket. The symbol limit is per user, across all connections: Standard allows 1 symbol and Prime allows 15 symbols, which is up to 3 connections with 5 symbols each. See Plans & rate limits.
| Description | Standard plan | Prime plan |
|---|---|---|
| Symbols per user, across all connections [Market Depth] | 1 | 15 |
| Active Connections Per App Per User | 1 | 3 |
| Symbols per connection [Market Depth] | 1 | 5 |
| Channels per connection | 50 (1-50) | 50 (1-50) |