-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataManipulator.ts
33 lines (29 loc) · 1.01 KB
/
DataManipulator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { ServerRespond } from './DataStreamer';
export interface Row {
price_abc : number,
price_def : number,
ratio : number,
upper_bound: number,
lower_bound: number,
trigger_alert : number | undefined,
timestamp: Date,
}
export class DataManipulator {
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 upper_bound = 1.027 // provided with decent ammount of triger alerts
const lower_bound = 0.956
return{
price_abc : priceABC,
price_def : priceDEF,
ratio : ratio,
upper_bound: upper_bound,
lower_bound: lower_bound,
trigger_alert : (ratio > upper_bound || ratio < lower_bound) ? ratio : undefined,
timestamp: serverResponds[0].timestamp > serverResponds[1].timestamp ?
serverResponds[0].timestamp : serverResponds[1].timestamp,
}
}
}