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;
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="";
}
$(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();
}
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);
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);
}
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);
}
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);
}
};
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);
}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);
}
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"
}
};
};
});