From 62c4d1fdfd0da2db7787aa3a5bc3f3cec3b60a5e Mon Sep 17 00:00:00 2001 From: Milan Mehta <110523894+Milan1609@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:51:39 +0530 Subject: [PATCH] Update DataManipulator.ts --- src/DataManipulator.ts | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts index 7f622955cc..82e917fe1d 100644 --- a/src/DataManipulator.ts +++ b/src/DataManipulator.ts @@ -1,20 +1,30 @@ import { ServerRespond } from './DataStreamer'; export interface Row { - stock: string, - top_ask_price: number, + price_abc: number, + price_def: number, + ratio: number timestamp: Date, + upper_bound: number, + lower_bound:number, + trigger_alert: number, } export class DataManipulator { - static generateRow(serverResponds: ServerRespond[]) { - return serverResponds.map((el: any) => { - return { - stock: el.stock, - top_ask_price: el.top_ask && el.top_ask.price || 0, - timestamp: el.timestamp, - }; - }) - } + static generateRow(serverResponds: ServerRespond[]): Row { + const priceABC =(serverRespound[0].top_ask.price + serverRespound[0].top_bird.price)/2; + const priceDEF =(serverRespound[1].top_ask.price + serverRespound[1].top_bird.price)/2; + const upperBound = 1 + 0.05; + const lowerBound = 1 - 0.05; + return { + price_abc: priceABC, + Price_def: priceDEF, + ratio, + timestamp: serverRespound[0].timestamp > serverRespound[1].timestamp ? + serverRespound[0].timestamp : serverRespound[1].timestamp, + upper_bound:upperBound, + lower_bound:lowerBound, + trigger_alert : (ratio > upperBound || ratio < LowerBound) ? ratio : undefined , + }; }