cns 0.8.7 → 0.8.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3630eeaca7e56e765e2702bc46c885b19c9e5127239f6788ce510358d3b2d7e
4
- data.tar.gz: b2b87a278f6042d604d964f1c2bdd8d20db4b7a7d8d3c9448f36afbc2e2d8a08
3
+ metadata.gz: d136cac1b44b857085a4a5a3f2225edcc54f3f377c1eb5034583f2401b5c1a87
4
+ data.tar.gz: 34b8884a1f2f23ce546f3ca2d49b8ef66d67682ebd5cf3b1f0074c070129945d
5
5
  SHA512:
6
- metadata.gz: ec9c373225a2870fa14bc4eeefde9c20f6a2152a173108ce14e0f6b4bf948c7784b85337c3b0dc2f94ebaae005313c9145849805eff161f6bff094538ba942eb
7
- data.tar.gz: ebd9ed2c6d303bd6e6ba9fd533b9d9198dd8751ebe2f86c81e4b8dfcae4e5b8e632310e45a322b9dd1ed7f78a1bda4efb0a4127fc953710b133f2248b009722c
6
+ metadata.gz: bd0594653343221c13ab4e73f0635934754b2cdddba8e09c38ed144a15b925af6226df340eb6a0256c20698f3c2c7add741f084cbd2f43fd5665b73004984e0c
7
+ data.tar.gz: bb9aa97dad83b36a9d621bf8c66c5505719e01e42f531ed29f499cd44b0249f744b3b3a44c7356d907d6ab9a30383270c9686e8ddb5eeb8157b0e34bc04133dc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.8.7)
4
+ cns (0.8.8)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
data/lib/cns/bigquery.rb CHANGED
@@ -7,6 +7,7 @@ require('bigdecimal/util')
7
7
  module Cns
8
8
  BD = 'hernanirvaz.coins'
9
9
  FO = File.expand_path("~/#{File.basename($PROGRAM_NAME)}.log")
10
+ EM = %i[EOS XETH ZEUR btc eth]
10
11
  TB = {
11
12
  i: %w[blocknumber timestamp txhash axfrom axto iax value contractaddress input type gas gasused traceid iserror errcode dias],
12
13
  p: %w[blocknumber timestamp blockreward iax dias],
@@ -256,7 +257,7 @@ module Cns
256
257
  end
257
258
 
258
259
  def fts(value)
259
- "DATETIME(TIMESTAMP('#{value}'))"
260
+ "DATETIME(TIMESTAMP('#{value.iso8601}'))"
260
261
  end
261
262
 
262
263
  # @param [Hash] htx transacao norml etherscan
@@ -303,7 +304,7 @@ module Cns
303
304
  fnm(htx[:gasUsed]),
304
305
  fqt(htx[:traceId]),
305
306
  fin(htx[:isError]),
306
- fin(htx[:errCode]),
307
+ fqt(htx[:errCode]),
307
308
  fin(ops.dig(:h, htx[:hash]))
308
309
  ]
309
310
  "(#{vls.join(',')})"
@@ -325,7 +326,7 @@ module Cns
325
326
  fqt(htx[:address]),
326
327
  fnm(htx[:amount]),
327
328
  fin(htx[:blockNumber]),
328
- fin(htx[:timestamp]),
329
+ fin(htx[:timeStamp]),
329
330
  fin(ops.dig(:h, htx[:withdrawalIndex]))
330
331
  ]
331
332
  "(#{vls.join(',')})"
@@ -362,23 +363,23 @@ module Cns
362
363
  # @param [Hash] hlx ledger greymass
363
364
  # @return [String] valores formatados para insert eos (parte1)
364
365
  def neost_val(htx)
365
- act = htx[:action_trace][:act]
366
- dat = act[:data]
367
- qtd = dat[:quantity].to_s
368
- str = dat[:memo].inspect
366
+ # act = htx[:action_trace][:act]
367
+ # dat = act[:data]
368
+ # qtd = dat[:quantity].to_s
369
+ # str = dat[:memo].inspect
369
370
  vls = [
370
371
  fin(htx[:global_action_seq]),
371
372
  fin(htx[:account_action_seq]),
372
373
  fin(htx[:block_num]),
373
374
  fts(htx[:block_time]),
374
- fqt(act[:account]),
375
- fqt(act[:name]),
376
- fqt(dat[:from]),
377
- fqt(dat[:to]),
375
+ fqt(htx[:account]),
376
+ fqt(htx[:name]),
377
+ fqt(htx[:from]),
378
+ fqt(htx[:to]),
378
379
  fqt(htx[:iax]),
379
- fnm(qtd),
380
- fqt(qtd[/[[:upper:]]+/]),
381
- fqt(str),
380
+ fnm(htx[:quantity]),
381
+ fqt(htx[:moe]),
382
+ fqt(htx[:memo]),
382
383
  fin(ops.dig(:h, htx[:itx]))
383
384
  ]
