@icgio/icg-exchanges-wrapper 1.9.164 → 1.9.166

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.
@@ -104,6 +104,7 @@ module.exports = class Orders {
104
104
  query_order: 10 * 1000,
105
105
  rates: 1 * 1000,
106
106
  market_history: 2 * 1000,
107
+ ohlcv: 10 * 60 * 1000,
107
108
  }
108
109
  } else {
109
110
  this.interval_dict[exchange].balances = this.interval_dict[exchange].balances || 10 * 1000
@@ -113,6 +114,7 @@ module.exports = class Orders {
113
114
  this.interval_dict[exchange].query_order = this.interval_dict[exchange].query_order || 10 * 1000
114
115
  this.interval_dict[exchange].rates = this.interval_dict[exchange].rates || 1 * 1000
115
116
  this.interval_dict[exchange].market_history = this.interval_dict[exchange].market_history || 2 * 1000
117
+ this.interval_dict[exchange].ohlcv = this.interval_dict[exchange].ohlcv || 10 * 60 * 1000
116
118
  }
117
119
  }
118
120
  for (let exchange in this.exchange_basecur_curs_rates_only) {
@@ -125,6 +127,7 @@ module.exports = class Orders {
125
127
  this.query_order = {}
126
128
  this.rates = {}
127
129
  this.market_history = {}
130
+ this.ohlcv = {}
128
131
  this.cmc_rates = {}
129
132
  this.rates_combined_all = {}
130
133
  this.rates_combined_all_with_buy_sell_limits_against_reserve_balance = {}
@@ -143,6 +146,7 @@ module.exports = class Orders {
143
146
  query_order_check: false,
144
147
  rates_check: true,
145
148
  market_history_check: true,
149
+ ohlcv_check: false,
146
150
  cmc_rates_check: true,
147
151
  }
148
152
  this.info_log = (...args) => {
@@ -173,6 +177,9 @@ module.exports = class Orders {
173
177
  if (this.enabled.market_history_check) {
174
178
  this.check_market_history()
175
179
  }
180
+ if (this.enabled.ohlcv_check) {
181
+ this.check_ohlcv()
182
+ }
176
183
  if (this.enabled.cmc_rates_check) {
177
184
  this.check_cmc_rates(this.cmc_curs, 'curs')
178
185
  }
@@ -1265,7 +1272,7 @@ module.exports = class Orders {
1265
1272
  check_market_history() {
1266
1273
  let market_history_handler = (exchange, pair, res) => {
1267
1274
  if (res.success) {
1268
- _.set(this.market_history, [exchange, pair], Object.assign(res.body, { update_time: new Date() }))
1275
+ _.set(this.market_history, [exchange, pair], { data: res.body, update_time: new Date() })
1269
1276
  } else if (_.get(this.market_history, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].market_history) {
1270
1277
  this.info_log('%s %s market_history expired: %j', exchange, pair, res)
1271
1278
  this.market_history[exchange] = _.omit(this.market_history[exchange], [pair])
@@ -1300,6 +1307,36 @@ module.exports = class Orders {
1300
1307
  }
1301
1308
  get_market_history(this.Exchanges, this.exchange_pairs, this.interval_dict)
1302
1309
  }
1310
+ check_ohlcv() {
1311
+ let ohlcv_handler = (exchange, pair, res) => {
1312
+ if (res.success) {
1313
+ _.set(this.ohlcv, [exchange, pair], { data: res.body, update_time: new Date() })
1314
+ } else if (_.get(this.ohlcv, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].ohlcv) {
1315
+ this.info_log('%s %s ohlcv expired: %j', exchange, pair, res)
1316
+ this.ohlcv[exchange] = _.omit(this.ohlcv[exchange], [pair])
1317
+ }
1318
+ }
1319
+ const OHLCV_DEFAULT_PAST_HOURS = 24
1320
+ let get_ohlcv = (Exchanges, exchange_pairs, interval_dict) => {
1321
+ for (let exchange in Exchanges) {
1322
+ for (let pair of exchange_pairs[exchange]) {
1323
+ if (Exchanges[exchange].ohlcv) {
1324
+ let ohlcv_from_timetamp = new Date().floorHours(1).addHours(-OHLCV_DEFAULT_PAST_HOURS)
1325
+ let ohlcv_to_timestamp = new Date().floorHours(1)
1326
+ Exchanges[exchange].ohlcv(pair, ohlcv_from_timetamp, ohlcv_to_timestamp, (res) => {
1327
+ ohlcv_handler(exchange, pair, res)
1328
+ })
1329
+ setInterval(() => {
1330
+ Exchanges[exchange].ohlcv(pair, ohlcv_from_timetamp, ohlcv_to_timestamp, (res) => {
1331
+ ohlcv_handler(exchange, pair, res)
1332
+ })
1333
+ }, interval_dict[exchange].ohlcv)
1334
+ }
1335
+ }
1336
+ }
1337
+ }
1338
+ get_ohlcv(this.Exchanges, this.exchange_pairs, this.interval_dict)
1339
+ }
1303
1340
  check_cmc_rates(data, type) {
1304
1341
  let check_cmc_rates_base = (data) => {
1305
1342
  get_coinmarketcap_rates(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.9.164",
3
+ "version": "1.9.166",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
19
19
  "dependencies": {
20
- "@icgio/icg-exchanges": "^1.27.114",
21
- "@icgio/icg-exchanges-data": "^1.6.59",
20
+ "@icgio/icg-exchanges": "^1.27.116",
21
+ "@icgio/icg-exchanges-data": "^1.6.60",
22
22
  "@icgio/icg-utils": "^1.7.37",
23
23
  "influx": "^5.7.0",
24
24
  "lodash": "^4.17.20",