Skip to Content

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 (type 2) with the channel in resumeChannels to start it.
  • Use pauseChannels and resumeChannels in the same request to switch between groups. Both lists hold channel numbers as strings; the sample sends an empty pauseChannels list.
  • Subscribe uses subs 1 and unsubscribe uses subs -1, both with type 1 and mode depth.
  • Responses are protobuf. snapshot is true for the first full packet and false for diff packets. When error is true, feeds is empty.
  • Each depth level has price, qty, nord and num. For 50 levels, num runs from 0 to 49.

Request Message Types

TypePurposeEncoding FormatData Format
PingPing message to keep connection aliveString
"ping"
SubscribeSubscribe to the symbols for which data is requiredJson string
{
  "type": 1,
  "data": {
    "subs": 1,
    "symbols": [
      "NSE:IOC25FEBFUT",
      "NSE:NIFTY25FEBFUT",
      "NSE:BANKNIFTY25FEBFUT",
      "NSE:FINNIFTY25FEBFUT",
      "NSE:TCS25FEBFUT"
    ],
    "mode": "depth",
    "channel": "1"
  }
}
UnsubscribeUnsubscribe to the symbols for which data is NOT requiredJson string
{
  "type": 1,
  "data": {
    "subs": -1,
    "symbols": [
      "NSE:IOC25FEBFUT",
      "NSE:NIFTY25FEBFUT",
      "NSE:BANKNIFTY25FEBFUT",
      "NSE:FINNIFTY25FEBFUT",
      "NSE:TCS25FEBFUT"
    ],
    "mode": "depth",
    "channel": "1"
  }
}
Switch ChannelSwitch between active and paused channelsJson 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

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

Response structures

TypeData FormatField Explanation
SocketMessage
  • type: value will always be MessageType.depth
  • feeds: string (key) will be the symbol ticker and value will be the MarketFeed datastructure. This value will have the actual 50 depth values.
  • snapshot: true if it's a snapshot and false if it's a diff packet.
  • msg: will mostly contain error msgs when error = true.
  • error: true if it is an error, else false. In case of true, feeds will be nil/empty.
message SocketMessage {
  MessageType type = 1;
  map<string, MarketFeed> feeds = 2;
  bool snapshot = 3;
  string msg = 4;
  bool error = 5;
}
MarketFeed
  • depth: Depth datastructure. This field will have the actual market depth value.
  • feed_time: time of packet in unix epoch.
  • send_time: time of packet at the time of sending from server.
  • token: fytoken for symbol.
  • snapshot: true if snapshot, false if diff packet.
  • ticker: symbol ticker.
  • Note: other fields can be ignored
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
  • tbq: total bid qty
  • tsq: total sell qty
  • asks: array of asks of type MarketLevel datastructure
  • bids: array of bids of type MarketLevel datastructure
message Depth {
  google.protobuf.UInt64Value tbq = 1;
  google.protobuf.UInt64Value tsq = 2;
  repeated MarketLevel asks = 3;
  repeated MarketLevel bids = 4;
}
MarketLevel
  • price: price
  • qty: qty in the market depth for the price
  • nord: number of orders in market depth for the price
  • num: depth number, for 50 depth will be between 0 and 49 [0 based array indexing]
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.

DescriptionStandard planPrime plan
Symbols per user, across all connections [Market Depth]115
Active Connections Per App Per User13
Symbols per connection [Market Depth]15
Channels per connection50 (1-50)50 (1-50)
Last updated on