384
385
  "(#{vls.join(',')})"
@@ -403,15 +404,13 @@ module Cns
403
404
  # @param [Hash] hlx ledger (deposits + withdrawals) bitcoinde
404
405
  # @return [String] valores formatados del (ledger)
405
406
  def cdel_val(htx)
406
- tip = htx[:tp]
407
- qtd = htx[:qt]
408
407
  vls = [
409
408
  fin(htx[:txid]),
410
- fts(htx[:time].iso8601),
411
- fqt(tip),
409
+ fts(htx[:time]),
410
+ fqt(htx[:tp]),
412
411
  fqt(htx[:add]),
413
412
  fqt(htx[:moe]),
414
- fnm(tip == 'withdrawal' ? "-#{qtd}" : "#{qtd}"),
413
+ fnm(htx[:tp] == 'withdrawal' ? "-#{htx[:qt]}" : "#{htx[:qt]}"),
415
414
  fnm(htx[:fee])
416
415
  ]
417
416
  "(#{vls.join(',')})"
@@ -421,12 +420,13 @@ module Cns
421
420
  # @param [Hash] htx trade kraken
422
421
  # @return [String] valores formatados ust (trades parte1)
423
422
  def cust_val(idx, htx)
423
+ # gets ledgers related to this trade
424
424
  ldg = apius.exd[:kl].select { |_, obj| obj[:refid] == idx.to_s }.keys.join(',')
425
425
  vls = [
426
426
  fqt(idx),
427
427
  fqt(htx[:ordertxid]),
428
428
  fqt(htx[:pair]),
429
- ftm(htx[:time]),
429
+ fts(htx[:time]),
430
430
  fqt(htx[:type]),
431
431
  fqt(htx[:ordertype]),
432
432
  fnm(htx[:price]),
@@ -445,7 +445,7 @@ module Cns
445
445
  # @param [Hash] hlx ledger kraken
446
446
  # @return [String] valores formatados usl (ledger)
447
447
  def cusl_val(idx, hlx)
448
- vls = [fqt(idx), fqt(hlx[:refid]), ftm(hlx[:time]), fqt(hlx[:type]), fqt(hlx[:aclass]), fqt(hlx[:asset]), fnm(hlx[:amount]), fnm(hlx[:fee])]
448
+ vls = [fqt(idx), fqt(hlx[:refid]), fts(hlx[:time]), fqt(hlx[:type]), fqt(hlx[:aclass]), fqt(hlx[:asset]), fnm(hlx[:amount]), fnm(hlx[:fee])]
449
449
  "(#{vls.join(',')})"
450
450
  end
451
451
  end
data/lib/cns/bitcoinde.rb CHANGED
@@ -38,7 +38,7 @@ module Cns
38
38
  # @return [String] texto saldos & transacoes & ajuste dias
39
39
  def mresumo
40
40
  puts("\nBITCOINDE\ntipo bitcoinde bigquery")
41
- exd[:sl].sort { |ant, prx| ant <=> prx }.each { |key, val| puts(formata_saldos(key, val)) }
41
+ exd[:sl].sort.each { |key, val| puts(formata_saldos(key, val)) }
42
42
  mtotais
43
43
 
44
44
  mtrades
@@ -50,7 +50,7 @@ module Cns
50
50
 
51
51
  # @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
52
52
  def exd
53
- @exd ||= { sl: api.account_de, tt: api.trades_de, tl: api.deposits_de + api.withdrawals_de }
53
+ @exd ||= { sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de) }
54
54
  end
55
55
 
56
56
  # @return [Array<String>] lista txid dos trades novos
@@ -67,8 +67,8 @@ module Cns
67
67
  # @param [Hash] hsx saldo bitcoinde da moeda
68
68
  # @return [String] texto formatado saldos
69
69
  def formata_saldos(moe, hsx)
