From daf4a2fd08acdc176eae5666c86c6c40563f1fec Mon Sep 17 00:00:00 2001 From: Deepak Date: Sun, 11 Aug 2024 22:44:44 +0530 Subject: [PATCH] task-3 --- src/DataManipulator.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts index 7f622955cc..93bdd48df6 100644 --- a/src/DataManipulator.ts +++ b/src/DataManipulator.ts @@ -1,20 +1,32 @@ import { ServerRespond } from './DataStreamer'; export interface Row { - stock: string, - top_ask_price: number, - timestamp: Date, + price_abc:number, + price_def: number, + ratio : number, + timestamp:Date, + upperbound : number, + lower_bound : number, + trigger_alert : number | undefined, } 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, - }; - }) - } + const priceABC = (serverResponds[0].top_ask.price + serverResponds[0].top_bid.price)/2; + const priceDEF = (serverResponds[0].top_ask.price + serverResponds[0].top_bid.price)/2; + const ratio = priceABC / priceDEF ; + const upperBound = 1+0.05; + const lowerBound = 1- 0.05; + return { + price_abc:priceABC, + price_def:priceDEF, + ratio, + timestamp:serverResponds[0].timestamp > serverResponds[1].timestamp? + serverResponds[0].timestamp:serverResponds[1].timestamp, + upper_bound : upperBound, + lower_bound :lowerBound, + trigger_alert : (ratio>upperBound || ratio < lowerBound ) ? ratio : undefined, + } + }; }