@icgio/icg-exchanges-wrapper 1.9.39 → 1.9.41
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/middleware/account.js +20 -1
- package/middleware/orders.js +31 -29
- package/package.json +3 -3
package/middleware/account.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
|
|
3
|
-
const constants = require('@icgio/icg-utils')
|
|
3
|
+
const { constants, utils } = require('@icgio/icg-utils')
|
|
4
4
|
|
|
5
5
|
const { USDCNY, USDKRW, USDTHB } = constants.forex_rate
|
|
6
6
|
|
|
@@ -19,6 +19,25 @@ module.exports = class Account {
|
|
|
19
19
|
this.exchange_assets_benchmark = _.cloneDeep(this.initial_exchange_assets_benchmark)
|
|
20
20
|
this.assets_benchmark = _.cloneDeep(this.initial_assets_benchmark)
|
|
21
21
|
}
|
|
22
|
+
get_depth (rates, cmc_rates, percentages) {
|
|
23
|
+
let depth = {}
|
|
24
|
+
for (let exchange in rates) {
|
|
25
|
+
for (let pair in rates[exchange]) {
|
|
26
|
+
let [cur, base_cur] = utils.parse_pair(pair)
|
|
27
|
+
let { asks, bids } = rates[exchange][pair]
|
|
28
|
+
let mid = (asks[0][0] + bids[0][0]) / 2
|
|
29
|
+
for (let percentage of percentages) {
|
|
30
|
+
let ask_depth = utils.price_position(asks, mid * (1 + percentage)).sum
|
|
31
|
+
let bid_depth = utils.price_position(bids, mid / (1 + percentage)).sum
|
|
32
|
+
let ask_depth_in_usd = ask_depth * _.get(cmc_rates, [base_cur, 'USD'], 0)
|
|
33
|
+
let bid_depth_in_usd = bid_depth * _.get(cmc_rates, [base_cur, 'USD'], 0)
|
|
34
|
+
_.set(depth, [exchange, pair, 'ask', percentage], '$' + ask_depth_in_usd.toFixed(2))
|
|
35
|
+
_.set(depth, [exchange, pair, 'bid', percentage], '$' + bid_depth_in_usd.toFixed(2))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return depth
|
|
40
|
+
}
|
|
22
41
|
set_exchange_assets_from_balances (balances) {
|
|
23
42
|
for (let exchange in balances) {
|
|
24
43
|
for (let cur in balances[exchange].total) {
|
package/middleware/orders.js
CHANGED
|
@@ -11,32 +11,35 @@ const { round_price, round_amount } = require('@icgio/icg-exchanges-data')
|
|
|
11
11
|
|
|
12
12
|
const Account = require('./account.js')
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const STANDARD_LIMITS = {
|
|
15
15
|
public_max_concurrent: 10,
|
|
16
16
|
public_interval_concurrent: 1000,
|
|
17
17
|
private_max_concurrent: 5,
|
|
18
18
|
private_interval_concurrent: 1000
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const MEDIUM_LIMITS = {
|
|
21
21
|
public_max_concurrent: 7,
|
|
22
22
|
public_interval_concurrent: 1000,
|
|
23
23
|
private_max_concurrent: 4,
|
|
24
24
|
private_interval_concurrent: 1000
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const SMALL_LIMITS = {
|
|
27
27
|
public_max_concurrent: 5,
|
|
28
28
|
public_interval_concurrent: 1000,
|
|
29
29
|
private_max_concurrent: 3,
|
|
30
30
|
private_interval_concurrent: 1000
|
|
31
31
|
}
|
|
32
|
-
const
|
|
32
|
+
const MINIMUM_LIMITS = {
|
|
33
33
|
public_max_concurrent: 2,
|
|
34
34
|
public_interval_concurrent: 1000,
|
|
35
35
|
private_max_concurrent: 1,
|
|
36
36
|
private_interval_concurrent: 3000
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const RATES_LENGTH_MAX = 100
|
|
40
|
+
const RATES_LENGTH_DEFAULT = 50
|
|
41
|
+
const MARKET_HISTORY_DEFAULT_TIME = 10 * 60 * 1000
|
|
42
|
+
const TRADES_DEFAULT_TIME = 12 * 60 * 60 * 1000
|
|
40
43
|
|
|
41
44
|
module.exports = class Orders {
|
|
42
45
|
constructor (exchange_basecur_curs, cd, settings) {
|
|
@@ -71,21 +74,21 @@ module.exports = class Orders {
|
|
|
71
74
|
this.cmc_curs = settings.cmc_curs || []
|
|
72
75
|
for (let exchange in exchange_pairs) {
|
|
73
76
|
if (exchange === 'bitfinex') {
|
|
74
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(
|
|
77
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(SMALL_LIMITS, cd[exchange]))
|
|
75
78
|
} else if (exchange === 'gate' || exchange === 'gatev4') {
|
|
76
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(
|
|
79
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(MEDIUM_LIMITS, cd[exchange]))
|
|
77
80
|
} else if (exchange === 'okex') {
|
|
78
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(
|
|
81
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(SMALL_LIMITS, cd[exchange]))
|
|
79
82
|
} else if (exchange === 'poloniex') {
|
|
80
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(
|
|
83
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(MINIMUM_LIMITS, cd[exchange]))
|
|
81
84
|
} else if (exchange === 'bitforex' || exchange === 'bitkub' || exchange === 'coinbene') {
|
|
82
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(
|
|
85
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(MINIMUM_LIMITS, cd[exchange]))
|
|
83
86
|
} else if (cd[exchange]['api_keys'] || exchange === 'kucoin') {
|
|
84
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(
|
|
87
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(SMALL_LIMITS, cd[exchange]))
|
|
85
88
|
} else if (cd[exchange]['api_keys']) {
|
|
86
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(
|
|
89
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(STANDARD_LIMITS, cd[exchange]))
|
|
87
90
|
} else {
|
|
88
|
-
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(
|
|
91
|
+
this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(STANDARD_LIMITS, cd[exchange]))
|
|
89
92
|
}
|
|
90
93
|
if (!this.interval_dict || !this.interval_dict[exchange]) {
|
|
91
94
|
this.interval_dict[exchange] = {
|
|
@@ -153,7 +156,7 @@ module.exports = class Orders {
|
|
|
153
156
|
this.check_volumes()
|
|
154
157
|
}
|
|
155
158
|
if (this.enabled.cmc_rates_check) {
|
|
156
|
-
this.check_cmc_rates(this.cmc_curs)
|
|
159
|
+
this.check_cmc_rates(this.cmc_curs, 'curs')
|
|
157
160
|
}
|
|
158
161
|
if (this.enabled.balances_check && this.enabled.open_orders_check && this.enabled.trades_check) {
|
|
159
162
|
setInterval(() => {
|
|
@@ -734,7 +737,6 @@ module.exports = class Orders {
|
|
|
734
737
|
get_open_orders_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
|
|
735
738
|
}
|
|
736
739
|
check_trades () {
|
|
737
|
-
const trades_timeframe = 12 * 60 * 60 * 1000
|
|
738
740
|
let trades_handler = (exchange, pair, res) => {
|
|
739
741
|
if (res.success) {
|
|
740
742
|
_.set(this.trades, [exchange, pair], { trades: res.body, update_time: new Date() })
|
|
@@ -773,7 +775,7 @@ module.exports = class Orders {
|
|
|
773
775
|
let get_all_trades_ws = (exchange) => {
|
|
774
776
|
if (Exchanges[exchange].ws_status().trading === 'n-opened')
|
|
775
777
|
Exchanges[exchange].ws_account()
|
|
776
|
-
Exchanges[exchange].get_all_trades_ws(
|
|
778
|
+
Exchanges[exchange].get_all_trades_ws(TRADES_DEFAULT_TIME, (res) => {
|
|
777
779
|
all_trades_handler(exchange, res)
|
|
778
780
|
setTimeout(() => {
|
|
779
781
|
get_all_trades_ws(exchange)
|
|
@@ -781,7 +783,7 @@ module.exports = class Orders {
|
|
|
781
783
|
})
|
|
782
784
|
}
|
|
783
785
|
let get_trades_ws = (exchange, pair) => {
|
|
784
|
-
Exchanges[exchange].get_trades_ws(pair,
|
|
786
|
+
Exchanges[exchange].get_trades_ws(pair, TRADES_DEFAULT_TIME, (res) => {
|
|
785
787
|
trades_handler(exchange, pair, res)
|
|
786
788
|
setTimeout(() => {
|
|
787
789
|
get_trades_ws(exchange, pair)
|
|
@@ -789,7 +791,7 @@ module.exports = class Orders {
|
|
|
789
791
|
})
|
|
790
792
|
}
|
|
791
793
|
let get_all_trades = (exchange) => {
|
|
792
|
-
Exchanges[exchange].get_all_trades(
|
|
794
|
+
Exchanges[exchange].get_all_trades(TRADES_DEFAULT_TIME, (res) => {
|
|
793
795
|
all_trades_handler(exchange, res)
|
|
794
796
|
setTimeout(() => {
|
|
795
797
|
get_all_trades(exchange)
|
|
@@ -797,7 +799,7 @@ module.exports = class Orders {
|
|
|
797
799
|
})
|
|
798
800
|
}
|
|
799
801
|
let get_trades = (exchange, pair) => {
|
|
800
|
-
Exchanges[exchange].get_trades(pair,
|
|
802
|
+
Exchanges[exchange].get_trades(pair, TRADES_DEFAULT_TIME, (res) => {
|
|
801
803
|
trades_handler(exchange, pair, res)
|
|
802
804
|
setTimeout(() => {
|
|
803
805
|
get_trades(exchange, pair)
|
|
@@ -812,7 +814,7 @@ module.exports = class Orders {
|
|
|
812
814
|
let order_number = _.keys(order_info['sell']).length + _.keys(order_info['buy']).length, count = 0, result = []
|
|
813
815
|
for (let type in order_info) {
|
|
814
816
|
for (let order_id in order_info[type]) {
|
|
815
|
-
Exchanges[exchange].get_trades_id(pair, order_id,
|
|
817
|
+
Exchanges[exchange].get_trades_id(pair, order_id, TRADES_DEFAULT_TIME, (res) => {
|
|
816
818
|
count++
|
|
817
819
|
if (res.success) {
|
|
818
820
|
result = res.body.concat(result)
|
|
@@ -859,8 +861,8 @@ module.exports = class Orders {
|
|
|
859
861
|
check_rates () {
|
|
860
862
|
let rates_handler = (exchange, pair, res) => {
|
|
861
863
|
if (res.success) {
|
|
862
|
-
res.body.asks = res.body.asks.slice(0,
|
|
863
|
-
res.body.bids = res.body.bids.slice(0,
|
|
864
|
+
res.body.asks = res.body.asks.slice(0, RATES_LENGTH_MAX)
|
|
865
|
+
res.body.bids = res.body.bids.slice(0, RATES_LENGTH_MAX)
|
|
864
866
|
_.set(this.rates, [exchange, pair], Object.assign(res.body, { update_time: new Date() }))
|
|
865
867
|
for (let pair in this.pair_exchanges) {
|
|
866
868
|
let orderbook_all = {}, orderbook_all_with_buy_sell_limits = {},
|
|
@@ -959,7 +961,7 @@ module.exports = class Orders {
|
|
|
959
961
|
} else {
|
|
960
962
|
for (let pair of exchange_pairs[exchange]) {
|
|
961
963
|
setInterval(() => {
|
|
962
|
-
Exchanges[exchange].rate(pair,
|
|
964
|
+
Exchanges[exchange].rate(pair, RATES_LENGTH_DEFAULT, (res) => { rates_handler(exchange, pair, res) })
|
|
963
965
|
}, interval_dict[exchange].rates)
|
|
964
966
|
}
|
|
965
967
|
}
|
|
@@ -978,7 +980,7 @@ module.exports = class Orders {
|
|
|
978
980
|
}
|
|
979
981
|
let get_market_history = (Exchanges, exchange_pairs, interval_dict) => {
|
|
980
982
|
for (let exchange in Exchanges) {
|
|
981
|
-
const market_history_timeframe = (exchange === 'coinbene') ? 30 * 24 * 60 * 60 * 1000 :
|
|
983
|
+
const market_history_timeframe = (exchange === 'coinbene') ? 30 * 24 * 60 * 60 * 1000 : MARKET_HISTORY_DEFAULT_TIME
|
|
982
984
|
if (Exchanges[exchange].ws_market) {
|
|
983
985
|
setInterval(() => {
|
|
984
986
|
if (!this.ws_market_first_time[exchange]) {
|
|
@@ -1022,15 +1024,15 @@ module.exports = class Orders {
|
|
|
1022
1024
|
check_volumes_base()
|
|
1023
1025
|
}, 15 * 60 * 1000)
|
|
1024
1026
|
}
|
|
1025
|
-
check_cmc_rates (
|
|
1026
|
-
let check_cmc_rates_base = (
|
|
1027
|
+
check_cmc_rates (data, type) {
|
|
1028
|
+
let check_cmc_rates_base = (data) => {
|
|
1027
1029
|
get_coinmarketcap_rates(rates => {
|
|
1028
1030
|
this.cmc_rates = rates
|
|
1029
|
-
},
|
|
1031
|
+
}, data, type)
|
|
1030
1032
|
}
|
|
1031
|
-
check_cmc_rates_base(
|
|
1033
|
+
check_cmc_rates_base(data, type)
|
|
1032
1034
|
setInterval(() => {
|
|
1033
|
-
check_cmc_rates_base(
|
|
1035
|
+
check_cmc_rates_base(data, type)
|
|
1034
1036
|
}, 15 * 60 * 1000)
|
|
1035
1037
|
}
|
|
1036
1038
|
}
|
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.41",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@icgio/icg-exchanges": "^1.27.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.27.26",
|
|
21
21
|
"@icgio/icg-exchanges-data": "^1.6.18",
|
|
22
|
-
"@icgio/icg-utils": "^1.7.
|
|
22
|
+
"@icgio/icg-utils": "^1.7.9",
|
|
23
23
|
"influx": "^5.7.0",
|
|
24
24
|
"lodash": "^4.17.20",
|
|
25
25
|
"needle": "^2.6.0",
|