70
- vbq = bqd[:sl][moe.downcase.to_sym].to_d.round(9)
71
- vex = hsx[:total_amount].to_d.round(9)
70
+ vbq = bqd[:sl][moe.downcase.to_sym].to_d
71
+ vex = hsx[:total_amount]
72
72
  format(
73
73
  '%<mo>-5.5s %<ex>21.9f %<bq>21.9f %<ok>3.3s',
74
74
  mo: moe.upcase,
@@ -84,12 +84,12 @@ module Cns
84
84
  format(
85
85
  '%<ky>-6.6s %<dt>19.19s %<dp>10.10s %<ty>-5.5s %<mo>-8.8s %<vl>18.8f %<co>8.2f',
86
86
  ky: htx[:trade_id],
87
- dt: Time.parse(htx[:successfully_finished_at]),
88
- dp: Time.parse(htx[:trade_marked_as_paid_at]),
87
+ dt: htx[:successfully_finished_at].strftime('%F %T'),
88
+ dp: htx[:trade_marked_as_paid_at].strftime('%F'),
89
89
  ty: htx[:type],
90
- mo: htx[:trading_pair].upcase,
91
- vl: htx[:amount_currency_to_trade].to_d,
92
- co: htx[:volume_currency_to_pay].to_d
90
+ mo: htx[:trading_pair],
91
+ vl: htx[:amount_currency_to_trade],
92
+ co: htx[:volume_currency_to_pay]
93
93
  )
94
94
  end
95
95
 
@@ -99,11 +99,11 @@ module Cns
99
99
  format(
100
100
  '%<ky>6i %<dt>19.19s %<ty>-10.10s %<mo>-3.3s %<pr>19.8f %<vl>18.8f',
101
101
  ky: hlx[:txid],
102
- dt: hlx[:time],
102
+ dt: hlx[:time].strftime('%F %T'),
103
103
  ty: hlx[:tp],
104
- mo: hlx[:moe].upcase,
105
- pr: hlx[:qt].to_d,
106
- vl: hlx[:fee].to_d
104
+ mo: hlx[:moe],
105
+ pr: hlx[:qt],
106
+ vl: hlx[:fee]
107
107
  )
108
108
  end
109
109
 
@@ -123,7 +123,7 @@ module Cns
123
123
  return unless ops[:v] && !novcdet.empty?
124
124
 
125
125
  puts("\ntrades data hora dt criacao tipo par qtd eur")
126
- novcdet.sort { |ant, prx| Time.parse(prx[:successfully_finished_at]) <=> Time.parse(ant[:successfully_finished_at]) }.each { |obj| puts(formata_trades(obj)) }
126
+ novcdet.sort_by { |itm| -itm[:srx] }.each { |obj| puts(formata_trades(obj)) }
127
127
  end
128
128
 
129
129
  # @return [String] texto transacoes ledger
@@ -131,7 +131,38 @@ module Cns
131
131
  return unless ops[:v] && !novcdel.empty?
132
132
 
133
133
  puts("\nledger data hora tipo moe quantidade custo")
134
- novcdel.sort { |ant, prx| prx[:time] <=> ant[:time] }.each { |obj| puts(formata_ledger(obj)) }
134
+ novcdel.sort_by { |itm| -itm[:srx] }.each { |obj| puts(formata_ledger(obj)) }
135
+ end
136
+
137
+ private
138
+
139
+ # Processa os trades para garantir que as datas estejam no formato correto
140
+ def pdea(itm)
141
+ itm.select { |ky1, _| EM.include?(ky1) }.transform_values { |o| o.merge(total_amount: o[:total_amount].to_d) }
142
+ end
143
+
144
+ # Processa os trades para garantir que as datas estejam no formato correto
145
+ def pdet(itm)
146
+ itm.map do |t|
147
+ t.merge(
148
+ successfully_finished_at: srx = ptm(t[:successfully_finished_at]),
149
+ srx: Integer(srx),
150
+ trade_marked_as_paid_at: ptm(t[:trade_marked_as_paid_at]),
151
+ amount_currency_to_trade: t[:amount_currency_to_trade].to_d,
152
+ volume_currency_to_pay: t[:volume_currency_to_pay].to_d,
153
+ trading_pair: t[:trading_pair].upcase
154
+ )
155
+ end
156
+ end
157
+
158
+ # Processa os ledger entries para garantir que as datas estejam no formato correto
159
+ def pdel(itm)
160
+ itm.map { |t| t.merge(time: srx = ptm(t[:time]), srx: Integer(srx), qt: t[:qt].to_d, fee: t[:fee].to_d, moe: t[:moe].upcase) }
161
+ end
162
+
163
+ # Processa time field somtimes is string
164
+ def ptm(itm)
165
+ itm.is_a?(String) ? Time.parse(itm) : itm
135
166
  end
136
167
  end
137
168
  end
data/lib/cns/etherscan.rb CHANGED
@@ -69,32 +69,27 @@ module Cns
69
69
 
70
70
  # @return [Array<Integer>] lista indices transacoes normais novas
71
71
  def idt
72
- @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten -
73
- (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
72
+ @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
74
73
  end
75
74
 
76
75
  # @return [Array<Integer>] lista indices transacoes internas novas
77
76
  def idi
78
- @idi ||= bcd.map { |obc| obc[:ix].map { |obj| obj[:itx] } }.flatten -
79
- (ops[:t] ? [] : bqd[:ni].map { |obq| obq[:itx] })
77
+ @idi ||= bcd.map { |obc| obc[:ix].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:ni].map { |obq| obq[:itx] })
80
78
  end
81
79
 
82
80
  # @return [Array<Integer>] lista indices transacoes block novas
83
81
  def idp
84
- @idp ||= bcd.map { |obc| obc[:px].map { |obj| obj[:itx] } }.flatten -
85
- (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] })
82
+ @idp ||= bcd.map { |obc| obc[:px].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] })
86
83
  end
