From be59e44bf522519b64cc042e3026efc6f13fb6a5 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 2 Dec 2024 21:41:28 +0100 Subject: [PATCH] update websocket --- src/lib/components/Table/Table.svelte | 2 +- src/lib/utils.ts | 4 ++-- src/routes/stocks/[tickerID]/+layout.svelte | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/components/Table/Table.svelte b/src/lib/components/Table/Table.svelte index e366c649..d6a384e9 100644 --- a/src/lib/components/Table/Table.svelte +++ b/src/lib/components/Table/Table.svelte @@ -349,7 +349,7 @@ try { const newList = JSON?.parse(data); if (newList?.length > 0) { - //console.log("Received message:", newList); + console.log("Received message:", newList); if (originalData.some((item) => "changesPercentage" in item)) { originalData = calculateChange(originalData, newList); stockList = updateStockList(stockList, originalData); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 4703c179..d5a54955 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -132,9 +132,9 @@ export const calculateChange = (oldList?: any[], newList?: any[]) => { const item = oldList[i]; const newItem = newListMap.get(item.symbol); - if (newItem?.ap) { + if (newItem?.avgPrice) { const { price, changesPercentage } = item; - const newPrice = newItem.ap; + const newPrice = newItem.avgPrice; if (price != null && changesPercentage != null) { const baseLine = price / (1 + Number(changesPercentage) / 100); diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index aac81d1e..0f74b9fe 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -167,7 +167,7 @@ //console.log('Received message:', data); try { const parsedData = JSON.parse(data); - const { type, lp, time, bp, ap } = parsedData || {}; + const { type, lp, time, bp, ap, avgPrice } = parsedData || {}; if (type === "T") { $realtimePrice = typeof lp !== "undefined" ? lp : null; @@ -179,7 +179,7 @@ } else if (type === "Q") { $wsBidPrice = typeof bp !== "undefined" ? bp : null; $wsAskPrice = typeof ap !== "undefined" ? ap : null; - $realtimePrice = $wsAskPrice?.toFixed(2); + $realtimePrice = typeof avgPrice !== "undefined" ? avgPrice : null; } // Update price increase state