@icgio/icg-exchanges-wrapper 1.9.166 → 1.9.168
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 +1 -2
- package/index.js +0 -1
- package/middleware/orders.js +45 -17
- package/package.json +3 -3
- package/middleware/websocket.js +0 -69
package/.prettierignore
CHANGED
package/index.js
CHANGED
package/middleware/orders.js
CHANGED
|
@@ -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 = {}
|
|
@@ -243,7 +244,24 @@ module.exports = class Orders {
|
|
|
243
244
|
}
|
|
244
245
|
}, NO_CALLBACK_TIMEOUT)
|
|
245
246
|
let limit_trade = (cb) => {
|
|
246
|
-
if (
|
|
247
|
+
if (this.Exchanges[exchange].exchange_type === 'dex') {
|
|
248
|
+
let rates_with_routes = this.rates_with_routes[exchange][pair]
|
|
249
|
+
let routes
|
|
250
|
+
if (method === 'buy') {
|
|
251
|
+
for (let ask of rates_with_routes.asks) {
|
|
252
|
+
if (ask[0] === price) {
|
|
253
|
+
routes = [ask[2]]
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
for (let bid of rates_with_routes.bids) {
|
|
258
|
+
if (bid[0] === price) {
|
|
259
|
+
routes = [bid[2]]
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
this.Exchanges[exchange].limit_trade_with_routes(pair, method, price, amount, routes, cb)
|
|
264
|
+
} else if (limiter_on) {
|
|
247
265
|
this.Exchanges[exchange].limit_trade(pair, method, price, amount, cb)
|
|
248
266
|
} else {
|
|
249
267
|
this.Exchanges[exchange].limit_trade_base(pair, method, price, amount, cb)
|
|
@@ -290,15 +308,6 @@ module.exports = class Orders {
|
|
|
290
308
|
clearTimeout(no_callback_timeout)
|
|
291
309
|
})
|
|
292
310
|
}
|
|
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
311
|
cancel_order(exchange, pair, order) {
|
|
303
312
|
let original_status = order.status
|
|
304
313
|
this.update_order_info(
|
|
@@ -1207,9 +1216,15 @@ module.exports = class Orders {
|
|
|
1207
1216
|
}
|
|
1208
1217
|
let rates_handler = (exchange, pair, res) => {
|
|
1209
1218
|
if (res.success) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1219
|
+
let { asks, bids } = res.body
|
|
1220
|
+
if (this.Exchanges[exchange].exchange_type === 'dex') {
|
|
1221
|
+
_.set(this.rates_with_routes, [exchange, pair], { asks, bids, update_time: new Date() })
|
|
1222
|
+
asks = asks.map((ask) => ask.slice(0, 2))
|
|
1223
|
+
bids = bids.map((bid) => bid.slice(0, 2))
|
|
1224
|
+
}
|
|
1225
|
+
asks = asks.slice(0, RATES_LENGTH_MAX)
|
|
1226
|
+
bids = bids.slice(0, RATES_LENGTH_MAX)
|
|
1227
|
+
_.set(this.rates, [exchange, pair], { asks, bids, update_time: new Date() })
|
|
1213
1228
|
// console.log(exchange, pair)
|
|
1214
1229
|
process_rates()
|
|
1215
1230
|
} else if (_.get(this.rates, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].rates) {
|
|
@@ -1232,7 +1247,7 @@ module.exports = class Orders {
|
|
|
1232
1247
|
}
|
|
1233
1248
|
}
|
|
1234
1249
|
}, interval_dict[exchange].rates)
|
|
1235
|
-
} else {
|
|
1250
|
+
} else if (Exchanges[exchange].exchange_type === 'spot') {
|
|
1236
1251
|
for (let pair of exchange_pairs[exchange]) {
|
|
1237
1252
|
setInterval(() => {
|
|
1238
1253
|
Exchanges[exchange].rate(pair, RATES_LENGTH_DEFAULT, (res) => {
|
|
@@ -1240,6 +1255,14 @@ module.exports = class Orders {
|
|
|
1240
1255
|
})
|
|
1241
1256
|
}, interval_dict[exchange].rates)
|
|
1242
1257
|
}
|
|
1258
|
+
} else if (Exchanges[exchange].exchange_type === 'dex') {
|
|
1259
|
+
for (let pair of exchange_pairs[exchange]) {
|
|
1260
|
+
setInterval(() => {
|
|
1261
|
+
Exchanges[exchange].rate_with_routes(pair, (res) => {
|
|
1262
|
+
rates_handler(exchange, pair, res)
|
|
1263
|
+
})
|
|
1264
|
+
}, interval_dict[exchange].rates)
|
|
1265
|
+
}
|
|
1243
1266
|
}
|
|
1244
1267
|
}
|
|
1245
1268
|
for (let exchange in ExchangesRatesOnly) {
|
|
@@ -1294,7 +1317,7 @@ module.exports = class Orders {
|
|
|
1294
1317
|
}
|
|
1295
1318
|
}
|
|
1296
1319
|
}, interval_dict[exchange].market_history)
|
|
1297
|
-
} else {
|
|
1320
|
+
} else if (Exchanges[exchange].market_history) {
|
|
1298
1321
|
for (let pair of exchange_pairs[exchange]) {
|
|
1299
1322
|
setInterval(() => {
|
|
1300
1323
|
Exchanges[exchange].market_history(pair, market_history_timeframe, (res) => {
|
|
@@ -1308,15 +1331,20 @@ module.exports = class Orders {
|
|
|
1308
1331
|
get_market_history(this.Exchanges, this.exchange_pairs, this.interval_dict)
|
|
1309
1332
|
}
|
|
1310
1333
|
check_ohlcv() {
|
|
1334
|
+
const OHLCV_DEFAULT_PAST_HOURS = 24
|
|
1311
1335
|
let ohlcv_handler = (exchange, pair, res) => {
|
|
1312
1336
|
if (res.success) {
|
|
1313
|
-
|
|
1337
|
+
if (res.body.length < OHLCV_DEFAULT_PAST_HOURS) {
|
|
1338
|
+
console.error('ohlcv length should be:', OHLCV_DEFAULT_PAST_HOURS, exchange, pair, res.body.length)
|
|
1339
|
+
this.ohlcv[exchange] = _.omit(this.ohlcv[exchange], [pair])
|
|
1340
|
+
} else {
|
|
1341
|
+
_.set(this.ohlcv, [exchange, pair], { data: res.body, update_time: new Date() })
|
|
1342
|
+
}
|
|
1314
1343
|
} else if (_.get(this.ohlcv, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].ohlcv) {
|
|
1315
1344
|
this.info_log('%s %s ohlcv expired: %j', exchange, pair, res)
|
|
1316
1345
|
this.ohlcv[exchange] = _.omit(this.ohlcv[exchange], [pair])
|
|
1317
1346
|
}
|
|
1318
1347
|
}
|
|
1319
|
-
const OHLCV_DEFAULT_PAST_HOURS = 24
|
|
1320
1348
|
let get_ohlcv = (Exchanges, exchange_pairs, interval_dict) => {
|
|
1321
1349
|
for (let exchange in Exchanges) {
|
|
1322
1350
|
for (let pair of exchange_pairs[exchange]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.168",
|
|
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.
|
|
21
|
-
"@icgio/icg-exchanges-data": "^1.6.
|
|
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",
|
package/middleware/websocket.js
DELETED
|
@@ -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
|
-
// })
|