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, __dirname,
`../app/json/websocket/companies/${symbol?.toUpperCase()}.json` `../app/json/websocket/companies/${symbol?.toUpperCase()}.json`
); );
try { try {
if (fs?.existsSync(filePath)) { if (fs?.existsSync(filePath)) {
const fileData = fs?.readFileSync(filePath, "utf8"); const fileData = fs?.readFileSync(filePath, "utf8");
@ -295,7 +296,9 @@ try {
? jsonData.bp ? jsonData.bp
: avgPrice; : 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]; const lastSentSignature = lastSentData[symbol];
if (currentDataSignature !== lastSentSignature) { if (currentDataSignature !== lastSentSignature) {
@ -312,6 +315,7 @@ try {
lastSentData[symbol] = currentDataSignature; lastSentData[symbol] = currentDataSignature;
} }
} }
}
} else { } else {
console.error("File not found for ticker:", symbol); console.error("File not found for ticker:", symbol);
} }
@ -328,6 +332,7 @@ try {
}; };
// Start receiving messages from the client // Start receiving messages from the client
connection.socket.on("message", (message) => { connection.socket.on("message", (message) => {
try { try {