-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalances.js
73 lines (55 loc) · 2.41 KB
/
balances.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
"use strict";
const ccxt = require ('../../ccxt.js')
const asTable = require ('as-table')
const log = require ('ololog').configure ({ locate: false })
require ('ansicolor').nice
let sleep = (ms) => new Promise (resolve => setTimeout (resolve, ms))
;(async () => {
// instantiate the exchange
let gdax = new ccxt.gdax ({ // ... or new ccxt.gdax ()
'apiKey': '92560ffae9b8a01d012726c698bcb2f1', // standard
'secret': '9aHjPmW+EtRRKN/OiZGjXh8OxyThnDL4mMDre4Ghvn8wjMniAr5jdEZJLN/knW6FHeQyiz3dPIL5ytnF0Y6Xwg==',
'password': '6kszf4aci8r', // GDAX requires a password!
})
// use the testnet for GDAX
gdax.urls['api'] = 'https://api-public.sandbox.gdax.com'
let hitbtc = new ccxt.hitbtc ({
'apiKey': '18339694544745d9357f9e7c0f7c41bb',
'secret': '8340a60fb4e9fc73a169c26c7a7926f5',
})
let quadrigacx = new ccxt.quadrigacx ({
'apiKey': 'jKvWkMqrOj',
'secret': 'f65a2e3bf3c73171ee14e389314b2f78',
'uid': '395037', // QuadrigaCX requires uid!
})
try {
// fetch account balance from the exchange
let gdaxBalance = await gdax.fetchBalance ()
// output the result
log (gdax.name.green, 'balance', gdaxBalance)
// fetch another
let hitbtcBalance = await hitbtc.fetchBalance ()
// output it
log (hitbtc.name.green, 'balance', hitbtcBalance)
// and the last one
let quadrigacxBalance = await quadrigacx.fetchBalance ()
// output it
log (quadrigacx.name.green, 'balance', quadrigacxBalance)
} catch (e) {
if (e instanceof ccxt.DDoSProtection || e.message.includes ('ECONNRESET')) {
log.bright.yellow ('[DDoS Protection] ' + e.message)
} else if (e instanceof ccxt.RequestTimeout) {
log.bright.yellow ('[Request Timeout] ' + e.message)
} else if (e instanceof ccxt.AuthenticationError) {
log.bright.yellow ('[Authentication Error] ' + e.message)
} else if (e instanceof ccxt.ExchangeNotAvailable) {
log.bright.yellow ('[Exchange Not Available Error] ' + e.message)
} else if (e instanceof ccxt.ExchangeError) {
log.bright.yellow ('[Exchange Error] ' + e.message)
} else if (e instanceof ccxt.NetworkError) {
log.bright.yellow ('[Network Error] ' + e.message)
} else {
throw e;
}
}
}) ()