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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cns/apibc.rb +6 -2
- data/lib/cns/apice.rb +12 -6
- data/lib/cns/etherscan.rb +3 -8
- data/lib/cns/kraken.rb +4 -4
- data/lib/cns/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d956c363cc9263bde314d61e987fd558ef04082cf6e966be8918ea5fe911d00
|
|
4
|
+
data.tar.gz: bfab434ac3d3a76d9340c79a75643c6ca0d295238cd13afa4dd19f9d343f4616
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4321ad66e65f2667d8ee0d894e2610fc9dbf5d7bad4848b65b679a4898dd6e41ad76440cdc4a2ae27039502e5765a05e6435c05bcb91f0f4f4e10fed12f1016b
|
|
7
|
+
data.tar.gz: 0a0fb3d9421299798b8563041306a0a859d45e2cb46a1cf36fdc0e0e97c63d58660a83d586c98da78014e271dbea9e8efd8f714ad75011d2b030102303571226
|
data/Gemfile.lock
CHANGED
data/lib/cns/apibc.rb
CHANGED
|
@@ -73,11 +73,14 @@ module Cns
|
|
|
73
73
|
|
|
74
74
|
private
|
|
75
75
|
|
|
76
|
-
#
|
|
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
|
-
#
|
|
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]
|
|
74
|
+
# @param [Integer] tsp optional timestamp to fetch trades from (last N seconds)
|
|
75
75
|
# @return [Hash] trades kraken
|
|
76
|
-
def trades_us(
|
|
77
|
-
|
|
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]
|
|
89
|
+
# @param [Integer] tsp optional timestamp to fetch ledger from (last N seconds)
|
|
84
90
|
# @return [Hash] ledger kraken
|
|
85
|
-
def ledger_us(
|
|
86
|
-
pag_us_req('Ledgers', :ledger,
|
|
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 =
|
|
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
|
-
|
|
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
|
-
#
|
|
159
|
-
|
|
160
|
-
{sl: pusa(api.account_us), kt: pust(api.trades_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))}
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
# @return [Array<String>] indices trades bigquery
|
data/lib/cns/version.rb
CHANGED