@icgio/icg-exchanges-wrapper 1.9.81 → 1.9.83

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.
@@ -1,11 +1,20 @@
1
1
  const _ = require('lodash')
2
2
 
3
- const { constants, utils } = require('@icgio/icg-utils')
3
+ const { forex_rate, utils } = require('@icgio/icg-utils')
4
4
 
5
- const { USDCNY, USDKRW, USDTHB } = constants.forex_rate
5
+ let USDCNY, USDKRW, USDTHB
6
+ forex_rate.get_forex_rate('USDCNY', (res) => {
7
+ USDCNY = res
8
+ })
9
+ forex_rate.get_forex_rate('USDKRW', (res) => {
10
+ USDKRW = res
11
+ })
12
+ forex_rate.get_forex_rate('USDTHB', (res) => {
13
+ USDTHB = res
14
+ })
6
15
 
7
16
  module.exports = class Account {
8
- constructor (initial_balances) {
17
+ constructor(initial_balances) {
9
18
  this.initial_exchange_assets_benchmark = {}
10
19
  this.exchange_assets_benchmark = {}
11
20
  this.initial_assets_benchmark = {}
@@ -19,7 +28,7 @@ module.exports = class Account {
19
28
  this.exchange_assets_benchmark = _.cloneDeep(this.initial_exchange_assets_benchmark)
20
29
  this.assets_benchmark = _.cloneDeep(this.initial_assets_benchmark)
21
30
  }
22
- get_depth (rates, cmc_rates, percentages) {
31
+ get_depth(rates, cmc_rates, percentages) {
23
32
  let depth = {}
24
33
  for (let exchange in rates) {
25
34
  for (let pair in rates[exchange]) {
@@ -38,30 +47,29 @@ module.exports = class Account {
38
47
  }
39
48
  return depth
40
49
  }
41
- set_exchange_assets_from_balances (balances) {
50
+ set_exchange_assets_from_balances(balances) {
42
51
  for (let exchange in balances) {
43
52
  for (let cur in balances[exchange].total) {
44
53
  _.set(this.exchange_assets_benchmark, [exchange, cur], balances[exchange].total[cur])
45
54
  }
46
55
  }
47
56
  }
48
- get_exchange_position (balances, initial=true) {
57
+ get_exchange_position(balances, initial = true) {
49
58
  let exchange_assets_benchmark = initial ? this.initial_exchange_assets_benchmark : this.exchange_assets_benchmark
50
59
  let exchange_position = {}
51
60
  for (let exchange in exchange_assets_benchmark) {
52
61
  for (let cur in exchange_assets_benchmark[exchange]) {
53
- if (!_.get(balances, [exchange, 'total']))
54
- console.error('get_exchange_position error: ', exchange, balances[exchange])
62
+ if (!_.get(balances, [exchange, 'total'])) console.error('get_exchange_position error: ', exchange, balances[exchange])
55
63
  if (_.get(balances, [exchange, 'total', cur])) {
56
64
  let diff = balances[exchange].total[cur] - exchange_assets_benchmark[exchange][cur]
57
65
  _.set(exchange_position, [exchange, cur, 'amount'], diff)
58
- _.set(exchange_position, [exchange, cur, 'percentage'], (diff / exchange_assets_benchmark[exchange][cur] * 100).toPrecision(3) + '%')
66
+ _.set(exchange_position, [exchange, cur, 'percentage'], ((diff / exchange_assets_benchmark[exchange][cur]) * 100).toPrecision(3) + '%')
59
67
  }
60
68
  }
61
69
  }
62
70
  return exchange_position
63
71
  }
64
- get_position (balances, initial=true) {
72
+ get_position(balances, initial = true) {
65
73
  let exchange_position = this.get_exchange_position(balances, initial)
66
74
  let position = {}
67
75
  for (let exchange in exchange_position) {
@@ -71,17 +79,17 @@ module.exports = class Account {
71
79
  _.set(position, [cur, 'percentage'], 0)
72
80
  }
73
81
  position[cur].amount += exchange_position[exchange][cur].amount
74
- position[cur].percentage = (position[cur].amount / this.assets_benchmark[cur] * 100).toPrecision(3) + '%'
82
+ position[cur].percentage = ((position[cur].amount / this.assets_benchmark[cur]) * 100).toPrecision(3) + '%'
75
83
  }
76
84
  }
77
85
  return position
78
86
  }
79
- get_exchange_profit (balances, cmc_rates, initial=true) {
87
+ get_exchange_profit(balances, cmc_rates, initial = true) {
80
88
  let exchange_position = this.get_exchange_position(balances, initial)
81
89
  let exchange_profit = {}
82
90
  for (let exchange in exchange_position) {
83
91
  let profit = {
84
- USD: 0
92
+ USD: 0,
85
93
  }
86
94
  for (let cur in exchange_position[exchange]) {
87
95
  let position = exchange_position[exchange][cur].amount
@@ -96,7 +104,8 @@ module.exports = class Account {
96
104
  } else {
97
105
  if (!cmc_rates[cur]) {
98
106
  console.log('get_exchange_profit rates_cmc %s does not exist', cur)
99
- } else if (cmc_rates[cur].update_time < new Date().getTime() - 4 * 60 * 60 * 1000) { // some currencies like USDT are updating slow
107
+ } else if (cmc_rates[cur].update_time < new Date().getTime() - 4 * 60 * 60 * 1000) {
108
+ // some currencies like USDT are updating slow
100
109
  console.log('get_exchange_profit rates_cmc %s expired', cur)
101
110
  }
102
111
  profit.USD += position * _.get(cmc_rates, [cur, 'USD'], 0)
@@ -106,9 +115,9 @@ module.exports = class Account {
106
115
  }
107
116
  return exchange_profit
108
117
  }
109
- get_profit (balances, cmc_rates, initial=true) {
118
+ get_profit(balances, cmc_rates, initial = true) {
110
119
  let exchange_profit = this.get_exchange_profit(balances, cmc_rates, initial)
111
- let profit = {
120
+ let profit = {
112
121
  USD: 0,
113
122
  }
114
123
  for (let exchange in exchange_profit) {
@@ -116,7 +125,7 @@ module.exports = class Account {
116
125
  }
117
126
  return profit
118
127
  }
119
- get_exchange_distribution (balances, cmc_rates) {
128
+ get_exchange_distribution(balances, cmc_rates) {
120
129
  let exchange_distribution = {}
121
130
  for (let exchange in balances) {
122
131
  let total_in_USD = 0
@@ -130,9 +139,9 @@ module.exports = class Account {
130
139
  for (let cur in balances[exchange].total) {
131
140
  let percentage = 0
132
141
  if (_.includes(constants.stablecoins, cur)) {
133
- percentage = balances[exchange].total[cur] * 1 / total_in_USD
142
+ percentage = (balances[exchange].total[cur] * 1) / total_in_USD
134
143
  } else {
135
- percentage = balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0) / total_in_USD
144
+ percentage = (balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0)) / total_in_USD
136
145
  }
137
146
  if (percentage > 0.0001) {
138
147
  _.set(exchange_distribution, [exchange, cur], (percentage * 100).toPrecision(3) + '%')
@@ -141,7 +150,7 @@ module.exports = class Account {
141
150
  }
142
151
  return exchange_distribution
143
152
  }
144
- get_total_distribution (balances, cmc_rates) {
153
+ get_total_distribution(balances, cmc_rates) {
145
154
  let total_distribution = {}
146
155
  let total_in_USD = 0
147
156
  for (let exchange in balances) {
@@ -157,9 +166,9 @@ module.exports = class Account {
157
166
  for (let cur in balances[exchange].total) {
158
167
  let percentage = 0
159
168
  if (_.includes(constants.stablecoins, cur)) {
160
- percentage = balances[exchange].total[cur] * 1 / total_in_USD
169
+ percentage = (balances[exchange].total[cur] * 1) / total_in_USD
161
170
  } else {
162
- percentage = balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0) / total_in_USD
171
+ percentage = (balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0)) / total_in_USD
163
172
  }
164
173
  if (percentage > 0.0001) {
165
174
  _.set(total_distribution, [cur, exchange], (percentage * 100).toPrecision(3) + '%')
@@ -73,23 +73,19 @@ module.exports = class Orders {
73
73
  this.account_init = false
74
74
  this.cmc_curs = settings.cmc_curs || []
75
75
  for (let exchange in exchange_pairs) {
76
- if (exchange === 'bitfinex') {
77
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(SMALL_LIMITS, cd[exchange]))
78
- } else if (exchange === 'gate' || exchange === 'gatev4') {
79
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(MEDIUM_LIMITS, cd[exchange]))
80
- } else if (exchange === 'okex') {
81
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(SMALL_LIMITS, cd[exchange]))
82
- } else if (exchange === 'poloniex' || exchange === 'bkex') {
83
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(MINIMUM_LIMITS, cd[exchange]))
84
- } else if (exchange === 'bitforex' || exchange === 'bitkub' || exchange === 'coinbene') {
85
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(MINIMUM_LIMITS, cd[exchange]))
86
- } else if (cd[exchange]['api_keys'] || exchange === 'kucoin') {
87
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(SMALL_LIMITS, cd[exchange]))
88
- } else if (cd[exchange]['api_keys']) {
89
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_keys'], cd[exchange]['secret_keys'], _.assign(STANDARD_LIMITS, cd[exchange]))
76
+ let api_key_temp = cd[exchange]['api_keys'] || cd[exchange]['api_key'],
77
+ secret_key_temp = cd[exchange]['secret_keys'] || cd[exchange]['secret_key'],
78
+ LIMITS
79
+ if (_.includes(['binance', 'gate', 'gatev4'], exchange)) {
80
+ LIMITS = MEDIUM_LIMITS
81
+ } else if (_.includes(['bitfinex', 'kucoin', 'lbank', 'okex', 'phemex', 'xt'], exchange)) {
82
+ LIMITS = SMALL_LIMITS
83
+ } else if (_.includes(['bitforex', 'bitkub', 'bkex', 'coinbene', 'poloniex'], exchange)) {
84
+ LIMITS = MINIMUM_LIMITS
90
85
  } else {
91
- this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](cd[exchange]['api_key'], cd[exchange]['secret_key'], _.assign(STANDARD_LIMITS, cd[exchange]))
86
+ LIMITS = STANDARD_LIMITS
92
87
  }
88
+ this.Exchanges[exchange] = new icg_exchanges[_.upperFirst(exchange)](api_key_temp, secret_key_temp, _.assign(LIMITS, cd[exchange]))
93
89
  if (!this.interval_dict || !this.interval_dict[exchange]) {
94
90
  this.interval_dict[exchange] = {
95
91
  balances: 10 * 1000,
@@ -729,7 +725,7 @@ module.exports = class Orders {
729
725
  check_open_orders() {
730
726
  const open_orders_timeframe = 12 * 60 * 60 * 1000
731
727
  let previous_orders_processer = (exchange, pair, orders) => {
732
- if (!_.includes(this.no_cancel_previous_exchanges, exchange)) {
728
+ if (_.includes(this.no_cancel_previous_exchanges, exchange)) {
733
729
  _.set(this.previous_orders_canceled_exchange_pair, [exchange, pair], true)
734
730
  } else if (this.cancel_previous_orders && !this.previous_orders_canceled) {
735
731
  orders.map((order) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.9.81",
3
+ "version": "1.9.83",
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.67",
20
+ "@icgio/icg-exchanges": "^1.27.68",
21
21
  "@icgio/icg-exchanges-data": "^1.6.37",
22
- "@icgio/icg-utils": "^1.7.12",
22
+ "@icgio/icg-utils": "^1.7.13",
23
23
  "influx": "^5.7.0",
24
24
  "lodash": "^4.17.20",
25
25
  "needle": "^2.6.0",