@icgio/icg-exchanges-wrapper 1.12.211 → 1.13.0

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.
@@ -4,7 +4,7 @@ const { v4: uuid } = require('uuid')
4
4
 
5
5
  const icg_exchanges = require('@icgio/icg-exchanges')
6
6
  const utils = require('@icgio/icg-utils').utils
7
- const get_coinmarketcap_rates = require('@icgio/icg-utils').coinmarketcap
7
+ const { coinmarketcap: get_coinmarketcap_rates, observable: Observable } = require('@icgio/icg-utils')
8
8
 
9
9
  const { round_price, round_amount } = require('@icgio/icg-exchanges-data')
10
10
 
@@ -103,9 +103,9 @@ module.exports = class Orders {
103
103
  LIMITS
104
104
  if (_.includes(['binance', 'gate', 'gatev4'], exchange)) {
105
105
  LIMITS = MEDIUM_LIMITS
106
- } else if (_.includes(['bitfinex', 'bitforex', 'bkex', 'coinsbit', 'kucoin', 'lbank', 'okx', 'phemex', 'xt'], exchange)) {
106
+ } else if (_.includes(['bitfinex', 'coinsbit', 'kucoin', 'lbank', 'okx', 'phemex', 'xt'], exchange)) {
107
107
  LIMITS = SMALL_LIMITS
108
- } else if (_.includes(['bitkub', 'coinbene', 'poloniex'], exchange)) {
108
+ } else if (_.includes(['bitkub', 'poloniex'], exchange)) {
109
109
  LIMITS = MINIMUM_LIMITS
110
110
  } else if (_.includes(['swft'], exchange)) {
111
111
  LIMITS = SWFT_LIMITS
@@ -147,6 +147,7 @@ module.exports = class Orders {
147
147
  this.query_order = {}
148
148
  this.rates = {}
149
149
  this.rates_with_routes = {}
150
+ this.rates_observable = new Observable()
150
151
  this.market_history = {}
151
152
  this.ohlcv = {}
152
153
  this.cmc_rates = {}
@@ -224,7 +225,6 @@ module.exports = class Orders {
224
225
  this.process_query_order(this.query_order)
225
226
  }, PROCESS_INTERVAL)
226
227
  }
227
- this.ws_market_first_time = {}
228
228
  }
229
229
  init_account(balances, benchmarks) {
230
230
  this.account = new Account(balances, benchmarks)
@@ -1282,22 +1282,23 @@ module.exports = class Orders {
1282
1282
  this.info_log('%s %s rates expired: %j', exchange, pair, res)
1283
1283
  this.rates[exchange] = _.omit(this.rates[exchange], [pair])
1284
1284
  }
1285
+ this.rates_observable.notify()
1285
1286
  }
