Data Services Streaming (WebSocket) - All Segments-Login

URL

WebSocket - Steps - Login

  • Login - POST REST API
  • JWT Authentication
  • Websocket Connection

Request

Key Required Value Discription
Segments All 2, 3, 4, 12, 13, 17, 35 Segments
Instrument TPIL_Instruments 1 Instruments
Otherinfo Optional 0 Timestamp-Seconds

Description

  • Action: Subscribe/Unsubscribe
  • Mode: TouchLine/Market Depth
  • Exchange, SegmentID, InstrumentID, Symbol, Series, Expiry, StrikePrice, oInfo: TimeStamp[XXXXX]

Example

  • Subscribe: NSE, 4, 1, SBIN,EQ, -1, -1, 1637620155
  • Subscribe: BSE, 3, 1, SBIN,EQ, -1, -1, 1637620156
  • Subscribe:Domestic Forex, 17,1, USDINRCOMP,-1,-1,T1637620155
  • Subscribe:International Forex, 12,1, EURUSD,-1,-1,1637620155
  • UnSubscribe: NSE, 4, 1, SBIN,EQ, -1, -1, 1637620155

Note: Otherinfo parameter will be Timestamp in seconds

                            
                              {
                                 "username":"XXXXX",
                                 "password": "XXXXX"
                            }

                          
                        

                        [
                         {
                            "messageHeader": {
                              "wsi":  "",
                              "uid":  "",
                              "mcd":  0,
                              "tim":  0,
                              "erc":  0,
                              "ers":  ""
                             },
                              "msg": {
                                "wsi":  "",
                                "uid":  "",
                                "mcd":  0,
                                "tim":  0,
                                "erc":  0,
                                "ers":  ""
                               },
                                "ipa":  "XXX.XXX.XX.XX:1234",
                                "pot":  1234,
                                "ctx":  "WebSocket",
                                "jwt":  "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJERkRFTU8wMTE2ICAgICAiLCJERkRFTU8wMTE2ICAgICAiOiIxMzAuMjExLjAuMTMiLCJleHAiOjE2NTg4ODk1NzgsImlhdCI6MTY1ODgyOTU3OH0.fiTjgPIdUihoEeZx-CdYQnNfnWryw6bDQWWSiZDZRzol2Pg6OJtcOw0QNUS2od3QUWsoYY43lCok0szJLy_i7Q",
                                "tok":  "4c267be8-8de5-4b4d-9fac-4b23cb3379bb"
                               }
                          ]
                      
                    
                      

    //1.WS connect - Hand Shake Connection
   //2.Heart Beat connection
   //3.Subscribe the Data  




var ws;
function setConnected(connected) {
     $("#connect").prop("disabled", connected);
       $("#disconnect").prop("disabled", !connected);
       if (connected) {
          $("#conversation").show();
        }
        else {
           $("#conversation").hide();
         }
         $("#greetings").html("");
}

function connect() {
    	var inputval = document.getElementById("myInput").value;
    	var utoken = document.getElementById("Token").value;
    	var userName = document.getElementById("Username").value;

     //UAT
    	ws = new WebSocket('ws://uat.tickermarket.com/TPILWebSocket/user?username='+userName+'&jwt='+Jwttoken+"&token="+utoken);

    	ws.onmessage = function(data){
     	showGreeting(data.data);
    	}
    	 setConnected(true);
}

function exchsend(){

    	if (ws != null) {
           ws.close();
      }

    	var exdata = JSON.stringify({'exchname': $("#exchanges").val()})
    	 alert(exdata);
        ws.send(exdata);
}

function disconnect() {
      if (ws != null) {
          ws.close();
      }
     setConnected(false);
     console.log("Disconnected");
     document.getElementById("myInput").value="";
     document.getElementById("Token").value="";
}


