### PUT /TBTWebsocketUsageGuide Source: https://myapi.fyers.in/static/media/v3.0ce77080e168cb8039ed.yaml 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

Example Usage

Let’s say you organize your subscriptions as follows: Now, depending on what data you need, you can control the channels dynamically: This approach provides greater flexibility and control over market data streaming, allowing you to filter and manage real-time data efficiently. ```markdown ### Example Usage ```bash curl -X PUT "//petstore.swagger.io/v2/TBTWebsocketUsageGuide" ``` ``` -------------------------------- ### POST /DataApi Source: https://myapi.fyers.in/static/media/v3.0ce77080e168cb8039ed.yaml The historical API provides archived data (up to date) for the symbols. across various exchanges within the given range. A historical record is presented in the form of a candle and the data is available in different resolutions like - minute, 10 minutes, 60 minutes...240 minutes and daily.
To Handle partial Candle

To receive completed candle data, it is important to send a timestamp that comes before the current minute. If you send a timestamp for the current minute, you will receive partial data because the minute is not yet finished. Therefore, it is recommended to always use a "range_to" timestamp of the previous minute to ensure that you receive the completed candle data.

Example:

Current Time(seconds can be 1-59): 12:10:20 PM

Input for history will be:

So you will get 2 candles - 12:08 PM and 12:09 PM candles. This example is for 1-minute candles; for other resolutions, you have to subtract the resolution time from "range_to" to get completed candles only.


Limits for History
## Request Attribute **Attribute** | **Data Type** | **Description** ---|---|--- `symbol*` | string | Mandatory.
Eg: NSE:SBIN-EQ `resolution*` | string | The candle resolution. Possible values are: Day : “D” or “1D”
5 seconds : “5S”
10 seconds : “10S”
15 seconds : “15S”
30 seconds : “30S”
45 seconds : “45S”
1 minute : “1”
2 minute : “2"
3 minute : "3"
5 minute : "5"
10 minute : "10"
15 minute : "15"
20 minute : "20"
30 minute : "30"
60 minute : "60"
120 minute : "120"
240 minute : "240" `date_format*` | int | date_format is a boolean flag. 0 to enter the epoch value. Eg:670073472. 1 to enter the date format as yyyy-mm-dd. `range_from*` | string | Indicating the start date of records. Accepts epoch value if date_format flag is set to 0. Eg: range_from: 670073472
Accepts yyyy-mm-dd format if date_format flag is set to 1. Eg: 2021-01-01 `range_to*` | string | Indicating the end date of records. Accepts epoch value if date_format flag is set to 0. Eg: range_to: 1622028732
Accepts yyyy-mm-dd format if date_format flag is set to 1. Eg:2021-03-01 `cont_flag*` | int | set cont flag 1 for continues data and future options. `oi_flag` | int | set flag to "1" enable oi as a part of candle. ## Response Attribute **Attribute** | **Data Type** | **Description** ---|---|--- `s` | string | ok / error `Candels` | array | Candles data containing array of following data for particular time stamp:
1.Current epoch time
2. Open Value
3.Highest Value
4.Lowest Value
5.Close Value
6.Total traded quantity (volume) ```markdown ### Example Usage ```bash curl -X POST "//petstore.swagger.io/v2/DataApi" ``` ``` -------------------------------- ### PATCH /TBTWebsocketUsageGuide Source: https://myapi.fyers.in/static/media/v3.0ce77080e168cb8039ed.yaml We use Protocol Buffers (protobuf) as the response format for all market data. The .proto file, which defines the data structure, is available at: 📌 Proto URL: https://public.fyers.in/tbtproto/1.0.0/msg.proto 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. You can download the files from the below link: https://public.fyers.in/tbtproto/1.0.0/protogencode.zip
Copy the required file directly in your project and use it.

Proto Versions and 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
Type Data Format Field 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 its a snapshot and false if its 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 the packet in unix epoch
  • send_time: time of the packet at the time of sending from server
  • token: fytoken for the symbol
  • snapshot: true if its a snapshot else false for a 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 the 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;
}
      
