cns 2.1.4 → 2.1.5

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: b0deb219876c5a8fd82a5338c9d7635b11356feffcdc908514be211fb0bbc909
4
- data.tar.gz: b188c18e7a9226bded29d42d0f9142280c94e9230fe7d41ff94d4776dc56222c
3
+ metadata.gz: 9d956c363cc9263bde314d61e987fd558ef04082cf6e966be8918ea5fe911d00
4
+ data.tar.gz: bfab434ac3d3a76d9340c79a75643c6ca0d295238cd13afa4dd19f9d343f4616
5
5
  SHA512:
6
- metadata.gz: 9833256521bb67118970871725a5ca3da4f5cc371a8aa3d531421238f66510a8040dd778de1a42506b6aeacda1deb581195f449cd883776951ba3b97b2d8bffc
7
- data.tar.gz: 163a57bfbdfe4ba4a6f864db5ba97266c4e1f5088e2b72543137c20bcc4810bf1799d5bbc03e76aa929c6b8984ad75a212f7756471b1c4c968ba923cb17d8a8c
6
+ metadata.gz: 4321ad66e65f2667d8ee0d894e2610fc9dbf5d7bad4848b65b679a4898dd6e41ad76440cdc4a2ae27039502e5765a05e6435c05bcb91f0f4f4e10fed12f1016b
7
+ data.tar.gz: 0a0fb3d9421299798b8563041306a0a859d45e2cb46a1cf36fdc0e0e97c63d58660a83d586c98da78014e271dbea9e8efd8f714ad75011d2b030102303571226
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (2.1.4)
4
+ cns (2.1.5)
5
5
  curb
6
6
  faraday
7
7
  faraday-retry
data/lib/cns/apibc.rb CHANGED
@@ -73,11 +73,14 @@ module Cns
73
73
 
74
74
  private
75
75
 
76
- # Calculate (and cache) the block number for N days ago
76
+ # cache block number for N days ago to avoid multiple API calls
77
+ # @param [Integer] days number of days in the past to get block number for
78
+ # @return [Integer] ethereum block number corresponding to N days ago
77
79
  def start_block(days)
78
80
  return 0 if days.nil?
79
81
  return @blks[days] if @blks.key?(days)
80
82
 
83
+ # unix timestamp para obter transacoes 24x60x60 = 86400 segundos
81
84
  res = block_req(Integer(Time.now - (days * 86_400)))
82
85
  if res[:status] == '1'
83
86
  blk = Integer(res[:result], 10)
@@ -90,7 +93,8 @@ module Cns
90
93
  0
91
94
  end
92
95
 
93
- # New dedicated method for Block API calls
96
+ # @param [Integer] timestamp unix timestamp
97
+ # @return [Hash] ethereum block number corresponding to the given timestamp
94
98
  def block_req(timestamp)
95
99
  prm = {chainid: 1, module: 'block', action: 'getblocknobytime', timestamp: timestamp, closest: 'after', apikey: @esky}
96
100
  pjsn(@escn.get('/v2/api', prm))
data/lib/cns/apice.rb CHANGED
@@ -71,19 +71,25 @@ module Cns
71
71
  end
72
72
 
73
73
  # Get trades from Kraken
74
- # @param [Integer] days optional number of days to fetch trades from (last N days)
74
+ # @param [Integer] tsp optional timestamp to fetch trades from (last N seconds)
75
75
  # @return [Hash] trades kraken
76
- def trades_us(days = nil)
77
- pag_us_req('TradesHistory', :trades, days ? {start: days} : {})
76
+ def trades_us(tsp = nil)
77
+ # last TradesHistory was 2023-06-03 (after that was discontinued by kraken)
78
+ if tsp && tsp > Integer(Time.new(2023, 6, 3))
79
+ # return empty array to avoid unnecessary API calls
80
+ []
81
+ else
82
+ pag_us_req('TradesHistory', :trades, tsp ? {start: tsp} : {})
83
+ end
78
84
  rescue Curl::Err::CurlError
