update websocket to include bid/ask price
This commit is contained in:
parent
bdf7e9ec9a
commit
b92655cb3c
@ -172,18 +172,26 @@ fastify.register(async function (fastify) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const jsonData = JSON.parse(stringData);
|
const jsonData = JSON.parse(stringData);
|
||||||
const bpData = jsonData.bp;
|
// Check if bpData is a number, not equal to zero, and jsonData properties are not null/undefined
|
||||||
|
if (
|
||||||
// Check if bpData is a number and not equal to zero
|
jsonData?.bp != null &&
|
||||||
if (typeof bpData === "number" && bpData !== 0) {
|
jsonData?.ap != null &&
|
||||||
if (connection.socket.readyState === WebSocket.OPEN && !isSend) {
|
jsonData?.lp != null &&
|
||||||
connection.socket.send(JSON.stringify({ bp: bpData }));
|
connection.socket.readyState === WebSocket.OPEN &&
|
||||||
|
!isSend
|
||||||
|
) {
|
||||||
|
connection.socket.send(
|
||||||
|
JSON.stringify({
|
||||||
|
bp: jsonData.bp?.toFixed(2),
|
||||||
|
ap: jsonData.ap?.toFixed(2),
|
||||||
|
lp: jsonData.lp?.toFixed(2),
|
||||||
|
})
|
||||||
|
);
|
||||||
isSend = true;
|
isSend = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isSend = false;
|
isSend = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error parsing JSON:", error);
|
console.error("Error parsing JSON:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user