-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-all-tickers-at-once.js
88 lines (64 loc) · 3.01 KB
/
load-all-tickers-at-once.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"use strict";
const ccxt = require ('../../ccxt.js')
const asTable = require ('as-table')
const log = require ('ololog').configure ({ locate: false })
require ('ansicolor').nice
//-----------------------------------------------------------------------------
process.on ('uncaughtException', e => { log.bright.red.error (e); process.exit (1) })
process.on ('unhandledRejection', e => { log.bright.red.error (e); process.exit (1) })
//-----------------------------------------------------------------------------
let human_value = function (price) {
return typeof price === 'undefined' ? 'N/A' : price
}
//-----------------------------------------------------------------------------
let test = async function (exchange, symbol) {
try {
await exchange.loadMarkets ()
if (symbol in exchange.markets) {
let ticker = await exchange.fetchTicker (symbol)
log (exchange.id.green, symbol.green, 'ticker',
ticker['datetime'],
'high: ' + human_value (ticker['high']),
'low: ' + human_value (ticker['low']),
'bid: ' + human_value (ticker['bid']),
'ask: ' + human_value (ticker['ask']),
'volume: ' + human_value (ticker['quoteVolume']))
} else {
// do nothing or throw an error
log.bright.yellow (exchange.id + ' does not have ' + symbol)
}
} catch (e) {
if (e instanceof ccxt.DDoSProtection) {
log.bright.yellow (exchange.id, '[DDoS Protection]')
} else if (e instanceof ccxt.RequestTimeout) {
log.bright.yellow (exchange.id, '[Request Timeout]')
} else if (e instanceof ccxt.AuthenticationError) {
log.bright.yellow (exchange.id, '[Authentication Error]')
} else if (e instanceof ccxt.ExchangeNotAvailable) {
log.bright.yellow (exchange.id, '[Exchange Not Available]')
} else if (e instanceof ccxt.ExchangeError) {
log.bright.yellow (exchange.id, '[Exchange Error]')
} else if (e instanceof ccxt.NetworkError) {
log.bright.yellow (exchange.id, '[Network Error]')
} else {
throw e
}
}
}
//-----------------------------------------------------------------------------
const symbol = 'BTC/USD'
//-----------------------------------------------------------------------------
async function main () {
let exchanges = []
// instantiate all exchanges
await Promise.all (ccxt.exchanges.map (async id => {
let exchange = new (ccxt)[id] ()
exchanges.push (exchange)
await test (exchange, symbol)
}))
let succeeded = exchanges.filter (exchange => exchange.markets ? true : false).length.toString ().bright.green
let failed = exchanges.filter (exchange => exchange.markets ? false : true).length
let total = ccxt.exchanges.length.toString ().bright.white
console.log (succeeded, 'of', total, 'exchanges loaded', ('(' + failed + ' errors)').red)
}
main ()