@icgio/icg-exchanges-wrapper 1.21.41 → 1.21.43
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/index.js +0 -10
- package/middleware/orders.js +106 -34
- package/package.json +2 -2
- package/functions/get-exchanges-balance.js +0 -52
- package/functions/get-exchanges-deposits.js +0 -85
- package/functions/get-exchanges-open-orders.js +0 -98
- package/functions/get-exchanges-trades.js +0 -101
- package/functions/get-exchanges-withdrawals.js +0 -85
package/index.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
const { get_exchanges_rates, get_exchanges_market_history, get_exchanges_ohlcv } = require('./functions/get-exchanges-rates-market-history-ohlcv.js')
|
|
2
|
-
const get_exchanges_balance = require('./functions/get-exchanges-balance.js')
|
|
3
|
-
const get_exchanges_trades = require('./functions/get-exchanges-trades.js')
|
|
4
|
-
const get_exchanges_open_orders = require('./functions/get-exchanges-open-orders.js')
|
|
5
|
-
const get_exchanges_deposits = require('./functions/get-exchanges-deposits.js')
|
|
6
|
-
const get_exchanges_withdrawals = require('./functions/get-exchanges-withdrawals.js')
|
|
7
2
|
|
|
8
3
|
module.exports.functions = {
|
|
9
4
|
get_exchanges_rates,
|
|
10
5
|
get_exchanges_market_history,
|
|
11
6
|
get_exchanges_ohlcv,
|
|
12
|
-
get_exchanges_balance,
|
|
13
|
-
get_exchanges_trades,
|
|
14
|
-
get_exchanges_open_orders,
|
|
15
|
-
get_exchanges_deposits,
|
|
16
|
-
get_exchanges_withdrawals,
|
|
17
7
|
}
|
|
18
8
|
|
|
19
9
|
module.exports.orders = require('./middleware/orders.js')
|
package/middleware/orders.js
CHANGED
|
@@ -174,6 +174,7 @@ module.exports = class Orders {
|
|
|
174
174
|
this.f_filled_threshold = 0.999
|
|
175
175
|
this.previous_orders_canceled = false
|
|
176
176
|
this.previous_orders_canceled_exchange_pair = {}
|
|
177
|
+
this.previous_orders_cleanup = {}
|
|
177
178
|
this.account_init = false
|
|
178
179
|
this.cmc_curs = settings.cmc_curs || []
|
|
179
180
|
this.accounting_benchmark = settings.accounting_benchmark
|
|
@@ -1211,46 +1212,117 @@ module.exports = class Orders {
|
|
|
1211
1212
|
}
|
|
1212
1213
|
check_open_orders() {
|
|
1213
1214
|
const CANCEL_PREVIOUS_ORDERS_DELAY_MS = 60 * 1000
|
|
1214
|
-
let
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1215
|
+
let update_previous_orders_canceled = () => {
|
|
1216
|
+
let all_canceled = true
|
|
1217
|
+
outer: for (const exch of Object.keys(this.exchange_pairs)) {
|
|
1218
|
+
const pairs = this.exchange_pairs[exch]
|
|
1219
|
+
const exch_marks = this.previous_orders_canceled_exchange_pair[exch]
|
|
1220
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
1221
|
+
if (!exch_marks || !exch_marks[pairs[i]]) {
|
|
1222
|
+
all_canceled = false
|
|
1223
|
+
break outer
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1218
1226
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1227
|
+
if (all_canceled && !this.previous_orders_canceled) {
|
|
1228
|
+
console.log('original orders cleanup verified')
|
|
1229
|
+
}
|
|
1230
|
+
this.previous_orders_canceled = all_canceled
|
|
1231
|
+
}
|
|
1232
|
+
let complete_previous_orders_cleanup = (exchange, pair, state) => {
|
|
1233
|
+
if (state.complete) return
|
|
1234
|
+
state.complete = true
|
|
1235
|
+
_.set(this.previous_orders_canceled_exchange_pair, [exchange, pair], true)
|
|
1236
|
+
console.log('original orders cleanup verified: %s %s', exchange, pair)
|
|
1237
|
+
update_previous_orders_canceled()
|
|
1238
|
+
}
|
|
1239
|
+
let cancel_previous_orders_for_pair = (exchange, pair, state) => {
|
|
1240
|
+
if (!state.cancel_started || state.complete) return
|
|
1241
|
+
const order_ids = Array.from(state.remaining_ids).filter((order_id) => !state.in_flight_ids.has(order_id))
|
|
1242
|
+
if (order_ids.length === 0) return
|
|
1243
|
+
console.log('canceling original orders: %s %s count=%s remaining=%s', exchange, pair, order_ids.length, state.remaining_ids.size)
|
|
1244
|
+
order_ids.forEach((order_id) => {
|
|
1245
|
+
state.in_flight_ids.add(order_id)
|
|
1246
|
+
this.Exchanges[exchange].cancel_order_by_order(state.orders_by_id.get(order_id), (res) => {
|
|
1247
|
+
state.in_flight_ids.delete(order_id)
|
|
1248
|
+
if (!res || (!res.success && res.error !== 'order-not-open')) {
|
|
1249
|
+
console.error('cancel original order failed: %s %s order_id=%s %j', exchange, pair, order_id, res)
|
|
1250
|
+
}
|
|
1251
|
+
})
|
|
1252
|
+
})
|
|
1253
|
+
}
|
|
1254
|
+
let previous_orders_processer = (exchange, pair, orders) => {
|
|
1255
|
+
if (!this.previous_orders_canceled) {
|
|
1256
|
+
let state = _.get(this.previous_orders_cleanup, [exchange, pair])
|
|
1257
|
+
if (!state && _.includes(this.no_cancel_previous_exchanges, exchange)) {
|
|
1258
|
+
state = { complete: false }
|
|
1259
|
+
_.set(this.previous_orders_cleanup, [exchange, pair], state)
|
|
1260
|
+
complete_previous_orders_cleanup(exchange, pair, state)
|
|
1261
|
+
} else if (!state && this.cancel_previous_orders) {
|
|
1262
|
+
const orders_by_id = new Map()
|
|
1263
|
+
let has_malformed_orders = false
|
|
1264
|
+
orders.forEach((order) => {
|
|
1265
|
+
if (!order || order.order_id == null || order.order_id === '') {
|
|
1266
|
+
has_malformed_orders = true
|
|
1267
|
+
console.error('original order missing order_id: %s %s %j', exchange, pair, order)
|
|
1268
|
+
return
|
|
1269
|
+
}
|
|
1270
|
+
const order_id = String(order.order_id)
|
|
1271
|
+
if (!orders_by_id.has(order_id)) orders_by_id.set(order_id, _.cloneDeep(order))
|
|
1233
1272
|
})
|
|
1234
|
-
|
|
1235
|
-
|
|
1273
|
+
state = {
|
|
1274
|
+
orders_by_id,
|
|
1275
|
+
remaining_ids: new Set(orders_by_id.keys()),
|
|
1276
|
+
in_flight_ids: new Set(),
|
|
1277
|
+
unexpected_ids: new Set(),
|
|
1278
|
+
cancel_started: false,
|
|
1279
|
+
has_malformed_orders,
|
|
1280
|
+
complete: false,
|
|
1236
1281
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1282
|
+
_.set(this.previous_orders_cleanup, [exchange, pair], state)
|
|
1283
|
+
_.set(this.previous_orders_canceled_exchange_pair, [exchange, pair], false)
|
|
1284
|
+
const delay_ms = this.cancel_previous_orders_with_delay ? CANCEL_PREVIOUS_ORDERS_DELAY_MS : 0
|
|
1285
|
+
console.log('original orders captured: %s %s count=%s delay_ms=%s', exchange, pair, state.remaining_ids.size, delay_ms)
|
|
1286
|
+
if (state.remaining_ids.size === 0 && !state.has_malformed_orders) {
|
|
1287
|
+
complete_previous_orders_cleanup(exchange, pair, state)
|
|
1288
|
+
} else {
|
|
1289
|
+
const start_cancel = () => {
|
|
1290
|
+
if (state.complete || state.cancel_started) return
|
|
1291
|
+
state.cancel_started = true
|
|
1292
|
+
cancel_previous_orders_for_pair(exchange, pair, state)
|
|
1248
1293
|
}
|
|
1294
|
+
if (delay_ms > 0) setTimeout(start_cancel, delay_ms)
|
|
1295
|
+
else start_cancel()
|
|
1296
|
+
}
|
|
1297
|
+
} else if (state && !state.complete && state.remaining_ids) {
|
|
1298
|
+
const live_ids = new Set()
|
|
1299
|
+
state.has_malformed_orders = false
|
|
1300
|
+
orders.forEach((order) => {
|
|
1301
|
+
if (!order || order.order_id == null || order.order_id === '') state.has_malformed_orders = true
|
|
1302
|
+
else live_ids.add(String(order.order_id))
|
|
1303
|
+
})
|
|
1304
|
+
const unexpected_ids = new Set(Array.from(live_ids).filter((order_id) => !state.orders_by_id.has(order_id)))
|
|
1305
|
+
const unexpected_ids_changed =
|
|
1306
|
+
unexpected_ids.size !== state.unexpected_ids.size || Array.from(unexpected_ids).some((order_id) => !state.unexpected_ids.has(order_id))
|
|
1307
|
+
if (unexpected_ids.size > 0 && unexpected_ids_changed) {
|
|
1308
|
+
console.error('unexpected orders during original cleanup: %s %s count=%s order_ids=%j', exchange, pair, unexpected_ids.size, Array.from(unexpected_ids).slice(0, 10))
|
|
1309
|
+
}
|
|
1310
|
+
state.unexpected_ids = unexpected_ids
|
|
1311
|
+
const previous_remaining = state.remaining_ids.size
|
|
1312
|
+
state.remaining_ids.forEach((order_id) => {
|
|
1313
|
+
if (!live_ids.has(order_id)) {
|
|
1314
|
+
state.remaining_ids.delete(order_id)
|
|
1315
|
+
state.in_flight_ids.delete(order_id)
|
|
1316
|
+
}
|
|
1317
|
+
})
|
|
1318
|
+
if (state.remaining_ids.size !== previous_remaining) {
|
|
1319
|
+
console.log('original orders cleanup progress: %s %s remaining=%s', exchange, pair, state.remaining_ids.size)
|
|
1249
1320
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
|
|
1321
|
+
if (state.remaining_ids.size === 0 && !state.has_malformed_orders && state.unexpected_ids.size === 0) {
|
|
1322
|
+
complete_previous_orders_cleanup(exchange, pair, state)
|
|
1323
|
+
} else if (state.cancel_started) {
|
|
1324
|
+
cancel_previous_orders_for_pair(exchange, pair, state)
|
|
1252
1325
|
}
|
|
1253
|
-
this.previous_orders_canceled = all_canceled
|
|
1254
1326
|
}
|
|
1255
1327
|
}
|
|
1256
1328
|
let rate_major = _.get(this.rates_combined_major, [pair])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.43",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@icgio/icg-exchanges": "^1.45.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.45.30",
|
|
21
21
|
"@icgio/icg-utils": "^1.9.64",
|
|
22
22
|
"lodash": "^4.17.23",
|
|
23
23
|
"pg": "^8.17.2"
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
let balances = {}
|
|
3
|
-
const get_exchanges_balance = function (exchanges, cb) {
|
|
4
|
-
if (!Array.isArray(exchanges)) {
|
|
5
|
-
console.error('exchanges should be an array')
|
|
6
|
-
return
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const promises = exchanges.map((exchange) => {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
if (exchange.balance_ws) {
|
|
12
|
-
if (exchange.ws_status().trading === 'n-opened') exchange.ws_account()
|
|
13
|
-
exchange.balance_ws(function (res) {
|
|
14
|
-
if (res.success) {
|
|
15
|
-
_.set(balances, exchange.settings.id, res.body)
|
|
16
|
-
resolve()
|
|
17
|
-
} else {
|
|
18
|
-
console.error(`getting balance ws failed for ${exchange.name}:`, res)
|
|
19
|
-
delete balances[exchange.name]
|
|
20
|
-
resolve()
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
} else if (exchange.balance) {
|
|
24
|
-
exchange.balance(function (res) {
|
|
25
|
-
if (res.success) {
|
|
26
|
-
_.set(balances, exchange.settings.id, res.body)
|
|
27
|
-
resolve()
|
|
28
|
-
} else {
|
|
29
|
-
console.error(`getting balance failed for ${exchange.name}:`, res)
|
|
30
|
-
delete balances[exchange.name]
|
|
31
|
-
resolve()
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
} else {
|
|
35
|
-
resolve()
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
Promise.all(promises)
|
|
41
|
-
.then(() => {
|
|
42
|
-
cb(balances)
|
|
43
|
-
})
|
|
44
|
-
.catch((error) => {
|
|
45
|
-
console.error('Error fetching balances:', error)
|
|
46
|
-
cb({})
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = {
|
|
51
|
-
get_exchanges_balance,
|
|
52
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
const TIMEFRAME_IN_THE_PAST = 90 * 24 * 60 * 60 * 1000
|
|
3
|
-
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
-
|
|
5
|
-
let exchange_pair_deposits = {}
|
|
6
|
-
let deposits_status = {}
|
|
7
|
-
|
|
8
|
-
function get_exchanges_deposits(exchanges, client_currency, cb) {
|
|
9
|
-
if (!Array.isArray(exchanges)) {
|
|
10
|
-
console.error('exchanges should be an array')
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const promises = exchanges.map((exchange) => {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const exchange_name = exchange.Name
|
|
17
|
-
const exchange_id = exchange.settings.id
|
|
18
|
-
|
|
19
|
-
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
20
|
-
resolve()
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let deposits_fetch_promises = []
|
|
25
|
-
|
|
26
|
-
if (exchange.get_all_deposits) {
|
|
27
|
-
deposits_fetch_promises.push(
|
|
28
|
-
new Promise((resolve_pair, reject_pair) => {
|
|
29
|
-
exchange.get_all_deposits(TIMEFRAME_IN_THE_PAST, function (res) {
|
|
30
|
-
if (res.success) {
|
|
31
|
-
const deposits = JSON.parse(JSON.stringify(res.body))
|
|
32
|
-
_.set(exchange_pair_deposits, [exchange_id], deposits)
|
|
33
|
-
} else {
|
|
34
|
-
console.error(`getting all deposits failed for ${exchange_name}:`, res)
|
|
35
|
-
delete exchange_pair_deposits[exchange_id]
|
|
36
|
-
}
|
|
37
|
-
_.set(deposits_status, [exchange_name], true)
|
|
38
|
-
resolve_pair()
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
)
|
|
42
|
-
} else if (exchange.get_deposits) {
|
|
43
|
-
client_currency.forEach((pair) => {
|
|
44
|
-
deposits_fetch_promises.push(
|
|
45
|
-
new Promise((resolve_pair, reject_pair) => {
|
|
46
|
-
exchange.get_deposits(pair, TIMEFRAME_IN_THE_PAST, function (res) {
|
|
47
|
-
if (res.success) {
|
|
48
|
-
const deposits = JSON.parse(JSON.stringify(res.body))
|
|
49
|
-
_.set(exchange_pair_deposits, [exchange_id, pair], deposits)
|
|
50
|
-
} else {
|
|
51
|
-
console.error(`getting deposits failed for ${exchange_name} ${pair}:`, res)
|
|
52
|
-
delete exchange_pair_deposits[exchange_id][pair]
|
|
53
|
-
}
|
|
54
|
-
_.set(deposits_status, [exchange_name + pair], true)
|
|
55
|
-
resolve_pair()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
)
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
Promise.all(deposits_fetch_promises)
|
|
63
|
-
.then(() => {
|
|
64
|
-
resolve()
|
|
65
|
-
})
|
|
66
|
-
.catch((error) => {
|
|
67
|
-
console.error('Error fetching deposits:', error)
|
|
68
|
-
resolve()
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
Promise.all(promises)
|
|
74
|
-
.then(() => {
|
|
75
|
-
cb(exchange_pair_deposits)
|
|
76
|
-
})
|
|
77
|
-
.catch((error) => {
|
|
78
|
-
console.error('Error fetching deposits:', error)
|
|
79
|
-
cb({})
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = {
|
|
84
|
-
get_exchanges_deposits,
|
|
85
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
|
|
3
|
-
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
-
|
|
5
|
-
let exchange_pair_open_orders = {}
|
|
6
|
-
let open_orders_status = {}
|
|
7
|
-
|
|
8
|
-
const get_exchanges_open_orders = function (exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
9
|
-
if (!Array.isArray(exchanges)) {
|
|
10
|
-
console.error('exchanges should be an array')
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const promises = exchanges.map((exchange) => {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const exchange_name = exchange.Name
|
|
17
|
-
const exchange_id = exchange.settings.id
|
|
18
|
-
|
|
19
|
-
if (!exchange_pair_dict[exchange_name]) {
|
|
20
|
-
resolve()
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const pair_list = exchange_pair_dict[exchange_name]
|
|
25
|
-
|
|
26
|
-
for (let pair of pair_list) {
|
|
27
|
-
_.set(open_orders_status, [exchange_name + pair], false)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
31
|
-
resolve()
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let open_orders_fetch_promises = []
|
|
36
|
-
|
|
37
|
-
if (exchange.get_all_open_orders) {
|
|
38
|
-
open_orders_fetch_promises.push(
|
|
39
|
-
new Promise((resolvePair, rejectPair) => {
|
|
40
|
-
exchange.get_all_open_orders(function (res) {
|
|
41
|
-
if (res.success) {
|
|
42
|
-
const open_orders = res.body
|
|
43
|
-
_.set(exchange_pair_open_orders, [exchange_id], open_orders)
|
|
44
|
-
} else {
|
|
45
|
-
console.error(`getting open orders failed for ${exchange_name}:`, res)
|
|
46
|
-
delete exchange_pair_open_orders[exchange_id]
|
|
47
|
-
}
|
|
48
|
-
_.set(open_orders_status, [exchange_name], true)
|
|
49
|
-
resolvePair()
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
)
|
|
53
|
-
} else if (exchange.get_open_orders) {
|
|
54
|
-
pair_list.forEach((pair) => {
|
|
55
|
-
open_orders_fetch_promises.push(
|
|
56
|
-
new Promise((resolvePair, rejectPair) => {
|
|
57
|
-
exchange.get_open_orders(pair, function (res) {
|
|
58
|
-
if (res.success) {
|
|
59
|
-
const open_orders = res.body
|
|
60
|
-
_.set(exchange_pair_open_orders, [exchange_id, pair], open_orders)
|
|
61
|
-
} else {
|
|
62
|
-
console.error(`getting open orders failed for ${exchange_name} ${pair}:`, res)
|
|
63
|
-
if (exchange_pair_open_orders[exchange_id]) {
|
|
64
|
-
delete exchange_pair_open_orders[exchange_id][pair]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
_.set(open_orders_status, [exchange_name + pair], true)
|
|
68
|
-
resolvePair()
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
)
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
Promise.all(open_orders_fetch_promises)
|
|
76
|
-
.then(() => {
|
|
77
|
-
resolve()
|
|
78
|
-
})
|
|
79
|
-
.catch((error) => {
|
|
80
|
-
console.error('Error fetching open orders:', error)
|
|
81
|
-
resolve()
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
Promise.all(promises)
|
|
87
|
-
.then(() => {
|
|
88
|
-
cb(exchange_pair_open_orders)
|
|
89
|
-
})
|
|
90
|
-
.catch((error) => {
|
|
91
|
-
console.error('Error fetching open orders:', error)
|
|
92
|
-
cb({})
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
module.exports = {
|
|
97
|
-
get_exchanges_open_orders,
|
|
98
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
|
|
3
|
-
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
-
const TRADES_TIMEFRAME = 1000000 * 60 * 1000
|
|
5
|
-
|
|
6
|
-
let exchange_pair_trades = {}
|
|
7
|
-
let trades_status = {}
|
|
8
|
-
|
|
9
|
-
const get_exchanges_trades = function (exchanges, exchange_pair_dict, cb, ws_enabled = true) {
|
|
10
|
-
if (!Array.isArray(exchanges)) {
|
|
11
|
-
console.error('exchanges should be an array')
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const promises = exchanges.map((exchange) => {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const exchange_name = exchange.Name
|
|
18
|
-
const exchange_id = exchange.settings.id
|
|
19
|
-
|
|
20
|
-
if (!exchange_pair_dict[exchange_name]) {
|
|
21
|
-
resolve()
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const pair_list = exchange_pair_dict[exchange_name]
|
|
26
|
-
|
|
27
|
-
for (let pair of pair_list) {
|
|
28
|
-
_.set(trades_status, [exchange_name + pair], false)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
32
|
-
resolve()
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let trades_fetch_promises = []
|
|
37
|
-
|
|
38
|
-
if (exchange.get_all_trades) {
|
|
39
|
-
trades_fetch_promises.push(
|
|
40
|
-
new Promise((resolve_pair, reject_pair) => {
|
|
41
|
-
exchange.get_all_trades(pair, TRADES_TIMEFRAME, function (res) {
|
|
42
|
-
if (res.success) {
|
|
43
|
-
const trades = res.body
|
|
44
|
-
_.set(exchange_pair_trades, [exchange_id, pair], trades)
|
|
45
|
-
} else {
|
|
46
|
-
console.error(`getting all trades failed for ${exchange_name} ${pair}:`, res)
|
|
47
|
-
if (exchange_pair_trades[exchange_id]) {
|
|
48
|
-
delete exchange_pair_trades[exchange_id][pair]
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
_.set(trades_status, [exchange_name + pair], true)
|
|
52
|
-
resolve_pair()
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
)
|
|
56
|
-
} else if (exchange.get_trades) {
|
|
57
|
-
pair_list.forEach((pair) => {
|
|
58
|
-
trades_fetch_promises.push(
|
|
59
|
-
new Promise((resolve_pair, reject_pair) => {
|
|
60
|
-
exchange.get_trades(pair, TRADES_TIMEFRAME, function (res) {
|
|
61
|
-
if (res.success) {
|
|
62
|
-
const trades = res.body
|
|
63
|
-
_.set(exchange_pair_trades, [exchange_id, pair], trades)
|
|
64
|
-
} else {
|
|
65
|
-
console.error(`getting trades failed for ${exchange_name} ${pair}:`, res)
|
|
66
|
-
if (exchange_pair_trades[exchange_id]) {
|
|
67
|
-
delete exchange_pair_trades[exchange_id][pair]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
_.set(trades_status, [exchange_name + pair], true)
|
|
71
|
-
resolve_pair()
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
)
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
Promise.all(trades_fetch_promises)
|
|
79
|
-
.then(() => {
|
|
80
|
-
resolve()
|
|
81
|
-
})
|
|
82
|
-
.catch((error) => {
|
|
83
|
-
console.error('Error fetching trades:', error)
|
|
84
|
-
resolve()
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
Promise.all(promises)
|
|
90
|
-
.then(() => {
|
|
91
|
-
cb(exchange_pair_trades)
|
|
92
|
-
})
|
|
93
|
-
.catch((error) => {
|
|
94
|
-
console.error('Error fetching trades:', error)
|
|
95
|
-
cb({})
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
module.exports = {
|
|
100
|
-
get_exchanges_trades,
|
|
101
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
const TIMEFRAME_IN_THE_PAST = 90 * 24 * 60 * 60 * 1000
|
|
3
|
-
const INVALID_EXCHANGES_LIST = ['Bitforex', 'Thinkbit', 'Kkcoin']
|
|
4
|
-
|
|
5
|
-
let exchange_pair_withdrawals = {}
|
|
6
|
-
let withdrawals_status = {}
|
|
7
|
-
|
|
8
|
-
const get_exchanges_withdrawals = function (exchanges, client_currency, cb) {
|
|
9
|
-
if (!Array.isArray(exchanges)) {
|
|
10
|
-
console.error('exchanges should be an array')
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const promises = exchanges.map((exchange) => {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const exchange_name = exchange.Name
|
|
17
|
-
const exchange_id = exchange.settings.id
|
|
18
|
-
|
|
19
|
-
if (_.includes(INVALID_EXCHANGES_LIST, exchange_name)) {
|
|
20
|
-
resolve()
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let withdrawals_fetch_promises = []
|
|
25
|
-
|
|
26
|
-
if (exchange.get_all_withdrawals) {
|
|
27
|
-
withdrawals_fetch_promises.push(
|
|
28
|
-
new Promise((resolve_pair, reject_pair) => {
|
|
29
|
-
exchange.get_all_withdrawals(TIMEFRAME_IN_THE_PAST, function (res) {
|
|
30
|
-
if (res.success) {
|
|
31
|
-
const withdrawals = JSON.parse(JSON.stringify(res.body))
|
|
32
|
-
_.set(exchange_pair_withdrawals, [exchange_id], withdrawals)
|
|
33
|
-
} else {
|
|
34
|
-
console.error(`getting all withdrawals failed for ${exchange_name}:`, res)
|
|
35
|
-
delete exchange_pair_withdrawals[exchange_id]
|
|
36
|
-
}
|
|
37
|
-
_.set(withdrawals_status, [exchange_name], true)
|
|
38
|
-
resolve_pair()
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
)
|
|
42
|
-
} else if (exchange.get_withdrawals) {
|
|
43
|
-
client_currency.forEach((pair) => {
|
|
44
|
-
withdrawals_fetch_promises.push(
|
|
45
|
-
new Promise((resolve_pair, reject_pair) => {
|
|
46
|
-
exchange.get_withdrawals(pair, TIMEFRAME_IN_THE_PAST, function (res) {
|
|
47
|
-
if (res.success) {
|
|
48
|
-
const withdrawals = JSON.parse(JSON.stringify(res.body))
|
|
49
|
-
_.set(exchange_pair_withdrawals, [exchange_id, pair], withdrawals)
|
|
50
|
-
} else {
|
|
51
|
-
console.error(`getting withdrawals failed for ${exchange_name} ${pair}:`, res)
|
|
52
|
-
delete exchange_pair_withdrawals[exchange_id][pair]
|
|
53
|
-
}
|
|
54
|
-
_.set(withdrawals_status, [exchange_name + pair], true)
|
|
55
|
-
resolve_pair()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
)
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
Promise.all(withdrawals_fetch_promises)
|
|
63
|
-
.then(() => {
|
|
64
|
-
resolve()
|
|
65
|
-
})
|
|
66
|
-
.catch((error) => {
|
|
67
|
-
console.error('Error fetching withdrawals:', error)
|
|
68
|
-
resolve()
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
Promise.all(promises)
|
|
74
|
-
.then(() => {
|
|
75
|
-
cb(exchange_pair_withdrawals)
|
|
76
|
-
})
|
|
77
|
-
.catch((error) => {
|
|
78
|
-
console.error('Error fetching withdrawals:', error)
|
|
79
|
-
cb({})
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = {
|
|
84
|
-
get_exchanges_withdrawals,
|
|
85
|
-
}
|