-
Notifications
You must be signed in to change notification settings - Fork 3
/
advanced-error-handling.js
39 lines (35 loc) · 1.44 KB
/
advanced-error-handling.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
"use strict";
const ccxt = require ('../../ccxt.js');
// instantiate the exchange
let exchange = new ccxt.coinbasepro ({
'apiKey': 'XXXXXXXXXXXXXX',
'secret': 'YYYYYYYYYYYYYY',
});
async function checkOrders(){
try {
// fetch orders
let orders = await exchange.fetchOrders ('BTC/USDT');
// output the result
console.log (exchange.id, 'fetched orders', orders);
} catch (e) {
if (e instanceof ccxt.DDoSProtection || e.message.includes ('ECONNRESET')) {
console.log ('[DDoS Protection] ' + e.message);
} else if (e instanceof ccxt.RequestTimeout) {
console.log ('[Request Timeout] ' + e.message);
} else if (e instanceof ccxt.AuthenticationError) {
console.log ('[Authentication Error] ' + e.message);
} else if (e instanceof ccxt.ExchangeNotAvailable) {
console.log ('[Exchange Not Available Error] ' + e.message);
} else if (e instanceof ccxt.ExchangeError) {
console.log ('[Exchange Error] ' + e.message);
} else if (e instanceof ccxt.NetworkError) {
console.log ('[Network Error] ' + e.message);
} else {
// you can throw it if you want to stop the execution
// console.log ('[Exception ' + e.constructor.name + '] ' + e.message);
throw e;
}
}
}
// for demonstrational purposes, we use 1000 ms interval
setInterval(checkOrders, 1000);