1286
1287
  let get_rates = (Exchanges, ExchangesRatesOnly, exchange_pairs, exchange_pairs_rates_only, interval_dict) => {
1288
+ if (!this.ws_market_first_time) {
1289
+ this.ws_market_first_time = {}
1290
+ }
1287
1291
  for (let exchange in Exchanges) {
1288
1292
  if (Exchanges[exchange].ws_market && Exchanges[exchange].exchange_type === 'spot') {
1289
- setInterval(() => {
1290
- if (!this.ws_market_first_time[exchange]) {
1291
- Exchanges[exchange].ws_market(exchange_pairs[exchange])
1292
- this.ws_market_first_time[exchange] = true
1293
- } else {
1294
- for (let pair of exchange_pairs[exchange]) {
1295
- Exchanges[exchange].rate_ws(pair, (res) => {
1296
- rates_handler(exchange, pair, res)
1297
- })
1298
- }
1299
- }
1300
- }, interval_dict[exchange].rates)
1293
+ if (!this.ws_market_first_time[exchange]) {
1294
+ Exchanges[exchange].ws_market(exchange_pairs[exchange])
1295
+ this.ws_market_first_time[exchange] = true
1296
+ }
1297
+ for (let pair of exchange_pairs[exchange]) {
1298
+ Exchanges[exchange].rate_ws_observable(pair, (res) => {
1299
+ rates_handler(exchange, pair, res)
1300
+ })
1301
+ }
1301
1302
  } else if (Exchanges[exchange].ws_market && Exchanges[exchange].exchange_type === 'dex') {
1302
1303
  setInterval(() => {
1303
1304
  if (!this.ws_market_first_time[exchange]) {
@@ -1331,18 +1332,15 @@ module.exports = class Orders {
1331
1332
  }
1332
1333
  for (let exchange in ExchangesRatesOnly) {
1333
1334
  if (ExchangesRatesOnly[exchange].ws_market) {
1334
- setInterval(() => {
1335
- if (!this.ws_market_first_time[exchange]) {
1336
- ExchangesRatesOnly[exchange].ws_market(exchange_pairs_rates_only[exchange])
1337
- this.ws_market_first_time[exchange] = true
1338
- } else {
1339
- for (let pair of exchange_pairs_rates_only[exchange]) {
1340
- ExchangesRatesOnly[exchange].rate_ws(pair, (res) => {
1341
- rates_handler(exchange, pair, res)
1342
- })
1343
- }
1344
- }
1345
- }, interval_dict[exchange].rates)
1335
+ if (!this.ws_market_first_time[exchange]) {
1336
+ ExchangesRatesOnly[exchange].ws_market(exchange_pairs_rates_only[exchange])
1337
+ this.ws_market_first_time[exchange] = true
1338
+ }
1339
+ for (let pair of exchange_pairs_rates_only[exchange]) {
1340
+ ExchangesRatesOnly[exchange].rate_ws_observable(pair, (res) => {
1341
+ rates_handler(exchange, pair, res)
1342
+ })
1343
+ }
1346
1344
  } else {
1347
1345
  for (let pair of exchange_pairs_rates_only[exchange]) {
1348
1346
  setInterval(() => {
@@ -1369,18 +1367,15 @@ module.exports = class Orders {
1369
1367
  for (let exchange in Exchanges) {
1370
1368
  const market_history_timeframe = exchange === 'coinbene' ? 30 * 24 * 60 * 60 * 1000 : MARKET_HISTORY_DEFAULT_TIME
1371
1369
  if (Exchanges[exchange].ws_market && Exchanges[exchange].exchange_type === 'spot') {
1372
- setInterval(() => {
1373
- if (!this.ws_market_first_time[exchange]) {
1374
- Exchanges[exchange].ws_market(exchange_pairs[exchange])
1375
- this.ws_market_first_time[exchange] = true
1376
- } else {
1377
- for (let pair of exchange_pairs[exchange]) {
1378
- Exchanges[exchange].market_history_ws(pair, market_history_timeframe, (res) => {
1379
- market_history_handler(exchange, pair, res)
1380
- })
1381
- }
1382
- }
1383
- }, interval_dict[exchange].market_history)
1370
+ if (!this.ws_market_first_time[exchange]) {
1371
+ Exchanges[exchange].ws_market(exchange_pairs[exchange])
1372
+ this.ws_market_first_time[exchange] = true
1373
+ }
1374
+ for (let pair of exchange_pairs[exchange]) {
1375
+ Exchanges[exchange].market_history_ws_observable(pair, market_history_timeframe, (res) => {
1376
+ market_history_handler(exchange, pair, res)
1377
+ })
1378
+ }
1384
1379
  } else if (Exchanges[exchange].market_history) {
1385
1380
  for (let pair of exchange_pairs[exchange]) {
1386
1381
  setInterval(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.12.211",
3
+ "version": "1.13.0",
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.30.95",
21
- "@icgio/icg-exchanges-data": "^1.8.173",
22
- "@icgio/icg-utils": "^1.7.77",
20
+ "@icgio/icg-exchanges": "^1.31.0",
21
+ "@icgio/icg-exchanges-data": "^1.9.0",
22
+ "@icgio/icg-utils": "^1.8.0",
23
23
  "influx": "^5.7.0",
24
24
  "lodash": "^4.17.20",
25
25
  "uuid": "^9.0.1",