-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (48 loc) · 1.42 KB
/
index.js
File metadata and controls
57 lines (48 loc) · 1.42 KB
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
51
52
53
54
55
56
57
'use strict';
const _ = require('lodash');
const CONST = require('./config/const.js');
module.exports = class Market {
constructor() {
this._sdks = {};
}
get platforms() {
return CONST.PLATFORMS;
}
async coins() {
const pfs = _.keys(this.platforms);
const coinList = {};
for (let i = 0; i < pfs.length; i++) {
let platform_ = pfs[i];
try {
const Sdk = require(`./lib/${platform_}.js`);
this._sdks[platform_] = new Sdk('');
let list = await (this._sdks[platform_].coins());
coinList[platform_] = list;
} catch (e) {
console.error(`market coins unexpected: ${e}`);
}
}
return coinList;
}
async ticker(symbol, pf) {
const pfs = _.keys(this.platforms);
let info = `${symbol}${CONST.TICKER_INFO.PRICE}`;
for (let i = 0; i < pfs.length; i++) {
let platform_ = pfs[i];
const coinId = symbol.toLowerCase() + this.platforms[platform_]['suffix'];
try {
if (!pf.includes(platform_)) continue;
let price = await this._sdks[platform_].ticker(coinId);
info += `\n${this.platforms[platform_]['name']}:${price}`;
} catch (e) {
if ('yunbi' === platform_) {
info += `${CONST.TICKER_INFO.YUNBI_UNEXCEPTION}`;
} else {
info += `${CONST.TICKER_INFO.TICKER_ERR} 平台:${platform_}`;
console.error(e);
}
}
}
return info;
}
};