diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts index 7f622955cc..300acd8baa 100644 --- a/src/DataManipulator.ts +++ b/src/DataManipulator.ts @@ -1,19 +1,33 @@ 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, + upper_bound:number, + lower_bound:number; + trigger_alert:number|undefined, } export class DataManipulator { - static generateRow(serverResponds: ServerRespond[]) { - return serverResponds.map((el: any) => { + static generateRow(serverResponds: ServerRespond[]): Row { + const priceABC = (serverResponds[0]. top_ask.price + serverResponds[0].top_bid.price)/2; + const priceDEF = (serverResponds[1]. top_ask.price + serverResponds[1].top_bid.price)/2; + const ratio = priceABC / priceDEF + const upperBound= 1 + 0.05; + const lowerBound = 1 - 0.05; return { - stock: el.stock, - top_ask_price: el.top_ask && el.top_ask.price || 0, - timestamp: el.timestamp, +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 + , }; }) } diff --git a/src/Graph.tsx b/src/Graph.tsx index 277797d933..bf750f4543 100644 --- a/src/Graph.tsx +++ b/src/Graph.tsx @@ -23,10 +23,13 @@ class Graph extends Component { const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; const schema = { - stock: 'string', - top_ask_price: 'float', - top_bid_price: 'float', - timestamp: 'date', + price_abc:'float', + price_def:'float', + ratio:'float', + timestamp:'date', + upper_bound:'float', + lower_bound:'float'; + trigger_alert:'float', }; if (window.perspective && window.perspective.worker()) { @@ -40,18 +43,21 @@ class Graph extends Component { elem.setAttribute('row-pivots', '["timestamp"]'); elem.setAttribute('columns', '["top_ask_price"]'); elem.setAttribute('aggregates', JSON.stringify({ - stock: 'distinctcount', - top_ask_price: 'avg', - top_bid_price: 'avg', - timestamp: 'distinct count', + price_abc:'avg', + price_def:'avg', + ratio:'avg', + timestamp:'distinct count', + upper_bound:'avg', + lower_bound:'avg'; + trigger_alert:'avg', })); } } componentDidUpdate() { if (this.table) { - this.table.update( - DataManipulator.generateRow(this.props.data), + this.table.update([ + DataManipulator.generateRow(this.props.data),] as unknown as TableData ); } }