update websocket

This commit is contained in:
MuslemRahimi 2024-12-02 21:41:28 +01:00
parent 2a34847fa1
commit be59e44bf5
3 changed files with 5 additions and 5 deletions

View File

@ -349,7 +349,7 @@
try { try {
const newList = JSON?.parse(data); const newList = JSON?.parse(data);
if (newList?.length > 0) { if (newList?.length > 0) {
//console.log("Received message:", newList); console.log("Received message:", newList);
if (originalData.some((item) => "changesPercentage" in item)) { if (originalData.some((item) => "changesPercentage" in item)) {
originalData = calculateChange(originalData, newList); originalData = calculateChange(originalData, newList);
stockList = updateStockList(stockList, originalData); stockList = updateStockList(stockList, originalData);

View File

@ -132,9 +132,9 @@ export const calculateChange = (oldList?: any[], newList?: any[]) => {
const item = oldList[i]; const item = oldList[i];
const newItem = newListMap.get(item.symbol); const newItem = newListMap.get(item.symbol);
if (newItem?.ap) { if (newItem?.avgPrice) {
const { price, changesPercentage } = item; const { price, changesPercentage } = item;
const newPrice = newItem.ap; const newPrice = newItem.avgPrice;
if (price != null && changesPercentage != null) { if (price != null && changesPercentage != null) {
const baseLine = price / (1 + Number(changesPercentage) / 100); const baseLine = price / (1 + Number(changesPercentage) / 100);

View File

@ -167,7 +167,7 @@
//console.log('Received message:', data); //console.log('Received message:', data);
try { try {
const parsedData = JSON.parse(data); const parsedData = JSON.parse(data);
const { type, lp, time, bp, ap } = parsedData || {}; const { type, lp, time, bp, ap, avgPrice } = parsedData || {};
if (type === "T") { if (type === "T") {
$realtimePrice = typeof lp !== "undefined" ? lp : null; $realtimePrice = typeof lp !== "undefined" ? lp : null;
@ -179,7 +179,7 @@
} else if (type === "Q") { } else if (type === "Q") {
$wsBidPrice = typeof bp !== "undefined" ? bp : null; $wsBidPrice = typeof bp !== "undefined" ? bp : null;
$wsAskPrice = typeof ap !== "undefined" ? ap : null; $wsAskPrice = typeof ap !== "undefined" ? ap : null;
$realtimePrice = $wsAskPrice?.toFixed(2); $realtimePrice = typeof avgPrice !== "undefined" ? avgPrice : null;
} }
// Update price increase state // Update price increase state