87
84
 
88
85
  # @return [Array<Integer>] lista indices transacoes withdrawals novas
89
86
  def idw
90
- @idw ||= bcd.map { |obc| obc[:wx].map { |obj| obj[:itx] } }.flatten -
91
- (ops[:t] ? [] : bqd[:nw].map { |obq| obq[:itx] })
87
+ @idw ||= bcd.map { |obc| obc[:wx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nw].map { |obq| obq[:itx] })
92
88
  end
93
89
 
94
90
  # @return [Array<Integer>] lista indices transacoes token novas
95
91
  def idk
96
- @idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten -
97
- (ops[:t] ? [] : bqd[:nk].map { |obq| obq[:itx] })
92
+ @idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nk].map { |obq| obq[:itx] })
98
93
  end
99
94
 
100
95
  # @example (see Apibc#account_es)
@@ -104,12 +99,12 @@ module Cns
104
99
  acc = abc[:account].downcase
105
100
  {
106
101
  ax: acc,
107
- sl: (abc[:balance].to_d / (10**18)),
108
- tx: filtrar_tx(acc, api.norml_es(acc)),
109
- ix: filtrar_tx(acc, api.inter_es(acc)),
110
- px: filtrar_px(acc, api.block_es(acc)),
111
- wx: filtrar_wx(acc, api.withw_es(acc)),
112
- kx: filtrar_tx(acc, api.token_es(acc))
102
+ sl: abc[:balance].to_d / (10**18),
103
+ tx: ftik(acc, api.norml_es(acc)),
104
+ ix: ftik(acc, api.inter_es(acc)),
105
+ px: fppp(acc, api.block_es(acc)),
106
+ wx: fwww(acc, api.withw_es(acc)),
107
+ kx: ftik(acc, api.token_es(acc))
113
108
  }
114
109
  end
115
110
 
@@ -135,56 +130,29 @@ module Cns
135
130
  }
136
131
  end
137
132
 
138
- # @param add (see Apibc#norml_es)
139
- # @param [Array<Hash>] ary lista transacoes/token events
140
- # @return [Array<Hash>] lista transacoes/token events filtrada
141
- def filtrar_tx(add, ary)
142
- # elimina transferencia from: (lax) to: (add) - esta transferencia aparece em from: (add) to: (lax)
143
- # .delete_if { |odl| add.casecmp?(odl[:to]) && lax.include?(odl[:from].downcase) }
144
- # elimina chaves irrelevantes (DL) & adiciona chave indice itx & adiciona identificador da carteira iax
145
- ary.map { |omp| omp.delete_if { |key, _| DL.include?(key) }.merge(itx: String(omp[:hash]), iax: add, srx: Integer(omp[:timeStamp])) }
146
- end
147
-
148
- # @param add (see Apibc#norml_es)
149
- # @param [Array<Hash>] ary lista blocks events
150
- # @return [Array<Hash>] lista blocks events filtrada
151
- def filtrar_px(add, ary)
152
- # adiciona chave indice itx & adiciona identificador da carteira iax
153
- ary.map { |omp| omp.merge(itx: Integer(omp[:blockNumber]), iax: add) }
154
- end
155
-
156
- # @param add (see Apibc#norml_es)
157
- # @param [Array<Hash>] ary lista blocks events
158
- # @return [Array<Hash>] lista blocks events filtrada
159
- def filtrar_wx(add, ary)
160
- # adiciona chave indice itx & adiciona identificador da carteira iax
161
- ary.map { |omp| omp.merge(itx: Integer(omp[:withdrawalIndex]), iax: add) }
162
- end
163
-
164
- # dt: Time.at(Integer(htx[:timeStamp])),
165
133
  # @return [Array<Hash>] lista ordenada transacoes normais novas
166
134
  def sortx
167
- novnetht.sort { |ant, prx| ant[:srx] <=> prx[:srx] }
135
+ novnetht.sort_by { |itm| -itm[:srx] }
168
136
  end
169
137
 
170
138
  # @return [Array<Hash>] lista ordenada transacoes internas novas
171
139
  def sorix
172
- novnethi.sort { |ant, prx| ant[:srx] <=> prx[:srx] }
140
+ novnethi.sort_by { |itm| -itm[:srx] }
173
141
  end
174
142
 
175
143
  # @return [Array<Hash>] lista ordenada transacoes block novas
