-
Notifications
You must be signed in to change notification settings - Fork 0
/
DepthManager.ts
47 lines (41 loc) · 1.06 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
import axios from "axios";
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 depth = await axios.get(`https://public.coindcx.com/market_data/orderbook?pair=${this.market}`);
this.bids = depth.data.bids
this.asks = depth.data.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
}
}
}