@icgio/icg-exchanges-wrapper 1.12.172 → 1.12.174
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/functions/get-exchanges-balance.js +38 -24
- package/functions/get-exchanges-deposits.js +79 -0
- package/functions/get-exchanges-open-orders.js +92 -0
- package/functions/get-exchanges-rates-market-history-ohlcv.js +92 -41
- package/functions/get-exchanges-trades.js +120 -88
- package/functions/get-exchanges-withdrawals.js +79 -0
- package/index.js +6 -0
- package/middleware/account.js +2 -0
- package/package.json +1 -1
|
@@ -1,32 +1,46 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
let balances = {}
|
|
3
|
+
module.exports = function (exchanges, cb) {
|
|
4
|
+
if (!Array.isArray(exchanges)) {
|
|
5
|
+
console.error('exchanges should be an array');
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
} else {
|
|
10
|
-
for (let Exchange of Exchanges) {
|
|
11
|
-
if (Exchange.balance_ws) {
|
|
12
|
-
if (Exchange.ws_status().trading === 'n-opened') Exchange.ws_account()
|
|
13
|
-
Exchange.balance_ws(function (res) {
|
|
9
|
+
const promises = exchanges.map(exchange => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
if (exchange.balance_ws) {
|
|
12
|
+
if (exchange.ws_status().trading === 'n-opened') exchange.ws_account();
|
|
13
|
+
exchange.balance_ws(function (res) {
|
|
14
14
|
if (res.success) {
|
|
15
|
-
_.set(balances,
|
|
15
|
+
_.set(balances, exchange.settings.id, res.body);
|
|
16
|
+
resolve();
|
|
16
17
|
} else {
|
|
17
|
-
delete balances[
|
|
18
|
+
delete balances[exchange.name];
|
|
19
|
+
resolve();
|
|
18
20
|
}
|
|
19
|
-
})
|
|
20
|
-
} else if (
|
|
21
|
-
|
|
21
|
+
});
|
|
22
|
+
} else if (exchange.balance) {
|
|
23
|
+
exchange.balance(function (res) {
|
|
22
24
|
if (res.success) {
|
|
23
|
-
_.set(balances,
|
|
25
|
+
_.set(balances, exchange.settings.id, res.body);
|
|
26
|
+
resolve();
|
|
24
27
|
} else {
|
|
25
|
-
delete balances[
|
|
28
|
+
delete balances[exchange.name];
|
|
29
|
+
resolve();
|
|
26
30
|
}
|
|
27
|
-
})
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
resolve();
|
|
28
34
|
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Promise.all(promises)
|
|
39
|
+
.then(() => {
|
|
40
|
+
cb(balances);
|
|
41
|
+
})
|
|
42
|
+
.catch(error => {
|
|
43
|
+
console.error('Error fetching balances:', error);
|
|
44
|
+
cb({});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
const TIMEFRAME_IN_THE_PAST = 90 * 24 * 60 * 60 * 1000
|
|
3
|
+
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
+
|
|
5
|
+
let exchange_pair_deposits = {}
|
|
6
|
+
let deposits_status = {}
|
|
7
|
+
|
|
8
|
+
module.exports = function (exchanges, client_currency, cb) {
|
|
9
|
+
if (!Array.isArray(exchanges)) {
|
|
10
|
+
console.error('exchanges should be an array')
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const promises = exchanges.map((exchange) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const exchange_name = exchange.Name
|
|
17
|
+
const exchange_id = exchange.settings.id
|
|
18
|
+
|
|
19
|
+
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
20
|
+
resolve()
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let deposits_fetch_promises = []
|
|
25
|
+
|
|
26
|
+
if (exchange.get_all_deposits) {
|
|
27
|
+
deposits_fetch_promises.push(
|
|
28
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
29
|
+
exchange.get_all_deposits(TIMEFRAME_IN_THE_PAST, function (res) {
|
|
30
|
+
if (res.success) {
|
|
31
|
+
const deposits = JSON.parse(JSON.stringify(res.body))
|
|
32
|
+
_.set(exchange_pair_deposits, [exchange_id], deposits)
|
|
33
|
+
} else {
|
|
34
|
+
delete exchange_pair_deposits[exchange_id]
|
|
35
|
+
}
|
|
36
|
+
_.set(deposits_status, [exchange_name], true)
|
|
37
|
+
resolve_pair()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
)
|
|
41
|
+
} else if (exchange.get_deposits) {
|
|
42
|
+
client_currency.forEach((pair) => {
|
|
43
|
+
deposits_fetch_promises.push(
|
|
44
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
45
|
+
exchange.get_deposits(pair, TIMEFRAME_IN_THE_PAST, function (res) {
|
|
46
|
+
if (res.success) {
|
|
47
|
+
const deposits = JSON.parse(JSON.stringify(res.body))
|
|
48
|
+
_.set(exchange_pair_deposits, [exchange_id, pair], deposits)
|
|
49
|
+
} else {
|
|
50
|
+
delete exchange_pair_deposits[exchange_id][pair]
|
|
51
|
+
}
|
|
52
|
+
_.set(deposits_status, [exchange_name + pair], true)
|
|
53
|
+
resolve_pair()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Promise.all(deposits_fetch_promises)
|
|
61
|
+
.then(() => {
|
|
62
|
+
resolve()
|
|
63
|
+
})
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
console.error('Error fetching deposits:', error)
|
|
66
|
+
resolve()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
Promise.all(promises)
|
|
72
|
+
.then(() => {
|
|
73
|
+
cb(exchange_pair_deposits)
|
|
74
|
+
})
|
|
75
|
+
.catch((error) => {
|
|
76
|
+
console.error('Error fetching deposits:', error)
|
|
77
|
+
cb({})
|
|
78
|
+
})
|
|
79
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
|
|
3
|
+
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
+
|
|
5
|
+
let exchange_pair_open_orders = {}
|
|
6
|
+
let open_orders_status = {}
|
|
7
|
+
|
|
8
|
+
module.exports = function (exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
9
|
+
if (!Array.isArray(exchanges)) {
|
|
10
|
+
console.error('exchanges should be an array')
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const promises = exchanges.map((exchange) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const exchange_name = exchange.Name
|
|
17
|
+
const exchange_id = exchange.settings.id
|
|
18
|
+
|
|
19
|
+
if (!exchange_pair_dict[exchange_name]) {
|
|
20
|
+
resolve()
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const pair_list = exchange_pair_dict[exchange_name]
|
|
25
|
+
|
|
26
|
+
for (let pair of pair_list) {
|
|
27
|
+
_.set(open_orders_status, [exchange_name + pair], false)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
31
|
+
resolve()
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let open_orders_fetch_promises = []
|
|
36
|
+
|
|
37
|
+
if (exchange.get_all_open_orders) {
|
|
38
|
+
open_orders_fetch_promises.push(
|
|
39
|
+
new Promise((resolvePair, rejectPair) => {
|
|
40
|
+
exchange.get_all_open_orders(function (res) {
|
|
41
|
+
if (res.success) {
|
|
42
|
+
const open_orders = res.body
|
|
43
|
+
_.set(exchange_pair_open_orders, [exchange_id], open_orders)
|
|
44
|
+
} else {
|
|
45
|
+
delete exchange_pair_open_orders[exchange_id]
|
|
46
|
+
}
|
|
47
|
+
_.set(open_orders_status, [exchange_name], true)
|
|
48
|
+
resolvePair()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
} else if (exchange.get_open_orders) {
|
|
53
|
+
pair_list.forEach((pair) => {
|
|
54
|
+
open_orders_fetch_promises.push(
|
|
55
|
+
new Promise((resolvePair, rejectPair) => {
|
|
56
|
+
exchange.get_open_orders(pair, function (res) {
|
|
57
|
+
if (res.success) {
|
|
58
|
+
const open_orders = res.body
|
|
59
|
+
_.set(exchange_pair_open_orders, [exchange_id, pair], open_orders)
|
|
60
|
+
} else {
|
|
61
|
+
if (exchange_pair_open_orders[exchange_id]) {
|
|
62
|
+
delete exchange_pair_open_orders[exchange_id][pair]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
_.set(open_orders_status, [exchange_name + pair], true)
|
|
66
|
+
resolvePair()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Promise.all(open_orders_fetch_promises)
|
|
74
|
+
.then(() => {
|
|
75
|
+
resolve()
|
|
76
|
+
})
|
|
77
|
+
.catch((error) => {
|
|
78
|
+
console.error('Error fetching open orders:', error)
|
|
79
|
+
resolve()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
Promise.all(promises)
|
|
85
|
+
.then(() => {
|
|
86
|
+
cb(exchange_pair_open_orders)
|
|
87
|
+
})
|
|
88
|
+
.catch((error) => {
|
|
89
|
+
console.error('Error fetching open orders:', error)
|
|
90
|
+
cb({})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
@@ -3,11 +3,13 @@ const _ = require('lodash')
|
|
|
3
3
|
const DEFAULT_ORDERBOOK_LEVEL = 50
|
|
4
4
|
|
|
5
5
|
let first_time = {},
|
|
6
|
-
checked_rates = {},
|
|
7
6
|
exchange_pair_rates = {},
|
|
8
7
|
pair_exchange_rates = {}
|
|
8
|
+
|
|
9
9
|
module.exports.get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
10
|
-
checked_rates = {}
|
|
10
|
+
let checked_rates = {}
|
|
11
|
+
let promises = []
|
|
12
|
+
|
|
11
13
|
if (!Array.isArray(Exchanges)) {
|
|
12
14
|
console.error('Exchanges should be an array')
|
|
13
15
|
return
|
|
@@ -18,16 +20,65 @@ module.exports.get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb
|
|
|
18
20
|
continue
|
|
19
21
|
}
|
|
20
22
|
checked_rates[Exchange_name] = true
|
|
23
|
+
|
|
21
24
|
if (!exchange_pair_dict[Exchange_name]) {
|
|
22
25
|
continue
|
|
23
26
|
}
|
|
27
|
+
|
|
24
28
|
if (Exchange.ws_market && ws_enabled) {
|
|
25
|
-
|
|
29
|
+
let ws_promise = new Promise((resolve, reject) => {
|
|
26
30
|
Exchange.ws_market(exchange_pair_dict[Exchange_name])
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
const check_status = () => {
|
|
33
|
+
let all_pairs_opened = exchange_pair_dict[Exchange_name].every((pair) => {
|
|
34
|
+
return Exchange.ws.market.pair_status[pair] === 'opened' && Exchange.ws.market.asks_dict[pair].length > 0 && Exchange.ws.market.bids_dict[pair].length > 0
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
if (all_pairs_opened) {
|
|
38
|
+
let rate_promises = exchange_pair_dict[Exchange_name].map((pair) => {
|
|
39
|
+
return new Promise((rate_resolve) => {
|
|
40
|
+
Exchange.rate_ws(pair, function (res) {
|
|
41
|
+
if (res.success) {
|
|
42
|
+
_.set(exchange_pair_rates, [Exchange_name, pair], res.body)
|
|
43
|
+
_.set(pair_exchange_rates, [pair, Exchange_name], res.body)
|
|
44
|
+
} else {
|
|
45
|
+
if (exchange_pair_rates[Exchange_name]) {
|
|
46
|
+
delete exchange_pair_rates[Exchange_name][pair]
|
|
47
|
+
}
|
|
48
|
+
if (pair_exchange_rates[pair]) {
|
|
49
|
+
delete pair_exchange_rates[pair][Exchange_name]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
rate_resolve()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
Promise.all(rate_promises)
|
|
58
|
+
.then(() => {
|
|
59
|
+
// if (Exchange.ws.market.end_base) {
|
|
60
|
+
// Exchange.ws.market.end_base(); // Close the connection and prevent reconnection
|
|
61
|
+
// console.log(`${Exchange_name} WebSocket connection closed.`);
|
|
62
|
+
// }
|
|
63
|
+
resolve()
|
|
64
|
+
})
|
|
65
|
+
.catch((err) => {
|
|
66
|
+
console.error(`Error in rate_ws for ${Exchange_name}:`, err)
|
|
67
|
+
resolve()
|
|
68
|
+
})
|
|
69
|
+
} else {
|
|
70
|
+
setTimeout(check_status, 100)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
check_status()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
promises.push(ws_promise)
|
|
78
|
+
} else if (Exchange.rate) {
|
|
79
|
+
let rate_promises = exchange_pair_dict[Exchange_name].map((pair) => {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
Exchange.rate(pair, DEFAULT_ORDERBOOK_LEVEL, function (res) {
|
|
31
82
|
if (res.success) {
|
|
32
83
|
_.set(exchange_pair_rates, [Exchange_name, pair], res.body)
|
|
33
84
|
_.set(pair_exchange_rates, [pair, Exchange_name], res.body)
|
|
@@ -39,48 +90,48 @@ module.exports.get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb
|
|
|
39
90
|
delete pair_exchange_rates[pair][Exchange_name]
|
|
40
91
|
}
|
|
41
92
|
}
|
|
93
|
+
resolve()
|
|
42
94
|
})
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
} else if (Exchange.rate) {
|
|
46
|
-
for (let pair of exchange_pair_dict[Exchange_name]) {
|
|
47
|
-
Exchange.rate(pair, DEFAULT_ORDERBOOK_LEVEL, function (res) {
|
|
48
|
-
if (res.success) {
|
|
49
|
-
_.set(exchange_pair_rates, [Exchange_name, pair], res.body)
|
|
50
|
-
_.set(pair_exchange_rates, [pair, Exchange_name], res.body)
|
|
51
|
-
} else {
|
|
52
|
-
if (exchange_pair_rates[Exchange_name]) {
|
|
53
|
-
delete exchange_pair_rates[Exchange_name][pair]
|
|
54
|
-
}
|
|
55
|
-
if (pair_exchange_rates[pair]) {
|
|
56
|
-
delete pair_exchange_rates[pair][Exchange_name]
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
95
|
})
|
|
60
|
-
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
promises = promises.concat(rate_promises) // Add all rate promises
|
|
61
99
|
} else if (Exchange.rate_with_routes) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
let rate_with_routes_promises = exchange_pair_dict[Exchange_name].map((pair) => {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
Exchange.rate_with_routes(pair, function (res) {
|
|
103
|
+
if (res.success) {
|
|
104
|
+
let { asks, bids } = res.body
|
|
105
|
+
asks = asks.map((ask) => ask.slice(0, 2))
|
|
106
|
+
bids = bids.map((bid) => bid.slice(0, 2))
|
|
107
|
+
_.set(exchange_pair_rates, [Exchange_name, pair], { asks, bids })
|
|
108
|
+
_.set(pair_exchange_rates, [pair, Exchange_name], { asks, bids })
|
|
109
|
+
} else {
|
|
110
|
+
if (exchange_pair_rates[Exchange_name]) {
|
|
111
|
+
delete exchange_pair_rates[Exchange_name][pair]
|
|
112
|
+
}
|
|
113
|
+
if (pair_exchange_rates[pair]) {
|
|
114
|
+
delete pair_exchange_rates[pair][Exchange_name]
|
|
115
|
+
}
|
|
76
116
|
}
|
|
77
|
-
|
|
117
|
+
resolve()
|
|
118
|
+
})
|
|
78
119
|
})
|
|
79
|
-
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
promises = promises.concat(rate_with_routes_promises) // Add all rate_with_routes promises
|
|
80
123
|
}
|
|
81
124
|
}
|
|
82
125
|
}
|
|
83
|
-
|
|
126
|
+
|
|
127
|
+
Promise.all(promises)
|
|
128
|
+
.then(() => {
|
|
129
|
+
cb({ exchange_pair_rates, pair_exchange_rates })
|
|
130
|
+
})
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
console.error('Error in fetching exchange rates:', error)
|
|
133
|
+
cb({ exchange_pair_rates, pair_exchange_rates })
|
|
134
|
+
})
|
|
84
135
|
}
|
|
85
136
|
|
|
86
137
|
let checked_market_history = {},
|
|
@@ -1,108 +1,140 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
|
|
3
3
|
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
-
const TRADES_TIMEFRAME =
|
|
4
|
+
const TRADES_TIMEFRAME = 1000000 * 60 * 1000
|
|
5
5
|
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
module.exports
|
|
10
|
-
if (!Array.isArray(
|
|
11
|
-
console.error('
|
|
6
|
+
let exchange_pair_trades = {}
|
|
7
|
+
let trades_status = {}
|
|
8
|
+
|
|
9
|
+
module.exports = function (exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
10
|
+
if (!Array.isArray(exchanges)) {
|
|
11
|
+
console.error('exchanges should be an array')
|
|
12
12
|
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const promises = exchanges.map((exchange) => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const exchange_name = exchange.Name
|
|
18
|
+
const exchange_id = exchange.settings.id
|
|
19
|
+
|
|
17
20
|
if (!exchange_pair_dict[exchange_name]) {
|
|
18
|
-
|
|
21
|
+
resolve()
|
|
22
|
+
return
|
|
19
23
|
}
|
|
20
|
-
|
|
24
|
+
|
|
25
|
+
const pair_list = exchange_pair_dict[exchange_name]
|
|
26
|
+
|
|
21
27
|
for (let pair of pair_list) {
|
|
22
|
-
_.set(trades_status, [
|
|
28
|
+
_.set(trades_status, [exchange_name + pair], false)
|
|
23
29
|
}
|
|
30
|
+
|
|
24
31
|
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
resolve()
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let trades_fetch_promises = []
|
|
37
|
+
|
|
38
|
+
if (exchange && exchange.get_all_trades_ws) {
|
|
39
|
+
if (exchange.ws_trades_status().trading === 'n-opened') {
|
|
40
|
+
exchange.ws_account()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pair_list.forEach((pair) => {
|
|
44
|
+
trades_fetch_promises.push(
|
|
45
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
46
|
+
exchange.get_all_trades_ws(pair, TRADES_TIMEFRAME, function (res) {
|
|
47
|
+
if (res.success) {
|
|
48
|
+
const trades = res.body
|
|
49
|
+
_.set(exchange_pair_trades, [exchange_id, pair], trades)
|
|
50
|
+
} else {
|
|
51
|
+
if (exchange_pair_trades[exchange_id]) {
|
|
52
|
+
delete exchange_pair_trades[exchange_id][pair]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_.set(trades_status, [exchange_name + pair], true)
|
|
56
|
+
resolve_pair()
|
|
57
|
+
})
|
|
36
58
|
})
|
|
37
|
-
|
|
38
|
-
} else {
|
|
39
|
-
if (exchange_pair_trades[exchange]) {
|
|
40
|
-
delete exchange_pair_trades[exchange]
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
for (let pair of pair_list) {
|
|
44
|
-
_.set(trades_status, [exchange + pair], true)
|
|
45
|
-
}
|
|
46
|
-
if (!_.includes(_.values(trades_status), false)) {
|
|
47
|
-
cb(exchange_pair_trades)
|
|
48
|
-
}
|
|
59
|
+
)
|
|
49
60
|
})
|
|
50
61
|
} else if (exchange.get_all_trades) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_.set(exchange_pair_trades, [exchange_id, pair],
|
|
62
|
+
trades_fetch_promises.push(
|
|
63
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
64
|
+
exchange.get_all_trades(pair, TRADES_TIMEFRAME, function (res) {
|
|
65
|
+
if (res.success) {
|
|
66
|
+
const trades = res.body
|
|
67
|
+
_.set(exchange_pair_trades, [exchange_id, pair], trades)
|
|
68
|
+
} else {
|
|
69
|
+
if (exchange_pair_trades[exchange_id]) {
|
|
70
|
+
delete exchange_pair_trades[exchange_id][pair]
|
|
71
|
+
}
|
|
57
72
|
}
|
|
58
|
-
|
|
73
|
+
_.set(trades_status, [exchange_name + pair], true)
|
|
74
|
+
resolve_pair()
|
|
59
75
|
})
|
|
60
|
-
} else {
|
|
61
|
-
if (exchange_pair_trades[exchange]) {
|
|
62
|
-
delete exchange_pair_trades[exchange][pair]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
for (let pair of pair_list) {
|
|
66
|
-
_.set(trades_status, [exchange + pair], true)
|
|
67
|
-
}
|
|
68
|
-
if (!_.includes(_.values(trades_status), false)) {
|
|
69
|
-
cb(exchange_pair_trades)
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
} else if (exchange.get_trades_ws) {
|
|
73
|
-
if (exchange.ws_trades_status().trading === 'n-opened') exchange.ws_account()
|
|
74
|
-
for (let pair of pair_list) {
|
|
75
|
-
exchange.get_trades_ws(pair, TRADES_TIMEFRAME, function (res) {
|
|
76
|
-
if (res.success) {
|
|
77
|
-
_.set(exchange_pair_trades, [exchange_id, pair], res.body)
|
|
78
|
-
} else {
|
|
79
|
-
if (exchange_pair_trades[exchange]) {
|
|
80
|
-
delete exchange_pair_trades[exchange][pair]
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
_.set(trades_status, [exchange + pair], true)
|
|
84
|
-
if (!_.includes(_.values(trades_status), false)) {
|
|
85
|
-
cb(exchange_pair_trades)
|
|
86
|
-
}
|
|
87
76
|
})
|
|
77
|
+
)
|
|
78
|
+
} else if (exchange.get_trades_ws) {
|
|
79
|
+
if (exchange.ws_trades_status().trading === 'n-opened') {
|
|
80
|
+
exchange.ws_account()
|
|
88
81
|
}
|
|
82
|
+
|
|
83
|
+
pair_list.forEach((pair) => {
|
|
84
|
+
trades_fetch_promises.push(
|
|
85
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
86
|
+
exchange.get_trades_ws(pair, TRADES_TIMEFRAME, function (res) {
|
|
87
|
+
if (res.success) {
|
|
88
|
+
_.set(exchange_pair_trades, [exchange_id, pair], res.body)
|
|
89
|
+
} else {
|
|
90
|
+
if (exchange_pair_trades[exchange_id]) {
|
|
91
|
+
delete exchange_pair_trades[exchange_id][pair]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_.set(trades_status, [exchange_name + pair], true)
|
|
95
|
+
resolve_pair()
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
})
|
|
89
100
|
} else if (exchange.get_trades) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
pair_list.forEach((pair) => {
|
|
102
|
+
trades_fetch_promises.push(
|
|
103
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
104
|
+
exchange.get_trades(pair, TRADES_TIMEFRAME, function (res) {
|
|
105
|
+
if (res.success) {
|
|
106
|
+
const trades = res.body
|
|
107
|
+
_.set(exchange_pair_trades, [exchange_id, pair], trades)
|
|
108
|
+
} else {
|
|
109
|
+
if (exchange_pair_trades[exchange_id]) {
|
|
110
|
+
delete exchange_pair_trades[exchange_id][pair]
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
_.set(trades_status, [exchange_name + pair], true)
|
|
114
|
+
resolve_pair()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
)
|
|
118
|
+
})
|
|
105
119
|
}
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
|
|
121
|
+
Promise.all(trades_fetch_promises)
|
|
122
|
+
.then(() => {
|
|
123
|
+
resolve()
|
|
124
|
+
})
|
|
125
|
+
.catch((error) => {
|
|
126
|
+
console.error('Error fetching trades:', error)
|
|
127
|
+
resolve()
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
Promise.all(promises)
|
|
133
|
+
.then(() => {
|
|
134
|
+
cb(exchange_pair_trades)
|
|
135
|
+
})
|
|
136
|
+
.catch((error) => {
|
|
137
|
+
console.error('Error fetching trades:', error)
|
|
138
|
+
cb({})
|
|
139
|
+
})
|
|
108
140
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
const TIMEFRAME_IN_THE_PAST = 90 * 24 * 60 * 60 * 1000
|
|
3
|
+
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
+
|
|
5
|
+
let exchange_pair_withdrawals = {}
|
|
6
|
+
let withdrawals_status = {}
|
|
7
|
+
|
|
8
|
+
module.exports = function (exchanges, client_currency, cb) {
|
|
9
|
+
if (!Array.isArray(exchanges)) {
|
|
10
|
+
console.error('exchanges should be an array')
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const promises = exchanges.map((exchange) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const exchange_name = exchange.Name
|
|
17
|
+
const exchange_id = exchange.settings.id
|
|
18
|
+
|
|
19
|
+
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
20
|
+
resolve()
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let withdrawals_fetch_promises = []
|
|
25
|
+
|
|
26
|
+
if (exchange.get_all_withdrawals) {
|
|
27
|
+
withdrawals_fetch_promises.push(
|
|
28
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
29
|
+
exchange.get_all_withdrawals(TIMEFRAME_IN_THE_PAST, function (res) {
|
|
30
|
+
if (res.success) {
|
|
31
|
+
const withdrawals = JSON.parse(JSON.stringify(res.body))
|
|
32
|
+
_.set(exchange_pair_withdrawals, [exchange_id], withdrawals)
|
|
33
|
+
} else {
|
|
34
|
+
delete exchange_pair_withdrawals[exchange_id]
|
|
35
|
+
}
|
|
36
|
+
_.set(withdrawals_status, [exchange_name], true)
|
|
37
|
+
resolve_pair()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
)
|
|
41
|
+
} else if (exchange.get_withdrawals) {
|
|
42
|
+
client_currency.forEach((pair) => {
|
|
43
|
+
withdrawals_fetch_promises.push(
|
|
44
|
+
new Promise((resolve_pair, reject_pair) => {
|
|
45
|
+
exchange.get_withdrawals(pair, TIMEFRAME_IN_THE_PAST, function (res) {
|
|
46
|
+
if (res.success) {
|
|
47
|
+
const withdrawals = JSON.parse(JSON.stringify(res.body))
|
|
48
|
+
_.set(exchange_pair_withdrawals, [exchange_id, pair], withdrawals)
|
|
49
|
+
} else {
|
|
50
|
+
delete exchange_pair_withdrawals[exchange_id][pair]
|
|
51
|
+
}
|
|
52
|
+
_.set(withdrawals_status, [exchange_name + pair], true)
|
|
53
|
+
resolve_pair()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Promise.all(withdrawals_fetch_promises)
|
|
61
|
+
.then(() => {
|
|
62
|
+
resolve()
|
|
63
|
+
})
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
console.error('Error fetching withdrawals:', error)
|
|
66
|
+
resolve()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
Promise.all(promises)
|
|
72
|
+
.then(() => {
|
|
73
|
+
cb(exchange_pair_withdrawals)
|
|
74
|
+
})
|
|
75
|
+
.catch((error) => {
|
|
76
|
+
console.error('Error fetching withdrawals:', error)
|
|
77
|
+
cb({})
|
|
78
|
+
})
|
|
79
|
+
}
|
package/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const { get_exchanges_rates, get_exchanges_market_history, get_exchanges_ohlcv } = require('./functions/get-exchanges-rates-market-history-ohlcv.js')
|
|
2
2
|
const get_exchanges_balance = require('./functions/get-exchanges-balance.js')
|
|
3
3
|
const get_exchanges_trades = require('./functions/get-exchanges-trades.js')
|
|
4
|
+
const get_exchanges_open_orders = require('./functions/get-exchanges-open-orders.js')
|
|
5
|
+
const get_exchanges_deposits = require('./functions/get-exchanges-deposits.js')
|
|
6
|
+
const get_exchanges_withdrawals = require('./functions/get-exchanges-withdrawals.js')
|
|
4
7
|
|
|
5
8
|
module.exports.functions = {
|
|
6
9
|
get_exchanges_rates,
|
|
@@ -8,6 +11,9 @@ module.exports.functions = {
|
|
|
8
11
|
get_exchanges_ohlcv,
|
|
9
12
|
get_exchanges_balance,
|
|
10
13
|
get_exchanges_trades,
|
|
14
|
+
get_exchanges_open_orders,
|
|
15
|
+
get_exchanges_deposits,
|
|
16
|
+
get_exchanges_withdrawals,
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
module.exports.orders = require('./middleware/orders.js')
|
package/middleware/account.js
CHANGED
|
@@ -98,7 +98,9 @@ module.exports = class Account {
|
|
|
98
98
|
_.set(exchange_position, [exchange, cur, 'percentage'], ((diff / exchange_assets_balances[exchange][cur]) * 100).toPrecision(3) + '%')
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
exchange_position[exchange] = utils.sort_keys(exchange_position[exchange])
|
|
101
102
|
}
|
|
103
|
+
exchange_position = utils.sort_keys(exchange_position)
|
|
102
104
|
return exchange_position
|
|
103
105
|
}
|
|
104
106
|
get_position(balances, type = 'initial') {
|