@icgio/icg-exchanges-wrapper 1.9.99 → 1.9.101
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/orders.js +53 -40
- package/package.json +2 -2
package/middleware/orders.js
CHANGED
|
@@ -61,7 +61,7 @@ module.exports = class Orders {
|
|
|
61
61
|
this.no_cancel_range_exchanges = settings.no_cancel_range_exchanges || []
|
|
62
62
|
this.no_trades_function_exchanges = settings.no_trades_function_exchanges || []
|
|
63
63
|
this.no_trades_function_f_filled_timeout = 30 * 1000
|
|
64
|
-
this.
|
|
64
|
+
this.no_arb_exchanges = settings.no_arb_exchanges || []
|
|
65
65
|
this.buy_sell_limits_threshold = 0.95
|
|
66
66
|
this.p_filled_threshold = 0
|
|
67
67
|
this.f_filled_threshold = 0.99
|
|
@@ -69,7 +69,8 @@ module.exports = class Orders {
|
|
|
69
69
|
this.previous_orders_canceled_exchange_pair = {}
|
|
70
70
|
this.account_init = false
|
|
71
71
|
this.cmc_curs = settings.cmc_curs || []
|
|
72
|
-
this.
|
|
72
|
+
this.balance_benchmark = settings.balance_benchmark || {}
|
|
73
|
+
this.min_reserve_balance = settings.min_reserve_balance || {}
|
|
73
74
|
for (let exchange in exchange_pairs) {
|
|
74
75
|
let api_key_temp = cd[exchange]['api_keys'] || cd[exchange]['api_key'],
|
|
75
76
|
secret_key_temp = cd[exchange]['secret_keys'] || cd[exchange]['secret_key'],
|
|
@@ -103,8 +104,11 @@ module.exports = class Orders {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
;(this.balances = {}), (this.open_orders = {}), (this.trades = {}), (this.rates = {}), (this.market_history = {}), (this.cmc_rates = {})
|
|
106
|
-
;(this.rates_combined_all = {}),
|
|
107
|
-
|
|
107
|
+
;(this.rates_combined_all = {}),
|
|
108
|
+
(this.rates_combined_all_with_buy_sell_limits_against_reserve_balance = {}),
|
|
109
|
+
(this.rates_combined_major = {}),
|
|
110
|
+
(this.rates_combined_good_with_buy_sell_limits_against_reserve_balance = {})
|
|
111
|
+
this.buy_sell_limits_against_reserve_balance = {}
|
|
108
112
|
this.order_info = {}
|
|
109
113
|
this.order_info_status = {}
|
|
110
114
|
this.enabled = settings.enabled || {
|
|
@@ -584,6 +588,12 @@ module.exports = class Orders {
|
|
|
584
588
|
_.setWith(this.order_info, `${exchange}.${pair}.${type}.${order_id}.${key}`, dict[key], Object)
|
|
585
589
|
}
|
|
586
590
|
this.info_log('UPDATE %s: %s %s %s %s %j', note, exchange, pair, type, order_id, dict)
|
|
591
|
+
// start: log every f-filled trade for future analysis
|
|
592
|
+
if (dict.status === 'F-FILLED') {
|
|
593
|
+
let { price, amount, close_time } = _.get(this.order_info, [exchange, pair, type, order_id])
|
|
594
|
+
console.log(`f_filled_orders_info:${exchange},${pair},${type},${order_id},${price},${amount},${close_time},${note}`)
|
|
595
|
+
}
|
|
596
|
+
// end: log every f-filled trade for future analysis
|
|
587
597
|
}
|
|
588
598
|
delete_order_info(exchange, pair, type, order_id, note) {
|
|
589
599
|
this.order_info[exchange][pair][type] = _.omit(this.order_info[exchange][pair][type], [order_id])
|
|
@@ -599,21 +609,33 @@ module.exports = class Orders {
|
|
|
599
609
|
let cur_balance = _.get(this.balances, [exchange, 'available', cur], 0)
|
|
600
610
|
let base_cur_balance = _.get(this.balances, [exchange, 'available', base_cur], 0)
|
|
601
611
|
let pair = cur + base_cur
|
|
602
|
-
_.
|
|
603
|
-
|
|
604
|
-
|
|
612
|
+
let max_cur_amount = cur_balance - _.get(this.min_reserve_balance, [exchange, cur], 0)
|
|
613
|
+
let max_base_cur_amount = base_cur_balance - _.get(this.min_reserve_balance, [exchange, base_cur], 0)
|
|
614
|
+
if (max_cur_amount > 0 || cur_balance === 0) {
|
|
615
|
+
} else {
|
|
616
|
+
console.error('balance low', exchange, cur, cur_balance, this.min_reserve_balance[exchange][cur])
|
|
617
|
+
max_cur_amount = 0
|
|
618
|
+
}
|
|
619
|
+
if (max_base_cur_amount > 0 || base_cur_balance === 0) {
|
|
620
|
+
} else {
|
|
621
|
+
console.error('balance low', exchange, cur, base_cur_balance, this.min_reserve_balance[exchange][base_cur])
|
|
622
|
+
max_base_cur_amount = 0
|
|
623
|
+
}
|
|
624
|
+
_.set(this.buy_sell_limits_against_reserve_balance, [exchange, pair], {
|
|
625
|
+
sell: max_cur_amount,
|
|
626
|
+
buy: max_base_cur_amount,
|
|
605
627
|
})
|
|
606
628
|
})
|
|
607
629
|
}
|
|
608
630
|
}
|
|
609
631
|
if (!this.account_init && _.keys(this.balances).length === _.keys(this.exchange_pairs).length) {
|
|
610
632
|
this.account_init = true
|
|
611
|
-
this.init_account(this.balances, this.
|
|
633
|
+
this.init_account(this.balances, this.balance_benchmark)
|
|
612
634
|
}
|
|
613
635
|
} else if (_.get(this.balances, [exchange, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].balances) {
|
|
614
636
|
this.info_log('%s balances expired: %j', exchange, res)
|
|
615
637
|
this.balances = _.omit(this.balances, [exchange])
|
|
616
|
-
this.
|
|
638
|
+
this.buy_sell_limits_against_reserve_balance = _.omit(this.buy_sell_limits_against_reserve_balance, [exchange])
|
|
617
639
|
}
|
|
618
640
|
}
|
|
619
641
|
function get_balances(Exchanges, interval_dict) {
|
|
@@ -641,18 +663,9 @@ module.exports = class Orders {
|
|
|
641
663
|
let position_all_handler = (exchange, res) => {
|
|
642
664
|
if (res.success) {
|
|
643
665
|
_.set(this.positions, [exchange], Object.assign(res.body, { update_time: new Date() }))
|
|
644
|
-
for (let exchange in this.exchange_pairs) {
|
|
645
|
-
this.exchange_pairs[exchange].map((pair) => {
|
|
646
|
-
_.set(this.buy_sell_limits, [exchange, pair], {
|
|
647
|
-
sell: 1000 + _.get(res.body, ['total', pair], 0),
|
|
648
|
-
buy: 1000 - _.get(res.body, ['total', pair], 0),
|
|
649
|
-
})
|
|
650
|
-
})
|
|
651
|
-
}
|
|
652
666
|
} else if (_.get(this.positions, [exchange, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].positions) {
|
|
653
667
|
this.info_log('%s positions expired: %j', exchange, res)
|
|
654
668
|
this.positions = _.omit(this.positions, [exchange])
|
|
655
|
-
this.buy_sell_limits = _.omit(this.buy_sell_limits, [exchange])
|
|
656
669
|
}
|
|
657
670
|
}
|
|
658
671
|
function get_positions(Exchanges, interval_dict) {
|
|
@@ -965,10 +978,10 @@ module.exports = class Orders {
|
|
|
965
978
|
_.set(this.rates, [exchange, pair], Object.assign(res.body, { update_time: new Date() }))
|
|
966
979
|
for (let pair in this.pair_exchanges) {
|
|
967
980
|
let orderbook_all = {},
|
|
968
|
-
|
|
981
|
+
orderbook_all_with_buy_sell_limits_against_reserve_balance = {},
|
|
969
982
|
orderbook_major = {},
|
|
970
983
|
orderbook_major_temp = {},
|
|
971
|
-
|
|
984
|
+
orderbook_good_with_buy_sell_limits_against_reserve_balance = {},
|
|
972
985
|
orderbook_good_temp = {}
|
|
973
986
|
for (let exchange of this.pair_exchanges[pair]) {
|
|
974
987
|
if (_.get(this.rates, [exchange, pair, 'asks'], []).length > 0 && _.get(this.rates, [exchange, pair, 'bids'], []).length > 0) {
|
|
@@ -980,32 +993,32 @@ module.exports = class Orders {
|
|
|
980
993
|
if (
|
|
981
994
|
_.get(this.rates, [exchange, pair, 'asks'], []).length > 0 &&
|
|
982
995
|
_.get(this.rates, [exchange, pair, 'bids'], []).length > 0 &&
|
|
983
|
-
_.get(this.
|
|
984
|
-
_.get(this.
|
|
996
|
+
_.get(this.buy_sell_limits_against_reserve_balance, [exchange, pair, 'buy']) &&
|
|
997
|
+
_.get(this.buy_sell_limits_against_reserve_balance, [exchange, pair, 'sell'])
|
|
985
998
|
) {
|
|
986
999
|
let rates = JSON.parse(JSON.stringify(this.rates[exchange][pair]))
|
|
987
|
-
let
|
|
988
|
-
asks: utils.sum_position_orderbook(rates.asks, this.
|
|
989
|
-
bids: utils.vol_position_orderbook(rates.bids, this.
|
|
1000
|
+
let rates_with_buy_sell_limits_against_reserve_balance = {
|
|
1001
|
+
asks: utils.sum_position_orderbook(rates.asks, this.buy_sell_limits_against_reserve_balance[exchange][pair].buy),
|
|
1002
|
+
bids: utils.vol_position_orderbook(rates.bids, this.buy_sell_limits_against_reserve_balance[exchange][pair].sell),
|
|
990
1003
|
}
|
|
991
|
-
|
|
1004
|
+
orderbook_all_with_buy_sell_limits_against_reserve_balance[exchange] = rates_with_buy_sell_limits_against_reserve_balance
|
|
992
1005
|
if (this.major_exchanges[pair] && _.includes(this.major_exchanges[pair], exchange)) {
|
|
993
1006
|
orderbook_major_temp[exchange] = rates
|
|
994
1007
|
if (_.keys(orderbook_major_temp).length === this.major_exchanges[pair].length) {
|
|
995
1008
|
orderbook_major = orderbook_major_temp
|
|
996
1009
|
}
|
|
997
1010
|
}
|
|
998
|
-
if (
|
|
999
|
-
orderbook_good_temp[exchange] =
|
|
1000
|
-
if (_.keys(orderbook_good_temp).length === this.pair_exchanges[pair].length - this.
|
|
1001
|
-
|
|
1011
|
+
if (!_.includes(this.no_arb_exchanges, exchange)) {
|
|
1012
|
+
orderbook_good_temp[exchange] = rates_with_buy_sell_limits_against_reserve_balance
|
|
1013
|
+
if (_.keys(orderbook_good_temp).length === this.pair_exchanges[pair].length - this.no_arb_exchanges.length) {
|
|
1014
|
+
orderbook_good_with_buy_sell_limits_against_reserve_balance = orderbook_good_temp
|
|
1002
1015
|
}
|
|
1003
1016
|
}
|
|
1004
1017
|
} else {
|
|
1005
|
-
|
|
1018
|
+
orderbook_all_with_buy_sell_limits_against_reserve_balance = _.omit(orderbook_all_with_buy_sell_limits_against_reserve_balance, [exchange])
|
|
1006
1019
|
orderbook_major = _.omit(orderbook_major, [exchange])
|
|
1007
1020
|
orderbook_major_temp = _.omit(orderbook_major_temp, [exchange])
|
|
1008
|
-
|
|
1021
|
+
orderbook_good_with_buy_sell_limits_against_reserve_balance = _.omit(orderbook_good_with_buy_sell_limits_against_reserve_balance, [exchange])
|
|
1009
1022
|
orderbook_good_temp = _.omit(orderbook_good_temp, [exchange])
|
|
1010
1023
|
}
|
|
1011
1024
|
}
|
|
@@ -1017,12 +1030,12 @@ module.exports = class Orders {
|
|
|
1017
1030
|
this.rates_combined_all = _.omit(this.rates_combined_all, [pair])
|
|
1018
1031
|
}
|
|
1019
1032
|
}
|
|
1020
|
-
if (_.keys(
|
|
1021
|
-
let o = utils.combine_orderbooks(
|
|
1033
|
+
if (_.keys(orderbook_all_with_buy_sell_limits_against_reserve_balance).length > 0) {
|
|
1034
|
+
let o = utils.combine_orderbooks(orderbook_all_with_buy_sell_limits_against_reserve_balance, 100)
|
|
1022
1035
|
if (o.asks.length > 0 && o.bids.length > 0) {
|
|
1023
|
-
_.set(this.
|
|
1036
|
+
_.set(this.rates_combined_all_with_buy_sell_limits_against_reserve_balance, [pair], o)
|
|
1024
1037
|
} else {
|
|
1025
|
-
this.
|
|
1038
|
+
this.rates_combined_all_with_buy_sell_limits_against_reserve_balance = _.omit(this.rates_combined_all_with_buy_sell_limits_against_reserve_balance, [pair])
|
|
1026
1039
|
}
|
|
1027
1040
|
}
|
|
1028
1041
|
if (_.keys(orderbook_major).length > 0) {
|
|
@@ -1033,12 +1046,12 @@ module.exports = class Orders {
|
|
|
1033
1046
|
this.rates_combined_major = _.omit(this.rates_combined_major, [pair])
|
|
1034
1047
|
}
|
|
1035
1048
|
}
|
|
1036
|
-
if (_.keys(
|
|
1037
|
-
let o = utils.combine_orderbooks(
|
|
1049
|
+
if (_.keys(orderbook_good_with_buy_sell_limits_against_reserve_balance).length > 0) {
|
|
1050
|
+
let o = utils.combine_orderbooks(orderbook_good_with_buy_sell_limits_against_reserve_balance, 100)
|
|
1038
1051
|
if (o.asks.length > 0 && o.bids.length > 0) {
|
|
1039
|
-
_.set(this.
|
|
1052
|
+
_.set(this.rates_combined_good_with_buy_sell_limits_against_reserve_balance, [pair], o)
|
|
1040
1053
|
} else {
|
|
1041
|
-
this.
|
|
1054
|
+
this.rates_combined_good_with_buy_sell_limits_against_reserve_balance = _.omit(this.rates_combined_good_with_buy_sell_limits_against_reserve_balance, [pair])
|
|
1042
1055
|
}
|
|
1043
1056
|
}
|
|
1044
1057
|
}
|
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.101",
|
|
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.27.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.27.86",
|
|
21
21
|
"@icgio/icg-exchanges-data": "^1.6.39",
|
|
22
22
|
"@icgio/icg-utils": "^1.7.18",
|
|
23
23
|
"influx": "^5.7.0",
|