```markdown ### Example Usage ```bash curl -X PATCH "//petstore.swagger.io/v2/TBTWebsocketUsageGuide" ``` ``` -------------------------------- ### GET /DataApi Source: https://myapi.fyers.in/static/media/v3.0ce77080e168cb8039ed.yaml The Quotes API retrieves the full market quotes for one or more symbols provided by the user. ## Request attributes **Attribute** | **Data Type** | **Description* ---|---|--- `symbols*` | string | Maximum symbol limit is 50. Eg: NSE:SBIN-EQ. ## Response attributes **Attribute** | **Data Type** | **Description** ---|---|--- `s` | string | ok / error `ch` | float | Change value `chp` | float | Percentage of change between the current value and the previous day's market close `lp` | float | Last traded price `spread` | float | Difference between lowest asking and highest bidding price `ask` | float | Asking price for the symbol `bid` | float | Bidding price for the symbol `open_price` | float | Price at market opening time `high_price` | float | Highest price for the day `low_price` | float | Lowest price for the day `prev_close_price` | float | Previous closing price `atp` | float | Average traded price `volume` | int | Volume traded `short_name` | string | Short name for the symbol Eg: “SBIN-EQ” `exchange` | string | Name of the exchange. Eg: “NSE” or “BSE” `description` | string | Description of the symbol `original_name` | string | Original name of the symbol name provided by the use `symbol` | string | Symbol name provided by the user `fyToken` | string | Unique token for each symbol `tt` | int | Today’s time `cmd` | dict | ---Deprecated--- ```markdown ### Example Usage ```bash curl -X GET "//petstore.swagger.io/v2/DataApi" ``` ``` -------------------------------- ### GET /OrderWebsocketUsageGuide Source: https://myapi.fyers.in/static/media/v3.0ce77080e168cb8039ed.yaml Once the connection is established, it is required to subscribe for required actions to get the data. To subscribe for different actions, create a message data, which would be the string format for json node. message = json.dumps( {"T": "SUB_ORD", "SLIST": action_data, "SUB_T": 1} ) **Json node Params:** T: Type: String
value: “SUB_ORD” (Fixed) action_data: Type: List/Array
Value: ['orders', 'trades', 'positions', 'edis', 'pricealerts', 'login'] Note: Based on the list passed in action_data web_socket data will be received SUB_T: Integer
Value: 1 (value 1 is for subscribing and -1 for unsubscribe) Convert the json to string and send this message to socket to subscribe for action_data mentioned **Sample Response:** {'code': 1605, 'message': 'Successfully subscribed', 's': 'ok'} **Response from socket on any action triggered** Once the subscribed successfully, for any action triggered, data will be received through socket, if any callback function is defined, would receive on function. Response would be string, In node we get as array buffer and in python we string, then it parsed to required format. In another programming language you might get in another format you just have to change in string. Type: string
Value: {"orders":{"client_id":"XP0001","exchange":10,"fy_token":"10100000001628","id":"23121800292158","id_fyers":"df013f50-6925-4e2d-ba0f-0becf1229298","instrument":0,"lot_size":1,"offline_flag":false,"oms_flag":"K:1","ord_source":"W","ord_status":20,"ord_type":2,"ordertag":"2:Untagged","org_ord_status":4,"pan":"LVJPS3998E","precision":2,"price_multiplier":1,"product_type":"CNC","qty":1,"qty_multiplier":1,"qty_remaining":1,"report_type":"New Ack","segment":10,"status_msg":"New Ack","symbol":"NSE:BECTORFOOD-EQ","symbol_desc":"MRS BECTORS FOOD SPE LTD","symbol_exch":"BECTORFOOD", "tick_size":0.05,"time_epoch_oms":1702887690,"time_exch":"NA","time_oms":"18-Dec-2023 13:51:30","tran_side":1,"update_time_epoch_oms":1702887690,"update_time_exch":"01-Jan-1970 05:30:00","validity":"DAY"},"s":"ok"} Note:
  1. Above response would be in the string format (In Python ) and arraybuffer (In Node). You have to check in which format you are getting data from websocket as it is dependent on the websocket library for the particular language.
  2. Once you get data, you have to change into the string.(if already in string format then no need to change). After that, you have to change this string to JSON. Here you find the following keys as a JSON Key (One of them ) : orders, trades, positions.
  3. Now Based on the Key the data is identified, if key is orders it means it is order update message, if key is trades then this message is for trades updates and same for positions updates.
  4. In an Fyers SDK the socket raw response is parsed to generate data with required keys and remove the unnecessary keys
    **Parsed Data:** {'s': 'ok', 'orders': {'clientId': 'XP03754', 'id': '23121800388066', 'qty': 1, 'remainingQuantity': 1, 'type': 2, 'fyToken': '10100000002705', 'exchange': 10, 'segment': 10, 'symbol': 'NSE:PRAJIND-EQ', 'instrument': 0, 'offlineOrder': False, 'orderDateTime': '18-Dec-2023 16:33:24', 'orderValidity': 'DAY', 'productType': 'CNC', 'side': 1, 'status': 4, 'source': 'W', 'ex_sym': 'PRAJIND', 'description': 'PRAJ INDUSTRIES LTD', 'orderNumStatus': '23121800388066:4'}}

    All the keys information for orders updates are available there : Link
    All the keys information for Trades updates are available there : Link
    All the keys information for positions updates are available there : Link

  5. Also attaching our internal mapping for your reference, how we are changing the keys from raw data to final data.
            "position_mapper" :
             {
                    "symbol": "symbol",
                    "id": "id",
                    "buy_avg": "buyAvg",
                    "buy_qty": "buyQty",
                    "buy_val": "buyVal",
                    "sell_avg": "sellAvg",
                    "sell_qty": "sellQty",
                    "sell_val": "sellVal",
                    "net_avg": "netAvg",
                    "net_qty": "netQty",
                    "tran_side": "side",
                    "qty": "qty",
                    "product_type": "productType",
                    "pl_realized": "realized_profit",
                    "rbirefrate": "rbiRefRate",
                    "fy_token": "fyToken",
                    "exchange": "exchange",
                    "segment": "segment",
                    "day_buy_qty": "dayBuyQty",
                    "day_sell_qty": "daySellQty",
                    "cf_buy_qty": "cfBuyQty",
                    "cf_sell_qty": "cfSellQty",
                    "qty_multiplier": "qtyMulti_com",
                    "pl_total": "pl",
                    "cross_curr_flag": "crossCurrency",
                    "pl_unrealized": "unrealized_profit"
            },
              "order_mapper" : 
            {
                    "client_id":"clientId",
                    "id":"id",
                    "id_parent":"parentId",
                    "id_exchange":"exchOrdId",
                    "qty":"qty",
                    "qty_remaining":"remainingQuantity",
                    "qty_filled":"filledQty",
                    "price_limit":"limitPrice",
                    "price_stop":"stopPrice",
                    "tradedPrice":"price_traded",
                    "ord_type":"type",
                    "fy_token":"fyToken",
                    "exchange":"exchange",
                    "segment":"segment",
                    "symbol":"symbol",
                    "instrument":"instrument",
                    "oms_msg":"message",
                    "offline_flag":"offlineOrder",
                    "time_oms":"orderDateTime",
                    "validity":"orderValidity",
                    "product_type":"productType",
                    "tran_side":"side",
                    "org_ord_status":"status",
                    "ord_source":"source",
                    "symbol_exch":"ex_sym",
                    "symbol_desc":"description"
              },
                "trade_mapper" : 
              {
                    "id_fill": "tradeNumber",
                    "id": "orderNumber",
                    "qty_traded": "tradedQty",
                    "price_traded": "tradePrice",
                    "traded_val": "tradeValue",
                    "product_type": "productType",
                    "client_id": "clientId",
                    "id_exchange": "exchangeOrderNo",
                    "ord_type": "orderType",
                    "tran_side": "side",
                    "symbol": "symbol",
                    "fill_time": "orderDateTime",
                    "fy_token": "fyToken",
                    "exchange": "exchange",
                    "segment": "segment"
              }
              
```markdown ### Example Usage ```bash curl -X GET "//petstore.swagger.io/v2/OrderWebsocketUsageGuide" ``` ``` -------------------------------- ### POST /ThirdParty Source: https://myapi.fyers.in/static/media/v3.0ce77080e168cb8039ed.yaml This is a simple OAuth 2 Authentication Flows.