176
144
  def sorpx
177
- novnethp.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
145
+ novnethp.sort_by { |itm| -itm[:itx] }
178
146
  end
179
147
 
180
148
  # @return [Array<Hash>] lista ordenada transacoes withdrawals novas
181
149
  def sorwx
182
- novnethw.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
150
+ novnethw.sort_by { |itm| -itm[:itx] }
183
151
  end
184
152
 
185
153
  # @return [Array<Hash>] lista ordenada transacoes token novas
186
154
  def sorkx
187
- novnethk.sort { |ant, prx| ant[:srx] <=> prx[:srx] }
155
+ novnethk.sort_by { |itm| -itm[:srx] }
188
156
  end
189
157
 
190
158
  # @return [String] texto carteiras & transacoes & ajuste dias
@@ -230,23 +198,12 @@ module Cns
230
198
  # @param (see formata_carteira)
231
199
  # @return [String] texto formatado valores duma carteira
232
200
  def formata_valores_simples(hjn)
233
- # id address etherscan bigquery
234
- # me-app 0x27c7f54e48956a906af2cbfbc8684b437776403d 22.377364 22.377364 OK
235
- # mm-hot 0x534029b6371dc4453dd750bc1198181f55c859fe 4.556609 4.556609 OK
236
- format(
237
- '%<v1>13.6f %<v2>13.6f %<ok>-3s',
238
- v1: hjn[:es],
239
- v2: hjn[:bs],
240
- ok: ok?(hjn) ? 'OK' : 'NOK'
241
- )
201
+ format('%<v1>13.6f %<v2>13.6f %<ok>-3s', v1: hjn[:es], v2: hjn[:bs], ok: ok?(hjn) ? 'OK' : 'NOK')
242
202
  end
243
203
 
244
204
  # @param (see formata_carteira)
245
205
  # @return [String] texto formatado valores duma carteira
246
206
  def formata_valores(hjn)
247
- # id address etherscan tn ti tb tk tw bigquery tn ti tb tk tw
248
- # me-app 0x27c..b43 22.3774 31 6 0 16 2190 22.3774 25 6 0 16 2190 OK
249
- # mm-hot 0x534..81f 4.5566 182 18 74 7 51 4.5566 33 18 74 6 51 OK
250
207
  format(
251
208
  '%<v1>11.4f %<n1>3i %<n2>2i %<n3>2i %<n4>2i %<w1>4i %<v2>11.4f %<n5>3i %<n6>2i %<n7>2i %<n8>2i %<w2>4i %<ok>-3s',
252
209
  v1: hjn[:es],
@@ -272,7 +229,6 @@ module Cns
272
229
 
273
230
  # @example ether address inicio..fim
274
231
  # 0x10f3a0cf0b534c..c033cf32e8a03586
275
- # @param add (see filtrar_tx)
276
232
  # @param [Integer] max chars a mostrar
277
233
  # @return [String] endereco formatado
278
234
  def formata_enderec1(add, max)
@@ -286,7 +242,6 @@ module Cns
286
242
 
287
243
  # @example ether address inicio..fim
288
244
  # me-app..4b437776403d
289
- # @param add (see filtrar_tx)
290
245
  # @param [Integer] max chars a mostrar
291
246
  # @return [String] endereco formatado
292
247
  def formata_enderec2(add, max)
@@ -309,8 +264,8 @@ module Cns
309
264
  hx: formata_enderec1(htx[:hash], 29),
310
265
  fr: formata_enderec2(htx[:from], 15),
311
266
  to: formata_enderec2(htx[:to], 15),
312
- dt: Time.at(Integer(htx[:timeStamp])),
313
- vl: (htx[:value].to_d / (10**18)).round(10)
267
+ dt: htx[:timeStamp].strftime('%F'),
268
+ vl: htx[:value] / (10**18)
314
269
  )
315
270
  end
316
271
 
@@ -323,8 +278,8 @@ module Cns
323
278
  hx: formata_enderec1(hkx[:hash], 23),
324
279
  fr: formata_enderec2(hkx[:from], 15),
325
280
  to: formata_enderec2(hkx[:to], 15),
326
- dt: Time.at(Integer(hkx[:timeStamp])),
327
- vl: (hkx[:value].to_d / (10**18)).round(10),
281
+ dt: hkx[:timeStamp].strftime('%F'),
282
+ vl: hkx[:value] / (10**18),
328
283
  sy: hkx[:tokenSymbol]
329
284
  )
330
285
  end
@@ -337,8 +292,8 @@ module Cns
337
292
  '%<bn>9i %<fr>-41.41s %<dt>10.10s %<vl>17.6f',
338
293
  bn: htx[:blockNumber],
339
294
  fr: formata_enderec2(htx[:iax], 41),
