cns 2.1.3 → 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: 7b4f061958b493cf2e1d3dccff8bb7bcc42443e592d0f594c67df399b8d1b000
4
- data.tar.gz: 60204c42355f161bd7db49c4764a58f7642458c17bef96462ba4a723a8f01859
3
+ metadata.gz: 9d956c363cc9263bde314d61e987fd558ef04082cf6e966be8918ea5fe911d00
4
+ data.tar.gz: bfab434ac3d3a76d9340c79a75643c6ca0d295238cd13afa4dd19f9d343f4616
5
5
  SHA512:
6
- metadata.gz: 7fbdce8e9f9f4498d544e1e1b3adef72da44bdc25892fa7e520fa634a0c2503a0ec1928b6269dde446d988b36fc0d5a54fd1a97be6a67d0e4f8632a5de92f24b
7
- data.tar.gz: e27fe2677a895df93997ad203dec3e1cc34094ab55a50935558ca451d23c417c0076b13e9f04d858271e7218629ef0b0ec9258926ee555042741328927c5a1cc
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.3)
4
+ cns (2.1.5)
5
5
  curb
6
6
  faraday
7
7
  faraday-retry
@@ -213,7 +213,7 @@ PLATFORMS
213
213
  DEPENDENCIES
214
214
  bundler
215
215
  cns!
216
- rake (~> 12.0)
216
+ rake (~> 12.0, >= 0)
217
217
  reek
218
218
  rubocop
219
219
  rubocop-rake
@@ -221,4 +221,4 @@ DEPENDENCIES
221
221
  yard
222
222
 
223
223
  BUNDLED WITH
224
- 2.6.9
224
+ 4.0.6
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,17 +71,25 @@ module Cns
71
71
  end
72
72
 
73
73
  # Get trades from Kraken
74
+ # @param [Integer] tsp optional timestamp to fetch trades from (last N seconds)
74
75
  # @return [Hash] trades kraken
75
- def trades_us
76
- pag_us_req('TradesHistory', :trades)
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
77
84
  rescue Curl::Err::CurlError
78
85
  []
79
86
  end
80
87
 
81
88
  # Get ledger from Kraken
89
+ # @param [Integer] tsp optional timestamp to fetch ledger from (last N seconds)
82
90
  # @return [Hash] ledger kraken
83
- def ledger_us
84
- pag_us_req('Ledgers', :ledger)
91
+ def ledger_us(tsp = nil)
92
+ pag_us_req('Ledgers', :ledger, tsp ? {start: tsp} : {})
85
93
  rescue Curl::Err::CurlError
86
94
  []
87
95
  end
@@ -102,15 +110,16 @@ module Cns
102
110
  # Generic paginated request handler for Kraken
103
111
  # @param [String] uri API endpoint URI
104
112
  # @param [Symbol] key Key to extract from the result
113
+ # @param [Hash] prm Additional options for the request
105
114
  # @yield [Array<Hash>] Block to process each batch of results
106
115
  # @return [Array<Hash>] Combined results from all pages
107
- def pag_us_req(uri, key)
116
+ def pag_us_req(uri, key, prm = {})
108
117
  ary = []
109
118
  ofs = 0
110
119
  loop do
111
120
  # Rate limiting for page requests (2s in Kraken)
112
121
  sleep(@lpag - Time.now + 2) if @lpag && Time.now - @lpag < 2
113
- ops = {nonce: nnc, ofs: ofs}
122
+ ops = prm.merge({nonce: nnc, ofs: ofs})
114
123
  rcrl(@curl, "#{API[:us]}/#{uri}", method: 'POST', post_data: ops, headers: hus(uri, ops))
115
124
  bth = pjsn(@curl).fetch(:result, {}).fetch(key, []).map { |k, v| us_unif(k, v) }
116
125
  break if bth.empty?
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,7 +155,9 @@ module Cns
155
155
 
156
156
  # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
157
157
  memoize def exd
158
- {sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us)}
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))}
159
161
  end
160
162
 
161
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.3'
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.3
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz