bugfixing

This commit is contained in:
MuslemRahimi 2024-12-10 17:08:15 +01:00
parent 63403896ca
commit 8fa8cff73a

View File

@ -258,6 +258,7 @@ fastify.register(async function (fastify) {
__dirname,
`../app/json/websocket/companies/${symbol?.toUpperCase()}.json`
);
try {
if (fs?.existsSync(filePath)) {
const fileData = fs?.readFileSync(filePath, "utf8");
@ -295,7 +296,9 @@ try {
? jsonData.bp
: avgPrice;
const currentDataSignature = `${jsonData?.bp}`;
// Check if finalPrice is equal to avgPrice before sending data
if (finalPrice - avgPrice === 0) {
const currentDataSignature = `${finalPrice}`;
const lastSentSignature = lastSentData[symbol];
if (currentDataSignature !== lastSentSignature) {
@ -312,6 +315,7 @@ try {
lastSentData[symbol] = currentDataSignature;
}
}
}
} else {
console.error("File not found for ticker:", symbol);
}
@ -328,6 +332,7 @@ try {
};
// Start receiving messages from the client
connection.socket.on("message", (message) => {
try {