forked from vagabond-systems/jpmc-task-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataManipulator.ts
31 lines (28 loc) · 1001 Bytes
/
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
import { ServerRespond } from './DataStreamer';
export interface Row {
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(serverRespond: 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 upper_bound = 1 + 0.05;
const lower_bound = 1 - 0.05;
return {
price_abc: priceABC,
price_def: priceDEF
ratio,
timestamp: serverRespond[0].timestamp > serverRespond[1].timestamp ?
serverRespoond[0].timestamp : serverRespond[1].timestamp,
upper_bound: upper_bound,
lower_bound: lower_bound,
trigger_alert: (ratio > upper_bound || ratio < lower_bound)? ratio: undefined,
};
}