//  Submit function - send subscription data
$(function () {
      $("form").on('submit', function (e) {
         e.preventDefault();
  });
  $( "#connect" ).click(function() { connect(); });
  $( "#disconnect" ).click(function() { disconnect(); });
  $( "#send" ).click(function() { sendName(); });

  const btn = document.querySelector("#exchsend");

  const sb = document.querySelector('#exchanges');

  const unsub = document.querySelector('#Unsub');

  btn.onclick = (event) => {

           event.preventDefault();
  }
//Heart Beat - Every 30 Seconds need to send the request continously

var subscribe_HB =
      {
           		"rqh": {
              	"mcd": "1010",
              	"tst" :"1654325456"
         },

      "rqd":{


          	  "key": {

         		"sid": "-1"
         		  iid: "-1",
         		  sym: "-1",
         		  ser: "-1",
         		  exd: "-1",
         		  stp: "-1",
       	 },
           	 "act":"beat",
           	 "oif":"1654325456"
        }

      };
         var exdata =  JSON.stringify(subscribe_HB);
         ws.send(exdata);



//subscribe FX Data- Request Header, Body and Data


     if($("#exchanges").val()=="INTLFX"){
             var symbol = $("#symbols").val();

           alert( $("#symbols").val());
           var subscribe_intlfx =
          	{
         	"rqh": {
             	"mcd": "1001",
             	"tst" :"1654325456"
              },

      "rqd":{


        "key": {

             	"sid": "12",
             	  iid: "2",
             	  sym: "EURUSD",
             	  ser: "-1",
             	  exd: "-1",
             	  stp: "-1",
         },
         "act":"subscribe",
         "oif":"1654325456"
        }

      };
         var exdata =  JSON.stringify(subscribe_intlfx);
         ws.send(exdata);

     }

//subscribe NSE Data- Request Header, Body and Data

else if($("#exchanges").val()=="NSE"){
          var symbol = $("#symbols").val();
          alert( $("#symbols").val());


         var subscribe_nse =
         {
             "rqh": {
                   "mcd": "1001",
                   "tst" :"1654325456"
                },

         "rqd":{


           "key": {

                   "sid": "4",
                     iid: "1",
                     sym: "SBIN",
                     ser: "-1",
                     exd: "-1",
                     stp: "-1",
              },
                 "act":"subscribe",
                 "oif":"1654325456"
             }

         };


          var exdata =  JSON.stringify(subscribe_nse);
          alert($("#exchanges").val());
          ws.send(exdata);
     }

//subscribe NSE Data- Request Header, Body and Data
else if($("#exchanges").val()=="BSE"){
          var symbol = $("#symbols").val();
     	var subscribe_bse =
         {
                "rqh": {
                   "mcd": "1001",
                   "tst" :"1654325456"
              },

         "rqd":{


           "key": {

                    "sid": "3",
                      iid: "1",
                      sym: "SBIN",
                      ser: "-1",
                      exd: "-1",
                      stp: "-1",
              },
              "act":"subscribe",
              "oif":"1654325456"
             }

         };


       var bseexdata =  JSON.stringify(subscribe_bse);
       alert($(subscribe_bse));
       ws.send(bseexdata);

    }else if($("#exchanges").val()=="MCX"){
            var symbol = $("#symbols").val();
              var exdata =  JSON.stringify(subscribe_mcx);



            ws.send(exdata);
          }
   };


   //unsubscribe - Fx

   unsub.onclick = (event) =>{
          var symbol = $("#symbols").val();
          alert( $("#symbols").val());

       if($("#exchanges").val()=="INTLFX"){

          var intlfxdata =     {
          	"rqh": {
          		"mcd": "1001",
          		"tst" :"1654325456"
         },

      "rqd":{


        "key": {

          		"sid": "12",
          		  iid: "2",
        			  sym: symbol,
          		  ser: "-1",
          		  exd: "-1",
          		  stp: "-1",
         },
         "act":"unsubscribe",
         "oif":"1654325456"
        }

      };


              var exdata =  JSON.stringify(intlfxdata);
              ws.send(exdata);


//unsubscribe - NSE

       }else if($("#exchanges").val()=="NSE"){
          var symbol = $("#symbols").val();
          var subscribe_nse =
          {
          "rqh": {
                    "mcd": "1001",
                    "tst" :"1654325456"
             },

          "rqd":{


            "key": {

                    "sid": "4",
                      iid: "1",
                      sym: symbol,
                      ser: "-1",
                      exd: "-1",
                      stp: "-1",
               },
               "act":"unsubscribe",
               "oif":"1654325456"
              }

          };


          var exdata =  JSON.stringify(subscribe_nse);
          ws.send(exdata);
       }

// Unsubscribe BSE

else if($("#exchanges").val()=="BSE"){
          var symbol = $("#symbols").val();
     var subscribe_bse =
         {
         "rqh": {
                   "mcd": "1001",
                   "tst" :"1654325456"
            },

         "rqd":{


                 "key": {

                   "sid": "3",
                     iid: "1",
                     sym: "SBIN",
                     ser: "-1",
                     exd: "-1",
                     stp: "-1",
            },
              "act":"subscribe",
              "oif":"1654325456"
               }

                     };

                  };

});