@icgio/icg-exchanges-wrapper 1.9.167 → 1.9.169

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/.prettierignore CHANGED
@@ -3,5 +3,4 @@ node_modules/
3
3
  lib/test*
4
4
  lib/bash.sh
5
5
  *.key
6
- test/
7
- test*
6
+ test/
package/index.js CHANGED
@@ -15,4 +15,3 @@ module.exports.functions = {
15
15
  }
16
16
 
17
17
  module.exports.orders = require('./middleware/orders.js')
18
- module.exports.websocket = require('./middleware/websocket.js')
@@ -126,6 +126,7 @@ module.exports = class Orders {
126
126
  this.trades = {}
127
127
  this.query_order = {}
128
128
  this.rates = {}
129
+ this.rates_with_routes = {}
129
130
  this.market_history = {}
130
131
  this.ohlcv = {}
131
132
  this.cmc_rates = {}
@@ -136,60 +137,65 @@ module.exports = class Orders {
136
137
  this.buy_sell_limits_against_reserve_balance = {}
137
138
  this.order_info = {}
138
139
  this.order_info_status = {}
139
- this.enabled = settings.enabled || {
140
+ this.function_enabled = settings.function_enabled || {
140
141
  info_log: true,
141
142
  error_log: true,
142
143
  balances_check: true,
143
144
  positions_check: false,
144
145
  open_orders_check: true,
145
146
  trades_check: true,
146
- query_order_check: false,
147
+ query_order_check: true,
148
+ query_order_check_exchange: {},
147
149
  rates_check: true,
148
150
  market_history_check: true,
149
151
  ohlcv_check: false,
150
152
  cmc_rates_check: true,
151
153
  }
152
154
  this.info_log = (...args) => {
153
- if (this.enabled.info_log) console.log(...args)
155
+ if (this.function_enabled.info_log) console.log(...args)
154
156
  }
155
157
  this.error_log = (...args) => {
156
- if (this.enabled.info_log) console.error(...args)
158
+ if (this.function_enabled.info_log) console.error(...args)
157
159
  }
158
- if (this.enabled.balances_check) {
160
+ if (this.function_enabled.balances_check) {
159
161
  this.check_balances()
160
162
  }
161
- if (this.enabled.positions_check) {
163
+ if (this.function_enabled.positions_check) {
162
164
  this.check_positions()
163
165
  }
164
- if (this.enabled.open_orders_check) {
166
+ if (this.function_enabled.open_orders_check) {
165
167
  this.check_open_orders()
166
168
  }
167
- if (this.enabled.trades_check) {
169
+ if (this.function_enabled.trades_check) {
168
170
  this.trades_amount_past_hour = {}
169
171
  this.check_trades()
170
172
  }
171
- if (this.enabled.query_order_check) {
172
- this.check_query_order()
173
+ if (this.function_enabled.query_order_check) {
174
+ for (let exchange in Exchanges) {
175
+ if (this.function_enabled.query_order_check_exchange[exchange]) {
176
+ this.check_query_order(exchange)
177
+ }
178
+ }
173
179
  }
174
- if (this.enabled.rates_check) {
180
+ if (this.function_enabled.rates_check) {
175
181
  this.check_rates()
176
182
  }
177
- if (this.enabled.market_history_check) {
183
+ if (this.function_enabled.market_history_check) {
178
184
  this.check_market_history()
179
185
  }
180
- if (this.enabled.ohlcv_check) {
186
+ if (this.function_enabled.ohlcv_check) {
181
187
  this.check_ohlcv()
182
188
  }
183
- if (this.enabled.cmc_rates_check) {
189
+ if (this.function_enabled.cmc_rates_check) {
184
190
  this.check_cmc_rates(this.cmc_curs, 'curs')
185
191
  }
186
- if (this.enabled.balances_check && this.enabled.open_orders_check && this.enabled.trades_check) {
192
+ if (this.function_enabled.balances_check && this.function_enabled.open_orders_check && this.function_enabled.trades_check) {
187
193
  setInterval(() => {
188
194
  this.process_trades(this.trades)
189
195
  this.process_open_orders(this.open_orders)
190
196
  }, PROCESS_INTERVAL)
191
197
  }
192
- if (this.enabled.query_order_check) {
198
+ if (this.function_enabled.query_order_check) {
193
199
  setInterval(() => {
194
200
  this.process_query_order(this.query_order)
195
201
  }, PROCESS_INTERVAL)
@@ -243,7 +249,24 @@ module.exports = class Orders {
243
249
  }
244
250
  }, NO_CALLBACK_TIMEOUT)
245
251
  let limit_trade = (cb) => {
246
- if (limiter_on) {
252
+ if (this.Exchanges[exchange].exchange_type === 'dex') {
253
+ let rates_with_routes = this.rates_with_routes[exchange][pair]
254
+ let routes
255
+ if (method === 'buy') {
256
+ for (let ask of rates_with_routes.asks) {
257
+ if (ask[0] === price) {
258
+ routes = [ask[2]]
259
+ }
260
+ }
261
+ } else {
262
+ for (let bid of rates_with_routes.bids) {
263
+ if (bid[0] === price) {
264
+ routes = [bid[2]]
265
+ }
266
+ }
267
+ }
268
+ this.Exchanges[exchange].limit_trade_with_routes(pair, method, price, amount, routes, cb)
269
+ } else if (limiter_on) {
247
270
  this.Exchanges[exchange].limit_trade(pair, method, price, amount, cb)
248
271
  } else {
249
272
  this.Exchanges[exchange].limit_trade_base(pair, method, price, amount, cb)
@@ -290,15 +313,6 @@ module.exports = class Orders {
290
313
  clearTimeout(no_callback_timeout)
291
314
  })
292
315
  }
293
- market_trade(exchange, pair, method, amount, id = uuid()) {
294
- if (!this.rates[exchange][pair]) {
295
- this.info_log('%s %s rates do not exist', exchange, pair)
296
- return
297
- }
298
- let input_array = method === 'sell' ? this.rates[exchange][pair].bids : this.rates[exchange][pair].asks
299
- let { price } = utils.vol_position(input_array, amount)
300
- this.limit_trade(exchange, pair, method, price, amount, id)
301
- }
302
316
  cancel_order(exchange, pair, order) {
303
317
  let original_status = order.status
304
318
  this.update_order_info(
@@ -1060,7 +1074,7 @@ module.exports = class Orders {
1060
1074
  }
1061
1075
  get_trades_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
1062
1076
  }
1063
- check_query_order() {
1077
+ check_query_order(exchange) {
1064
1078
  // const QUERY_ORDER_TIME_IN_MS = 30 * 60 * 1000
1065
1079
  const QUERY_ORDER_TIME_IN_MS = 0
1066
1080
  let query_order_handler = (exchange, pair, res) => {
@@ -1106,11 +1120,9 @@ module.exports = class Orders {
1106
1120
  }
1107
1121
  }
1108
1122
  }
1109
- for (let exchange in Exchanges) {
1110
- if (Exchanges[exchange].query_order) {
1111
- for (let pair of exchange_pairs[exchange]) {
1112
- query_order(exchange, pair)
1113
- }
1123
+ if (Exchanges[exchange].query_order) {
1124
+ for (let pair of exchange_pairs[exchange]) {
1125
+ query_order(exchange, pair)
1114
1126
  }
1115
1127
  }
1116
1128
  }
@@ -1207,9 +1219,15 @@ module.exports = class Orders {
1207
1219
  }
1208
1220
  let rates_handler = (exchange, pair, res) => {
1209
1221
  if (res.success) {
1210
- res.body.asks = res.body.asks.slice(0, RATES_LENGTH_MAX)
1211
- res.body.bids = res.body.bids.slice(0, RATES_LENGTH_MAX)
1212
- _.set(this.rates, [exchange, pair], Object.assign(res.body, { update_time: new Date() }))
1222
+ let { asks, bids } = res.body
1223
+ if (this.Exchanges[exchange].exchange_type === 'dex') {
1224
+ _.set(this.rates_with_routes, [exchange, pair], { asks, bids, update_time: new Date() })
1225
+ asks = asks.map((ask) => ask.slice(0, 2))
1226
+ bids = bids.map((bid) => bid.slice(0, 2))
1227
+ }
1228
+ asks = asks.slice(0, RATES_LENGTH_MAX)
1229
+ bids = bids.slice(0, RATES_LENGTH_MAX)
1230
+ _.set(this.rates, [exchange, pair], { asks, bids, update_time: new Date() })
1213
1231
  // console.log(exchange, pair)
1214
1232
  process_rates()
1215
1233
  } else if (_.get(this.rates, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].rates) {
@@ -1232,7 +1250,7 @@ module.exports = class Orders {
1232
1250
  }
1233
1251
  }
1234
1252
  }, interval_dict[exchange].rates)
1235
- } else {
1253
+ } else if (Exchanges[exchange].exchange_type === 'spot') {
1236
1254
  for (let pair of exchange_pairs[exchange]) {
1237
1255
  setInterval(() => {
1238
1256
  Exchanges[exchange].rate(pair, RATES_LENGTH_DEFAULT, (res) => {
@@ -1240,6 +1258,14 @@ module.exports = class Orders {
1240
1258
  })
1241
1259
  }, interval_dict[exchange].rates)
1242
1260
  }
1261
+ } else if (Exchanges[exchange].exchange_type === 'dex') {
1262
+ for (let pair of exchange_pairs[exchange]) {
1263
+ setInterval(() => {
1264
+ Exchanges[exchange].rate_with_routes(pair, (res) => {
1265
+ rates_handler(exchange, pair, res)
1266
+ })
1267
+ }, interval_dict[exchange].rates)
1268
+ }
1243
1269
  }
1244
1270
  }
1245
1271
  for (let exchange in ExchangesRatesOnly) {
@@ -1294,7 +1320,7 @@ module.exports = class Orders {
1294
1320
  }
1295
1321
  }
1296
1322
  }, interval_dict[exchange].market_history)
1297
- } else {
1323
+ } else if (Exchanges[exchange].market_history) {
1298
1324
  for (let pair of exchange_pairs[exchange]) {
1299
1325
  setInterval(() => {
1300
1326
  Exchanges[exchange].market_history(pair, market_history_timeframe, (res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.9.167",
3
+ "version": "1.9.169",
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.116",
21
- "@icgio/icg-exchanges-data": "^1.6.60",
20
+ "@icgio/icg-exchanges": "^1.27.117",
21
+ "@icgio/icg-exchanges-data": "^1.6.61",
22
22
  "@icgio/icg-utils": "^1.7.37",
23
23
  "influx": "^5.7.0",
24
24
  "lodash": "^4.17.20",
@@ -1,69 +0,0 @@
1
- // const _ = require('lodash')
2
-
3
- // const WebSocket = require('ws')
4
-
5
- // const Orders = require('./orders.js')
6
-
7
- // const wss = new WebSocket.Server({ port: 1688 })
8
-
9
- // let orders
10
-
11
- // wss.on('connection', (ws) => {
12
- // ws.send_json = (json) => {
13
- // ws.send(JSON.stringify(json))
14
- // }
15
- // ws.on('message', (message) => {
16
- // try {
17
- // message = JSON.parse(message)
18
- // } catch (error) {
19
- // ws.send_json('parse message error: %j', error)
20
- // }
21
- // if (message.action && message.action === 'new') {
22
- // let { exchange_basecur_curs, cd, settings } = message.params
23
- // if (!exchange_basecur_curs || !cd || !settings) {
24
- // ws.send_json('exchange_basecur_curs or cd or settings do not exist: %s %s %s', exchange_basecur_curs, cd, settings)
25
- // return
26
- // }
27
- // orders = new Orders(exchange_basecur_curs, cd, settings)
28
- // } else if (!orders) {
29
- // ws.send_json('need to create an Orders object first')
30
- // } else if (message.action && message.action === 'limit-trade') {
31
- // let { exchange, pair, method, price, amount } = message.params
32
- // if (!exchange || !pair || !method || !price || !amount) {
33
- // ws.send_json('limit trade params (exchange, pair, method, price, amount) required')
34
- // return
35
- // }
36
- // orders.limit_trade(exchange, pair, method, price, amount)
37
- // } else if (message.action && message.action === 'limit-trade-all') {
38
- // let { pair, method, price, amount } = message.params
39
- // if (!pair || !method || !price || !amount) {
40
- // ws.send_json('limit trade all params (pair, method, price, amount) required')
41
- // return
42
- // }
43
- // orders.limit_trade_all(pair, method, price, amount)
44
- // } else if (message.action && message.action === 'market-trade') {
45
- // let { exchange, pair, method, amount } = message.params
46
- // if (!exchange || !pair || !method || !amount) {
47
- // ws.send_json('market trade params (exchange, pair, method, amount) required')
48
- // return
49
- // }
50
- // orders.market_trade(exchange, pair, method, amount)
51
- // } else if (message.action && message.action === 'market-trade-all') {
52
- // let { pair, method, amount } = message.params
53
- // if (!pair || !method || !amount) {
54
- // ws.send_json('limit trade all params (pair, method, amount) required')
55
- // return
56
- // }
57
- // orders.market_trade_all(pair, method, amount)
58
- // } else if (message.action && message.action === 'cancel-order') {
59
- // let { exchange, order } = message.params
60
- // if (!exchange || !order) {
61
- // ws.send_json('cancel order params (exchange, order) required')
62
- // return
63
- // }
64
- // orders.cancel_order(exchange, order)
65
- // } else if (message.action && message.action === 'get-order-info-all') {
66
- // ws.send_json(orders.get_order_info_all())
67
- // }
68
- // })
69
- // })