@icgio/icg-exchanges-wrapper 1.14.23 → 1.14.25
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/middleware/orders.js +24 -14
- package/package.json +3 -3
package/middleware/orders.js
CHANGED
|
@@ -55,14 +55,16 @@ 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
|
-
constructor(
|
|
61
|
-
let {
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
let { exchange_pairs
|
|
61
|
+
constructor(exchange_cur_quote_cur_dict, cd, settings) {
|
|
62
|
+
let { exchange_cur_quote_cur, exchange_cur_quote_cur_rates_only, pair_map_rates_only } = exchange_cur_quote_cur_dict
|
|
63
|
+
this.exchange_cur_quote_cur = exchange_cur_quote_cur
|
|
64
|
+
this.exchange_cur_quote_cur_rates_only = exchange_cur_quote_cur_rates_only
|
|
65
|
+
this.pair_map_rates_only = pair_map_rates_only || {}
|
|
66
|
+
let { exchange_pairs, pair_exchanges } = utils.exchange_cur_quote_cur_converter(exchange_cur_quote_cur)
|
|
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)
|
|
66
68
|
this.exchange_pairs = exchange_pairs
|
|
67
69
|
this.pair_exchanges = pair_exchanges
|
|
68
70
|
this.exchange_pairs_rates_only = exchange_pairs_rates_only
|
|
@@ -137,7 +139,7 @@ module.exports = class Orders {
|
|
|
137
139
|
this.interval_dict[exchange].ohlcv = this.interval_dict[exchange].ohlcv || 10 * 60 * 1000
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
|
-
for (let exchange in this.
|
|
142
|
+
for (let exchange in this.exchange_cur_quote_cur_rates_only) {
|
|
141
143
|
this.ExchangesRatesOnly[exchange] = new icg_exchanges[_.upperFirst(exchange)]('', '', STANDARD_LIMITS)
|
|
142
144
|
}
|
|
143
145
|
this.balances = {}
|
|
@@ -742,9 +744,9 @@ module.exports = class Orders {
|
|
|
742
744
|
let balances_handler = (exchange, res) => {
|
|
743
745
|
if (res.success) {
|
|
744
746
|
_.set(this.balances, [exchange], Object.assign(res.body, { update_time: new Date() }))
|
|
745
|
-
for (let exchange in this.
|
|
746
|
-
for (let quote_cur in this.
|
|
747
|
-
this.
|
|
747
|
+
for (let exchange in this.exchange_cur_quote_cur) {
|
|
748
|
+
for (let quote_cur in this.exchange_cur_quote_cur[exchange]) {
|
|
749
|
+
this.exchange_cur_quote_cur[exchange][quote_cur].map((cur) => {
|
|
748
750
|
let cur_balance = _.get(this.balances, [exchange, 'available', cur], 0)
|
|
749
751
|
let quote_cur_balance = _.get(this.balances, [exchange, 'available', quote_cur], 0)
|
|
750
752
|
let pair = cur + quote_cur
|
|
@@ -1208,7 +1210,7 @@ module.exports = class Orders {
|
|
|
1208
1210
|
orderbook_all = _.omit(orderbook_all, [exchange])
|
|
1209
1211
|
}
|
|
1210
1212
|
if (_.get(this.rates, [exchange, pair, 'asks'], []).length > 0 && _.get(this.rates, [exchange, pair, 'bids'], []).length > 0) {
|
|
1211
|
-
|
|
1213
|
+
const rates = _.cloneDeep(this.rates[exchange][pair])
|
|
1212
1214
|
|
|
1213
1215
|
let major_rates_only_exchanges_length = this.major_exchanges[pair].length + _.get(this.rates_only_exchanges, [pair], []).length
|
|
1214
1216
|
if (this.major_exchanges[pair] && _.includes(this.major_exchanges[pair], exchange)) {
|
|
@@ -1278,8 +1280,14 @@ module.exports = class Orders {
|
|
|
1278
1280
|
} else {
|
|
1279
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])
|
|
1280
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
|
+
}
|
|
1281
1287
|
}
|
|
1288
|
+
this.rates_observable.notify()
|
|
1282
1289
|
}
|
|
1290
|
+
const throttled_process_rates = _.throttle(process_rates, PROCESS_RATES_THROTTLE, { leading: true, trailing: true })
|
|
1283
1291
|
let rates_handler = (exchange, pair, res, rates_with_routes = false) => {
|
|
1284
1292
|
if (res.success) {
|
|
1285
1293
|
let { asks, bids } = res.body
|
|
@@ -1291,13 +1299,15 @@ module.exports = class Orders {
|
|
|
1291
1299
|
asks = asks.slice(0, RATES_LENGTH_MAX)
|
|
1292
1300
|
bids = bids.slice(0, RATES_LENGTH_MAX)
|
|
1293
1301
|
_.set(this.rates, [exchange, pair], { asks, bids, update_time: new Date() })
|
|
1294
|
-
|
|
1295
|
-
|
|
1302
|
+
/*
|
|
1303
|
+
* throttle to 10ms
|
|
1304
|
+
*/
|
|
1305
|
+
throttled_process_rates()
|
|
1296
1306
|
} else if (_.get(this.rates, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].rates) {
|
|
1297
1307
|
this.info_log('%s %s rates expired: %j', exchange, pair, res)
|
|
1298
1308
|
this.rates[exchange] = _.omit(this.rates[exchange], [pair])
|
|
1309
|
+
this.rates_observable.notify()
|
|
1299
1310
|
}
|
|
1300
|
-
this.rates_observable.notify()
|
|
1301
1311
|
}
|
|
1302
1312
|
let get_rates = (Exchanges, ExchangesRatesOnly, exchange_pairs, exchange_pairs_rates_only, interval_dict) => {
|
|
1303
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.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,9 +17,9 @@
|
|
|
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
|
-
"@icgio/icg-utils": "^1.9.
|
|
22
|
+
"@icgio/icg-utils": "^1.9.13",
|
|
23
23
|
"influx": "^5.10.0",
|
|
24
24
|
"lodash": "^4.17.20",
|
|
25
25
|
"uuid": "^11.1.0",
|