@icgio/icg-exchanges-wrapper 1.14.24 → 1.14.26
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 +29 -25
- package/functions/get-exchanges-deposits.js +5 -1
- package/functions/get-exchanges-open-orders.js +5 -1
- package/functions/get-exchanges-rates-market-history-ohlcv.js +9 -3
- package/functions/get-exchanges-trades.js +5 -1
- package/functions/get-exchanges-withdrawals.js +5 -1
- package/middleware/orders.js +14 -8
- package/package.json +2 -2
|
@@ -1,46 +1,50 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
1
|
+
const _ = require('lodash')
|
|
2
2
|
let balances = {}
|
|
3
|
-
|
|
3
|
+
const get_exchanges_balance = function (exchanges, cb) {
|
|
4
4
|
if (!Array.isArray(exchanges)) {
|
|
5
|
-
console.error('exchanges should be an array')
|
|
6
|
-
return
|
|
5
|
+
console.error('exchanges should be an array')
|
|
6
|
+
return
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const promises = exchanges.map(exchange => {
|
|
9
|
+
const promises = exchanges.map((exchange) => {
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
11
|
if (exchange.balance_ws) {
|
|
12
|
-
if (exchange.ws_status().trading === 'n-opened') exchange.ws_account()
|
|
12
|
+
if (exchange.ws_status().trading === 'n-opened') exchange.ws_account()
|
|
13
13
|
exchange.balance_ws(function (res) {
|
|
14
14
|
if (res.success) {
|
|
15
|
-
_.set(balances, exchange.settings.id, res.body)
|
|
16
|
-
resolve()
|
|
15
|
+
_.set(balances, exchange.settings.id, res.body)
|
|
16
|
+
resolve()
|
|
17
17
|
} else {
|
|
18
|
-
delete balances[exchange.name]
|
|
19
|
-
resolve()
|
|
18
|
+
delete balances[exchange.name]
|
|
19
|
+
resolve()
|
|
20
20
|
}
|
|
21
|
-
})
|
|
21
|
+
})
|
|
22
22
|
} else if (exchange.balance) {
|
|
23
23
|
exchange.balance(function (res) {
|
|
24
24
|
if (res.success) {
|
|
25
|
-
_.set(balances, exchange.settings.id, res.body)
|
|
26
|
-
resolve()
|
|
25
|
+
_.set(balances, exchange.settings.id, res.body)
|
|
26
|
+
resolve()
|
|
27
27
|
} else {
|
|
28
|
-
delete balances[exchange.name]
|
|
29
|
-
resolve()
|
|
28
|
+
delete balances[exchange.name]
|
|
29
|
+
resolve()
|
|
30
30
|
}
|
|
31
|
-
})
|
|
31
|
+
})
|
|
32
32
|
} else {
|
|
33
|
-
resolve()
|
|
33
|
+
resolve()
|
|
34
34
|
}
|
|
35
|
-
})
|
|
36
|
-
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
37
|
|
|
38
38
|
Promise.all(promises)
|
|
39
39
|
.then(() => {
|
|
40
|
-
cb(balances)
|
|
40
|
+
cb(balances)
|
|
41
|
+
})
|
|
42
|
+
.catch((error) => {
|
|
43
|
+
console.error('Error fetching balances:', error)
|
|
44
|
+
cb({})
|
|
41
45
|
})
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
get_exchanges_balance,
|
|
50
|
+
}
|
|
@@ -5,7 +5,7 @@ const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
|
5
5
|
let exchange_pair_deposits = {}
|
|
6
6
|
let deposits_status = {}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function get_exchanges_deposits(exchanges, client_currency, cb) {
|
|
9
9
|
if (!Array.isArray(exchanges)) {
|
|
10
10
|
console.error('exchanges should be an array')
|
|
11
11
|
return
|
|
@@ -77,3 +77,7 @@ module.exports = function (exchanges, client_currency, cb) {
|
|
|
77
77
|
cb({})
|
|
78
78
|
})
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
get_exchanges_deposits,
|
|
83
|
+
}
|
|
@@ -5,7 +5,7 @@ const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
|
5
5
|
let exchange_pair_open_orders = {}
|
|
6
6
|
let open_orders_status = {}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const get_exchanges_open_orders = function (exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
9
9
|
if (!Array.isArray(exchanges)) {
|
|
10
10
|
console.error('exchanges should be an array')
|
|
11
11
|
return
|
|
@@ -90,3 +90,7 @@ module.exports = function (exchanges, exchange_pair_dict, cb, ws_enabled = true)
|
|
|
90
90
|
cb({})
|
|
91
91
|
})
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
module.exports = {
|
|
95
|
+
get_exchanges_open_orders,
|
|
96
|
+
}
|
|
@@ -6,7 +6,7 @@ let first_time = {},
|
|
|
6
6
|
exchange_pair_rates = {},
|
|
7
7
|
pair_exchange_rates = {}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
10
10
|
let checked_rates = {}
|
|
11
11
|
let promises = []
|
|
12
12
|
|
|
@@ -137,7 +137,7 @@ module.exports.get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb
|
|
|
137
137
|
let checked_market_history = {},
|
|
138
138
|
exchange_pair_market_history = {},
|
|
139
139
|
pair_exchange_market_history = {}
|
|
140
|
-
|
|
140
|
+
const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, timeframe_in_ms, cb, ws_enabled = true) {
|
|
141
141
|
checked_market_history = {}
|
|
142
142
|
if (!Array.isArray(Exchanges)) {
|
|
143
143
|
console.error('Exchanges should be an array')
|
|
@@ -199,7 +199,7 @@ let checked_ohlcv_exchange = {},
|
|
|
199
199
|
ohlcv_status = {},
|
|
200
200
|
exchange_pair_ohlcv = {},
|
|
201
201
|
pair_exchange_ohlcv = {}
|
|
202
|
-
|
|
202
|
+
const get_exchanges_ohlcv = function (Exchanges, exchange_pair_dict, from_in_ms, to_in_ms, cb) {
|
|
203
203
|
checked_ohlcv_exchange = {}
|
|
204
204
|
if (!Array.isArray(Exchanges)) {
|
|
205
205
|
console.error('Exchanges should be an array')
|
|
@@ -244,3 +244,9 @@ module.exports.get_exchanges_ohlcv = function (Exchanges, exchange_pair_dict, fr
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
+
|
|
248
|
+
module.exports = {
|
|
249
|
+
get_exchanges_rates,
|
|
250
|
+
get_exchanges_market_history,
|
|
251
|
+
get_exchanges_ohlcv,
|
|
252
|
+
}
|
|
@@ -6,7 +6,7 @@ const TRADES_TIMEFRAME = 1000000 * 60 * 1000
|
|
|
6
6
|
let exchange_pair_trades = {}
|
|
7
7
|
let trades_status = {}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const get_exchanges_trades = function (exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
10
10
|
if (!Array.isArray(exchanges)) {
|
|
11
11
|
console.error('exchanges should be an array')
|
|
12
12
|
return
|
|
@@ -138,3 +138,7 @@ module.exports = function (exchanges, exchange_pair_dict, cb, ws_enabled = true)
|
|
|
138
138
|
cb({})
|
|
139
139
|
})
|
|
140
140
|
}
|
|
141
|
+
|
|
142
|
+
module.exports = {
|
|
143
|
+
get_exchanges_trades,
|
|
144
|
+
}
|
|
@@ -5,7 +5,7 @@ const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
|
5
5
|
let exchange_pair_withdrawals = {}
|
|
6
6
|
let withdrawals_status = {}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const get_exchanges_withdrawals = function (exchanges, client_currency, cb) {
|
|
9
9
|
if (!Array.isArray(exchanges)) {
|
|
10
10
|
console.error('exchanges should be an array')
|
|
11
11
|
return
|
|
@@ -77,3 +77,7 @@ module.exports = function (exchanges, client_currency, cb) {
|
|
|
77
77
|
cb({})
|
|
78
78
|
})
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
get_exchanges_withdrawals,
|
|
83
|
+
}
|
package/middleware/orders.js
CHANGED
|
@@ -55,13 +55,14 @@ const MARKET_HISTORY_DEFAULT_TIME = 10 * 60 * 1000
|
|
|
55
55
|
const TRADES_DEFAULT_TIME = 7 * 24 * 60 * 60 * 1000
|
|
56
56
|
const NO_CALLBACK_TIMEOUT = 2 * 60 * 1000
|
|
57
57
|
const COMBINE_ORDERBOOKS_LEVEL = 100
|
|
58
|
+
const PROCESS_RATES_THROTTLE = 10
|
|
58
59
|
|
|
59
60
|
module.exports = class Orders {
|
|
60
61
|
constructor(exchange_cur_quote_cur_dict, cd, settings) {
|
|
61
62
|
let { exchange_cur_quote_cur, exchange_cur_quote_cur_rates_only, pair_map_rates_only } = exchange_cur_quote_cur_dict
|
|
62
63
|
this.exchange_cur_quote_cur = exchange_cur_quote_cur
|
|
63
64
|
this.exchange_cur_quote_cur_rates_only = exchange_cur_quote_cur_rates_only
|
|
64
|
-
this.pair_map_rates_only = pair_map_rates_only
|
|
65
|
+
this.pair_map_rates_only = pair_map_rates_only || {}
|
|
65
66
|
let { exchange_pairs, pair_exchanges } = utils.exchange_cur_quote_cur_converter(exchange_cur_quote_cur)
|
|
66
67
|
let { exchange_pairs: exchange_pairs_rates_only, pair_exchanges: pair_exchanges_rates_only } = utils.exchange_cur_quote_cur_converter(exchange_cur_quote_cur_rates_only)
|
|
67
68
|
this.exchange_pairs = exchange_pairs
|
|
@@ -1209,7 +1210,7 @@ module.exports = class Orders {
|
|
|
1209
1210
|
orderbook_all = _.omit(orderbook_all, [exchange])
|
|
1210
1211
|
}
|
|
1211
1212
|
if (_.get(this.rates, [exchange, pair, 'asks'], []).length > 0 && _.get(this.rates, [exchange, pair, 'bids'], []).length > 0) {
|
|
1212
|
-
|
|
1213
|
+
const rates = _.cloneDeep(this.rates[exchange][pair])
|
|
1213
1214
|
|
|
1214
1215
|
let major_rates_only_exchanges_length = this.major_exchanges[pair].length + _.get(this.rates_only_exchanges, [pair], []).length
|
|
1215
1216
|
if (this.major_exchanges[pair] && _.includes(this.major_exchanges[pair], exchange)) {
|
|
@@ -1279,8 +1280,14 @@ module.exports = class Orders {
|
|
|
1279
1280
|
} else {
|
|
1280
1281
|
this.rates_combined_good_with_buy_sell_limits_against_reserve_balance = _.omit(this.rates_combined_good_with_buy_sell_limits_against_reserve_balance, [pair])
|
|
1281
1282
|
}
|
|
1283
|
+
if (this.pair_map_rates_only[pair]) {
|
|
1284
|
+
const reference_pair = this.pair_map_rates_only[pair]
|
|
1285
|
+
this.rates_combined_major[reference_pair] = this.rates_combined_major[pair]
|
|
1286
|
+
}
|
|
1282
1287
|
}
|
|
1288
|
+
this.rates_observable.notify()
|
|
1283
1289
|
}
|
|
1290
|
+
const throttled_process_rates = _.throttle(process_rates, PROCESS_RATES_THROTTLE, { leading: true, trailing: true })
|
|
1284
1291
|
let rates_handler = (exchange, pair, res, rates_with_routes = false) => {
|
|
1285
1292
|
if (res.success) {
|
|
1286
1293
|
let { asks, bids } = res.body
|
|
@@ -1292,16 +1299,15 @@ module.exports = class Orders {
|
|
|
1292
1299
|
asks = asks.slice(0, RATES_LENGTH_MAX)
|
|
1293
1300
|
bids = bids.slice(0, RATES_LENGTH_MAX)
|
|
1294
1301
|
_.set(this.rates, [exchange, pair], { asks, bids, update_time: new Date() })
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
}
|
|
1302
|
+
/*
|
|
1303
|
+
* throttle to 10ms
|
|
1304
|
+
*/
|
|
1305
|
+
throttled_process_rates()
|
|
1300
1306
|
} else if (_.get(this.rates, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].rates) {
|
|
1301
1307
|
this.info_log('%s %s rates expired: %j', exchange, pair, res)
|
|
1302
1308
|
this.rates[exchange] = _.omit(this.rates[exchange], [pair])
|
|
1309
|
+
this.rates_observable.notify()
|
|
1303
1310
|
}
|
|
1304
|
-
this.rates_observable.notify()
|
|
1305
1311
|
}
|
|
1306
1312
|
let get_rates = (Exchanges, ExchangesRatesOnly, exchange_pairs, exchange_pairs_rates_only, interval_dict) => {
|
|
1307
1313
|
if (!this.ws_market_first_time) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@icgio/icg-exchanges": "^1.32.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.32.22",
|
|
21
21
|
"@icgio/icg-exchanges-data": "^1.10.11",
|
|
22
22
|
"@icgio/icg-utils": "^1.9.13",
|
|
23
23
|
"influx": "^5.10.0",
|