@icgio/icg-exchanges-wrapper 1.21.42 → 1.21.44
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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.44",
|
|
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.31",
|
|
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
|
-
}
|