Hi Members,
Whenever I try to connect wit the paytm money websocket User gets connected from websocket in first attempt after that attempt it works in every attempt.
here is my javascript code.
const socket = new WebSocket(
`wss://developer-ws.paytmmoney.com/broadcast/user/v1/data?x_jwt_token=${EnvironmentVariables.public_access_token}`
);
// Event triggered when user connection has successfully opened
socket.addEventListener("open", function () {
if (socket.readyState === socket.OPEN) {
socket.send(
JSON.stringify([
{
actionType: "ADD",
modeType: "FULL",
scripType: "INDEX",
exchangeType: "NSE",
scripId: "25",
},
])
);
}
});
// Event triggered when user connection has closed
socket.addEventListener("close", function (event) {
console.log("User has been disconnected");
});
// Event triggered when user connection gets an error
socket.addEventListener("error", function (event) {
console.log("[ERROR] - Error occured in bank nifty live socket", event);
});
// Event triggered when user connection gets a message from the server
socket.addEventListener("message", function (message) {
try {
let data: Buffer;
data = <Buffer>message.data;
let l = data.byteLength;
let dvu = new DataView(bufferToArrayBuffer(data));
let position = 0;
while (position != l) {
var type = dvu.getInt8(position);
position = position + 1;
switch (type) {
case 66:
position = processIndexQuotePacket(dvu, position);
writeFileSync(
`data/backup-live/livedata.json`,
JSON.stringify(liveData),
{
flag: "w",
}
);
default:
console.log("Default");
break;
}
}
} catch (error) {
console.log("[ERROR] - occurred in message addEventListener", error);
}
});
};