340
- dt: Time.at(Integer(htx[:timeStamp])),
341
- vl: (htx[:blockReward].to_d / (10**18)).round(10)
295
+ dt: htx[:timeStamp].strftime('%F'),
296
+ vl: htx[:blockReward] / (10**18)
342
297
  )
343
298
  end
344
299
 
@@ -346,13 +301,7 @@ module Cns
346
301
  # @param [Hash] htx transacao withdrawals etherscan
347
302
  # @return [String] texto formatado transacao withdrawals etherscan
348
303
  def formata_tx_withw(htx)
349
- format(
350
- '%<bn>10i %<vi>9i %<dt>10.10s %<vl>10.6f',
351
- bn: htx[:withdrawalIndex],
352
- vi: htx[:validatorIndex],
353
- dt: Time.at(Integer(htx[:timestamp])),
354
- vl: (htx[:amount].to_d / (10**9)).round(10)
355
- )
304
+ format('%<bn>10i %<vi>9i %<dt>10.10s %<vl>10.6f', bn: htx[:withdrawalIndex], vi: htx[:validatorIndex], dt: htx[:timeStamp].strftime('%F'), vl: htx[:amount] / (10**9))
356
305
  end
357
306
 
358
307
  # @return [String] texto transacoes normais
@@ -400,8 +349,31 @@ module Cns
400
349
  puts("\najuste dias transacoes normais \n-h=#{sortx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnetht.count.positive?
401
350
  puts("\najuste dias transacoes internas \n-h=#{sorix.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethi.count.positive?
402
351
  puts("\najuste dias transacoes block \n-h=#{sorpx.map { |obj| "#{obj[:blockNumber]}:0" }.join(' ')}") if novnethp.count.positive?
403
- puts("\najuste dias transacoes withdrawals\n-h=#{sorwx.map { |obj| "#{obj[:withdrawalIndex]}:0" }.join(' ')}") if novnethw.count.positive?
404
352
  puts("\najuste dias transacoes token \n-h=#{sorkx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethk.count.positive?
353
+ puts("\najuste dias transacoes withdrawals\n-h=#{sorwx.map { |obj| "#{obj[:withdrawalIndex]}:0" }.join(' ')}") if novnethw.count.positive?
354
+ end
355
+
356
+ private
357
+
358
+ # @param add (see Apibc#norml_es)
359
+ # @param [Array<Hash>] ary lista transacoes/token events
360
+ # @return [Array<Hash>] lista transacoes/token events filtrada
361
+ def ftik(add, ary)
362
+ ary.map { |o| o.merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d, srx: (tym = Integer(o[:timeStamp])), timeStamp: Time.at(tym)) }
363
+ end
364
+
365
+ # @param add (see Apibc#norml_es)
366
+ # @param [Array<Hash>] ary lista blocks events
367
+ # @return [Array<Hash>] lista blocks events filtrada
368
+ def fppp(add, ary)
369
+ ary.map { |o| o.merge(itx: Integer(o[:blockNumber]), iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(Integer(o[:timeStamp]))) }
370
+ end
371
+
372
+ # @param add (see Apibc#norml_es)
373
+ # @param [Array<Hash>] ary lista blocks events
374
+ # @return [Array<Hash>] lista blocks events filtrada
375
+ def fwww(add, ary)
376
+ ary.map { |o| o.merge(itx: Integer(o[:withdrawalIndex]), iax: add, amount: o[:amount].to_d, timeStamp: Time.at(Integer(o[:timestamp]))) }
405
377
  end
406
378
  end
407
379
  end
data/lib/cns/greymass.rb CHANGED
@@ -47,8 +47,7 @@ module Cns
47
47
 
48
48
  # @return [Array<Integer>] lista indices transacoes novas
49
49
  def idt
50
- @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten -
51
- (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
50
+ @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
52
51
  end
53
52
 
54
53
  # @example (see Apibc#account_gm)
@@ -56,11 +55,7 @@ module Cns
56
55
  # @return [Hash] dados greymass - address, saldo & transacoes
57
56
  def base_bc(wbq)
58
57
  xbq = wbq[:ax]
59
- {
60
- ax: xbq,
61
- sl: greymass_sl(xbq).reduce(:+),
62
- tx: filtrar_tx(xbq, api.ledger_gm(xbq))
63
- }
58
+ { ax: xbq, sl: peosa(xbq).reduce(:+), tx: pesot(xbq, api.ledger_gm(xbq)) }
64
59
  end
65
60
 
66
61
  # @param wbq (see base_bc)
@@ -78,26 +73,6 @@ module Cns
78
73
  }
79
74
  end
80
75
 
81
- # @param (see filtrar_tx)
82
- # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
83
- def greymass_sl(add)
84
- hac = api.account_gm(add)
85
- htr = hac[:total_resources]
86
- [hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
87
- end
88
-
89
- # @param add (see Apibc#account_gm)
90
- # @param [Array<Hash>] ary lista transacoes
91
- # @return [Array<Hash>] lista transacoes filtrada
92
- def filtrar_tx(add, ary)
93
- # elimina transferencia from: (lax) to: (add) - esta transferencia aparece em from: (add) to: (lax)
94
- # adiciona chave indice itx & adiciona identificador da carteira iax
95
- (ary.delete_if do |odl|
96
- adt = odl[:action_trace][:act][:data]
97
- adt[:to] == add && lax.include?(adt[:from])
98
- end).map { |omp| omp.merge(itx: omp[:global_action_seq], iax: add) }
99
- end
100
-
101
76
  # @return [String] texto carteiras & transacoes & ajuste dias
102
77
  def mresumo
103
78
  return unless dados.count.positive?
@@ -134,13 +109,13 @@ module Cns
134
109
  def formata_ledger(hlx)
135
110
  format(
136
111
  '%<bn>12i %<fr>-12.12s %<to>-12.12s %<ac>-10.10s %<dt>10.10s %<vl>12.4f %<sy>-6.6s',
137
- ac: (act = hlx[:action_trace][:act])[:name],
138
- fr: (adt = act[:data])[:from],
139
- vl: (aqt = adt[:quantity].to_s).to_d,
112
+ ac: hlx[:name],
113
+ fr: hlx[:from],
114
+ vl: hlx[:quantity],
140
115
  bn: hlx[:itx],
141
- to: adt[:to],
142
- dt: Date.parse(hlx[:block_time]),
143
- sy: aqt[/[[:upper:]]+/]
116
+ to: hlx[:to],
117
+ dt: hlx[:block_time].strftime('%F'),
118
+ sy: hlx[:moe]
144
119
  )
145
120
  end
146
121
 
@@ -149,14 +124,48 @@ module Cns
149
124
  return unless ops[:v] && novneost.count.positive?
150
125
 
151
126
  puts("\nsequence num from to accao data valor moeda")
152
- novneost.sort { |ant, prx| prx[:itx] <=> ant[:itx] }.each { |obj| puts(formata_ledger(obj)) }
127
+ soreost.each { |obj| puts(formata_ledger(obj)) }
153
128
  end
154
129
 
155
130
  # @return [String] texto configuracao ajuste dias das transacoes
156
131
  def mconfiguracao_ajuste_dias
157
132
  return unless novneost.count.positive?
158
133
 
159
- puts("\nstring ajuste dias\n-h=#{novneost.sort { |ant, prx| prx[:itx] <=> ant[:itx] }.map { |obj| "#{obj[:itx]}:0" }.join(' ')}")
134
+ puts("\nstring ajuste dias\n-h=#{soreost.map { |obj| "#{obj[:itx]}:0" }.join(' ')}")
135
+ end
136
+
137
+ private
138
+
139
+ # @return [Array<Hash>] lista ordenada transacoes
140
+ def soreost
141
+ novneost.sort_by { |itm| -itm[:itx] }
142
+ end
143
+
144
+ # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
145
+ def peosa(add)
146
+ hac = api.account_gm(add)
147
+ htr = hac[:total_resources]
148
+ [hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
149
+ end
150
+
151
+ # @param add (see Apibc#account_gm)
152
+ # @param [Array<Hash>] ary lista transacoes
153
+ # @return [Array<Hash>] lista transacoes filtrada
154
+ def pesot(add, ary)
155
+ ary.map do |omp|
156
+ omp.merge(
157
+ name: (act = omp[:action_trace][:act])[:name],
158
+ from: (adt = act[:data])[:from],
159
+ quantity: (qtd = adt[:quantity].to_s).to_d,
160
+ account: act[:account],
161
+ to: adt[:to],
162
+ memo: String(adt[:memo]).gsub(/\p{C}/, ''), # remove Non-Printable Characters
163
+ moe: qtd[/[[:upper:]]+/],
164
+ itx: omp[:global_action_seq],
165
+ iax: add,
166
+ block_time: Time.parse(omp[:block_time])
167
+ )
168
+ end
160
169
  end
161
170
  end
162
171
  end
data/lib/cns/kraken.rb CHANGED
@@ -38,7 +38,7 @@ module Cns
38
38
  # @return [String] texto saldos & transacoes & ajuste dias
39
39
  def mresumo
40
40
  puts("\nKRAKEN\ntipo kraken bigquery")
41
- exd[:sl].sort { |ant, prx| ant <=> prx }.each { |key, val| puts(formata_saldos(key, val)) }
41
+ exd[:sl].sort.each { |key, val| puts(formata_saldos(key, val)) }
42
42
  mtotais
43
43
 
44
44
  mtrades
@@ -50,7 +50,7 @@ module Cns
50
50
 
51
51
  # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
52
52
  def exd
53
- @exd ||= { sl: api.account_us, kt: api.trades_us, kl: api.ledger_us }
53
+ @exd ||= { sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us) }
54
54
  end
55
55
 
56
56
  # @return [Array<String>] lista txid dos trades novos
@@ -68,14 +68,13 @@ module Cns
68
68
  # @param [BigDecimal] sal saldo kraken da moeda
69
69
  # @return [String] texto formatado saldos
70
70
  def formata_saldos(moe, sal)
71
- vbq = bqd[:sl][moe.downcase.to_sym].to_d.round(9)
72
- vsl = sal.to_d.round(9)
71
+ vbq = bqd[:sl][moe.downcase.to_sym].to_d
73
72
  format(
74
73
  '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
75
74
  mo: moe.upcase,
76
- kr: vsl,
75
+ kr: sal,
77
76
  bq: vbq,
78
- ok: vbq == vsl ? 'OK' : 'NOK'
77
+ ok: vbq == sal ? 'OK' : 'NOK'
79
78
  )
80
79
  end
81
80
 
@@ -86,12 +85,12 @@ module Cns
86
85
  format(
87
86
  '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-8.8s %<pr>8.2f %<vl>10.4f %<co>13.2f',
88
87
  ky: idx,
89
- dt: Time.at(htx[:time]),
88
+ dt: htx[:time].strftime('%F %T'),
90
89
  ty: "#{htx[:type]}/#{htx[:ordertype]}",
91
- mo: htx[:pair].upcase,
92
- pr: htx[:price].to_d,
93
- vl: htx[:vol].to_d,
94
- co: htx[:cost].to_d
90
+ mo: htx[:pair],
91
+ pr: htx[:price],
92
+ vl: htx[:vol],
93
+ co: htx[:cost]
95
94
  )
96
95
  end
97
96
 
@@ -102,11 +101,11 @@ module Cns
102
101
  format(
103
102
  '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-4.4s %<pr>18.7f %<vl>18.7f',
104
103
  ky: idx,
105
- dt: Time.at(hlx[:time]),
104
+ dt: hlx[:time].strftime('%F %T'),
106
105
  ty: hlx[:type],
107
- mo: hlx[:asset].upcase,
108
- pr: hlx[:amount].to_d,
109
- vl: hlx[:fee].to_d
106
+ mo: hlx[:asset],
107
+ pr: hlx[:amount],
108
+ vl: hlx[:fee]
110
109
  )
111
110
  end
112
111
 
@@ -126,7 +125,7 @@ module Cns
126
125
  return unless ops[:v] && novcust.count.positive?
127
126
 
128
127
  puts("\ntrade data hora tipo par preco volume custo")
129
- novcust.sort { |ant, prx| prx[1][:time] <=> ant[1][:time] }.each { |key, val| puts(formata_trades(key, val)) }
128
+ novcust.sort_by { |itm| -itm[1][:srx] }.each { |key, val| puts(formata_trades(key, val)) }
130
129
  end
131
130
 
132
131
  # @return [String] texto transacoes ledger
@@ -134,7 +133,24 @@ module Cns
134
133
  return unless ops[:v] && novcusl.count.positive?
135
134
 
136
135
  puts("\nledger data hora tipo moeda quantidade custo")
137
- novcusl.sort { |ant, prx| prx[1][:time] <=> ant[1][:time] }.each { |key, val| puts(formata_ledger(key, val)) }
136
+ novcusl.sort_by { |itm| -itm[1][:srx] }.each { |key, val| puts(formata_ledger(key, val)) }
137
+ end
138
+
139
+ private
140
+
141
+ # Processa os trades para garantir que as datas estejam no formato correto
142
+ def pusa(itm)
143
+ itm.select { |key, _| EM.include?(key) }.transform_values { |val| val.to_d }
144
+ end
145
+
146
+ # Processa os trades para garantir que as datas estejam no formato correto
147
+ def pust(itm)
148
+ itm.transform_values { |t| t.merge(srx: (tym = Integer(t[:time])), time: Time.at(tym), pair: t[:pair].upcase, price: t[:price].to_d, vol: t[:vol].to_d, cost: t[:cost].to_d) }
149
+ end
150
+
151
+ # Processa os ledger entries para garantir que as datas estejam no formato correto
152
+ def pusl(itm)
153
+ itm.transform_values { |t| t.merge(srx: (tym = Integer(t[:time])), time: Time.at(tym), asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
138
154
  end
139
155
  end
140
156
  end
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '0.8.7'
4
+ VERSION = '0.8.8'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-24 00:00:00.000000000 Z
10
+ date: 2025-02-25 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler