forked from Haehnchen/crypto-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtickers.js
35 lines (27 loc) · 824 Bytes
/
tickers.js
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
'use strict';
const moment = require('moment')
module.exports = class Tickers {
constructor() {
this.tickers = {};
}
set(ticker) {
this.tickers[ticker.exchange + '.' + ticker.symbol] = ticker
}
get(exchange, symbol) {
return this.tickers[exchange + '.' + symbol] || null
}
getIfUpToDate(exchange, symbol, lastUpdatedSinceMs) {
if (!lastUpdatedSinceMs) {
throw 'Invalid ms argument given'
}
if (!(exchange + '.' + symbol) in this.tickers) {
return undefined;
}
return this.tickers[exchange + '.' + symbol].createdAt > moment().subtract(lastUpdatedSinceMs, 'ms').toDate()
? this.tickers[exchange + '.' + symbol]
: undefined
}
all() {
return this.tickers
}
}