bugfixing
This commit is contained in:
parent
63403896ca
commit
8fa8cff73a
@ -250,7 +250,7 @@ fastify.register(async function (fastify) {
|
|||||||
const lastSentData = {};
|
const lastSentData = {};
|
||||||
|
|
||||||
// Function to send data for all tickers as a list
|
// Function to send data for all tickers as a list
|
||||||
const sendData = async () => {
|
const sendData = async () => {
|
||||||
const dataToSend = [];
|
const dataToSend = [];
|
||||||
|
|
||||||
for (const symbol of tickers) {
|
for (const symbol of tickers) {
|
||||||
@ -258,7 +258,8 @@ 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");
|
||||||
|
|
||||||
@ -282,7 +283,7 @@ try {
|
|||||||
jsonData?.ap != null &&
|
jsonData?.ap != null &&
|
||||||
jsonData?.bp != null &&
|
jsonData?.bp != null &&
|
||||||
jsonData?.t != null &&
|
jsonData?.t != null &&
|
||||||
["Q","T"]?.includes(jsonData?.type) &&
|
["Q", "T"]?.includes(jsonData?.type) &&
|
||||||
connection.socket.readyState === WebSocket.OPEN
|
connection.socket.readyState === WebSocket.OPEN
|
||||||
) {
|
) {
|
||||||
const avgPrice = (
|
const avgPrice = (
|
||||||
@ -295,21 +296,24 @@ try {
|
|||||||
? jsonData.bp
|
? jsonData.bp
|
||||||
: avgPrice;
|
: avgPrice;
|
||||||
|
|
||||||
const currentDataSignature = `${jsonData?.bp}`;
|
// Check if finalPrice is equal to avgPrice before sending data
|
||||||
const lastSentSignature = lastSentData[symbol];
|
if (finalPrice - avgPrice === 0) {
|
||||||
|
const currentDataSignature = `${finalPrice}`;
|
||||||
|
const lastSentSignature = lastSentData[symbol];
|
||||||
|
|
||||||
if (currentDataSignature !== lastSentSignature) {
|
if (currentDataSignature !== lastSentSignature) {
|
||||||
dataToSend?.push({
|
dataToSend?.push({
|
||||||
symbol,
|
symbol,
|
||||||
ap: jsonData?.ap,
|
ap: jsonData?.ap,
|
||||||
bp: jsonData?.bp,
|
bp: jsonData?.bp,
|
||||||
lp: jsonData?.lp,
|
lp: jsonData?.lp,
|
||||||
avgPrice: finalPrice,
|
avgPrice: finalPrice,
|
||||||
type: jsonData?.type,
|
type: jsonData?.type,
|
||||||
time: formatTimestampNewYork(jsonData?.t),
|
time: formatTimestampNewYork(jsonData?.t),
|
||||||
});
|
});
|
||||||
|
|
||||||
lastSentData[symbol] = currentDataSignature;
|
lastSentData[symbol] = currentDataSignature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -323,10 +327,11 @@ try {
|
|||||||
// Send all collected data as a single message
|
// Send all collected data as a single message
|
||||||
if (dataToSend.length > 0 && connection.socket.readyState === WebSocket.OPEN) {
|
if (dataToSend.length > 0 && connection.socket.readyState === WebSocket.OPEN) {
|
||||||
connection.socket.send(JSON.stringify(dataToSend));
|
connection.socket.send(JSON.stringify(dataToSend));
|
||||||
//console.log(dataToSend);
|
// console.log(dataToSend);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Start receiving messages from the client
|
// Start receiving messages from the client
|
||||||
connection.socket.on("message", (message) => {
|
connection.socket.on("message", (message) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user