79
85
  []
80
86
  end
81
87
 
82
88
  # Get ledger from Kraken
83
- # @param [Integer] days optional number of days to fetch ledger from (last N days)
89
+ # @param [Integer] tsp optional timestamp to fetch ledger from (last N seconds)
84
90
  # @return [Hash] ledger kraken
85
- def ledger_us(days = nil)
86
- pag_us_req('Ledgers', :ledger, days ? {start: days} : {})
91
+ def ledger_us(tsp = nil)
92
+ pag_us_req('Ledgers', :ledger, tsp ? {start: tsp} : {})
87
93
  rescue Curl::Err::CurlError
88
94
  []
89
95
  end
data/lib/cns/etherscan.rb CHANGED
@@ -214,12 +214,6 @@ module Cns
214
214
  ops[:t] || false
215
215
  end
216
216
 
217
- # Numero dias para buscar transacoes
218
- # @return [Integer] days in the past to get transacoes
219
- def dias
220
- ops&.[](:d)&.positive? ? ops[:d] : nil
221
- end
222
-
223
217
  # Process timestamp
224
218
  # @param [Hash] htx transacao
225
219
  # @return [Hash] transaccao filtrada
@@ -259,13 +253,14 @@ module Cns
259
253
  # @return [Hash] dados etherscan - address, saldo & transacoes
260
254
  def esd(aes)
261
255
  acc = aes[:account].downcase
262
- dys = dias
256
+ dys = ops&.[](:d)&.positive? ? ops[:d] : nil
263
257
  {
264
258
  ax: acc,
265
259
  sl: aes[:balance].to_d / (10**18),
266
260
  tx: ftik(acc, api.norml_es(acc, days: dys)),
267
261
  ix: ftik(acc, api.inter_es(acc, days: dys)),
268
- px: fppp(acc, api.block_es(acc)), # block_es (mining) does not support time filtering
262
+ # block_es (mining) does not support timestamp filtering
263
+ px: fppp(acc, api.block_es(acc)),
269
264
  wx: fwww(acc, api.withw_es(acc, days: dys)),
270
265
  kx: ftik(acc, api.token_es(acc, days: dys))
271
266
  }
data/lib/cns/kraken.rb CHANGED
@@ -48,7 +48,7 @@ module Cns
48
48
  vkt, vnt = exd[:kt].count, bqd[:nt].count
49
49
  vkl, vnl = exd[:kl].count, bqd[:nl].count
50
50
 
51
- puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vkt, b: vnt, o: vkt == vnt ? 'OK' : 'NOK')}")
51
+ puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vkt, b: vnt, o: vkt == vnt ? 'OK' : 'NOK')}") if vkt.positive?
52
52
  puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vkl, d: vnl, o: vkl == vnl ? 'OK' : 'NOK')}")
53
53
  end
54
54
 
@@ -155,9 +155,9 @@ module Cns
155
155
 
156
156
  # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
157
157
  memoize def exd
158
- # Numero dias para buscar transacoes
159
- dys = ops&.[](:d)&.positive? ? Integer(Time.now - (ops[:d] * 86_400)) : nil
160
- {sl: pusa(api.account_us), kt: pust(api.trades_us(dys)), kl: pusl(api.ledger_us(dys))}
158
+ # unix timestamp para obter transacoes 24x60x60 = 86400 segundos
159
+ tsp = ops&.[](:d)&.positive? ? Integer(Time.now - (ops[:d] * 86_400)) : nil
160
+ {sl: pusa(api.account_us), kt: pust(api.trades_us(tsp)), kl: pusl(api.ledger_us(tsp))}
161
161
  end
162
162
 
163
163
  # @return [Array<String>] indices trades bigquery
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '2.1.4'
4
+ VERSION = '2.1.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz