From ba97f6fb00702b7ce19ac5c80613bdffbd2ecfc9 Mon Sep 17 00:00:00 2001 From: faizan-ab <154486451+faizan-ab@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:33:06 +0530 Subject: [PATCH 1/2] Update Graph.tsx --- src/Graph.tsx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Graph.tsx b/src/Graph.tsx index 277797d933..216884ff34 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()) { @@ -36,22 +39,25 @@ class Graph extends Component { // Load the `table` in the `` DOM reference. elem.load(this.table); elem.setAttribute('view', 'y_line'); - elem.setAttribute('column-pivots', '["stock"]'); elem.setAttribute('row-pivots', '["timestamp"]'); - elem.setAttribute('columns', '["top_ask_price"]'); + elem.setAttribute('columns', '["ratio","lower_bound"]'); elem.setAttribute('aggregates', JSON.stringify({ - stock: 'distinctcount', - top_ask_price: 'avg', - top_bid_price: 'avg', + 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( + this.table.update([ DataManipulator.generateRow(this.props.data), + ] as unknown as TableData ); } } From 86385940a9761a3be5108e7caa0481325d6834f2 Mon Sep 17 00:00:00 2001 From: faizan-ab <154486451+faizan-ab@users.noreply.github.com> Date: Sun, 8 Sep 2024 15:02:11 +0530 Subject: [PATCH 2/2] Update DataManipulator.ts --- src/DataManipulator.ts | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts index 7f622955cc..f7b7d938ed 100644 --- a/src/DataManipulator.ts +++ b/src/DataManipulator.ts @@ -1,19 +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, + upper_bound: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, + static generateRow(serverResponds: ServerRespond[]):Row { + const priceABC: (serverRespond[0].top_ask_price + serverRespond[0].top_bid_price)/2; + const priceDEF: (serverRespond[1].top_ask_price + serverRespond[1].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:serverResponse[0].timestamp > serverRespond[1].timestamp ? + serverRespond[0].timestamp : serverRespond[1].timestamp + upper_bound :upperBound, + lower_bound :lowerBound, + trigger_alert :(ratio>upperBound || ratio