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 , + }; }