-
Notifications
You must be signed in to change notification settings - Fork 0
/
DepthManager.ts
42 lines (41 loc) · 1.07 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
export class DepthManager {
private market : string;
private bids : {
[key : string] :string;
};
private asks : {
[key : string] :string;
};
constructor(market : string,){
this.market = market;
this.bids = {} ;
this.asks = {} ;
setInterval(() => {
this.pollMarket();
},3000)
}
async pollMarket() {
const res = await fetch(`https://public.coindcx.com/market_data/orderbook?pair=${this.market}`)
const depth = await res.json();
this.bids = depth.bids;
this.asks = depth.asks;
}
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
}
}
}