-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepthManager.ts
50 lines (45 loc) · 1.15 KB
/
DepthManager.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
export class DepthManager {
private market: string;
private bids: {
[key: string]: string;
};
private asks: {
[key: string]: string;
};
constructor(market: string) {
this.bids = {};
this.asks = {};
this.market = market;
setInterval(() => {
this.pollMarket();
}, 2500);
}
async pollMarket() {
const res = await fetch(
`https://public.coindcx.com/market_data/orderbook?pair=${this.market}`
);
const depth = await res.json();
//@ts-ignore
this.bids = depth.bids;
//@ts-ignore
this.asks = depth.asks;
}
async getRelevantDepth() {
let highestBid = -100;
let lowestAsk = 10000000;
Object.keys(this.bids).map((x) => {
if (parseFloat(x) > highestBid) {
highestBid = parseFloat(x);
}
});
Object.keys(this.asks).map((x) => {
if (parseFloat(x) < lowestAsk) {
lowestAsk = parseFloat(x);
}
});
return {
highestBid,
lowestAsk,
};
}
}