cns 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cns/{apice2.rb → apice.rb} +165 -0
- data/lib/cns/{beaconchain1.rb → beaconchain.rb} +84 -1
- data/lib/cns/bigquery.rb +620 -0
- data/lib/cns/{etherscan1.rb → etherscan.rb} +184 -1
- data/lib/cns/{greymass1.rb → greymass.rb} +62 -1
- data/lib/cns/version.rb +1 -1
- data/lib/cns.rb +5 -12
- metadata +7 -14
- data/lib/cns/apice1.rb +0 -177
- data/lib/cns/beaconchain2.rb +0 -90
- data/lib/cns/bigquery1.rb +0 -124
- data/lib/cns/bigquery2.rb +0 -104
- data/lib/cns/bigquery3.rb +0 -268
- data/lib/cns/bigquery4.rb +0 -154
- data/lib/cns/etherscan2.rb +0 -190
- data/lib/cns/greymass2.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50e17e193099669aed9ed6e7b5b555cd6a8ed33a664d4390ca96f3c0dd633da5
|
4
|
+
data.tar.gz: 47ef9c5fde7e329a39d3c2efbc37a004bafe215bfdaafdab2ea0502e3930f4ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dae786aa9f694ee2bcd67ff33fe929bc2a45b71829c015e2ba210551a609c332123bd0c7d8761dabcb73eceaa817b8216123b89560380927243abe6d16d4361
|
7
|
+
data.tar.gz: 2a7a177ffb73054a36972c2616b99a69222ab838f2e9f1ddae48497abd2238becc7be13b636d124c28b43a7f5fbcbbd108e9a08c6fff546f5af71ee476068978
|
data/Gemfile.lock
CHANGED
@@ -7,8 +7,109 @@ require('json')
|
|
7
7
|
|
8
8
|
# @author Hernani Rodrigues Vaz
|
9
9
|
module Cns
|
10
|
+
DC = %w[LTC NMC PPC DOGE XRP Linden USD CAD GBP ZEC BCH EURN NOKU FDZ GUSD SEED USDC].freeze
|
11
|
+
|
10
12
|
# classe para acesso dados centralized exchanges
|
11
13
|
class Apice
|
14
|
+
# @example account_de
|
15
|
+
# {
|
16
|
+
# data: {
|
17
|
+
# balances: {
|
18
|
+
# btc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
19
|
+
# bch: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
20
|
+
# btg: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
21
|
+
# eth: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
22
|
+
# bsv: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
23
|
+
# ltc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' }
|
24
|
+
# },
|
25
|
+
# encrypted_information: { uid: '0y...', bic_short: '0y...', bic_full: '0y...' }
|
26
|
+
# },
|
27
|
+
# errors: [],
|
28
|
+
# credits: 23
|
29
|
+
# }
|
30
|
+
# @param [String] uri Uniform Resource Identifier do pedido HTTP
|
31
|
+
# @return [Hash] saldos no bitcoinde
|
32
|
+
def account_de(uri = 'https://api.bitcoin.de/v4/account')
|
33
|
+
JSON.parse(
|
34
|
+
Curl.get(uri) { |obj| obj.headers = hde(uri) }.body,
|
35
|
+
symbolize_names: true
|
36
|
+
)[:data][:balances]
|
37
|
+
rescue StandardError
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
|
41
|
+
# @example account_fr
|
42
|
+
# {
|
43
|
+
# name: '...',
|
44
|
+
# email: '...',
|
45
|
+
# locale: 'en',
|
46
|
+
# channel_id: '...',
|
47
|
+
# meta_state: 'approved',
|
48
|
+
# balance_eur: '0.0',
|
49
|
+
# locked_eur: '0.0',
|
50
|
+
# balance_btc: '0.0',
|
51
|
+
# locked_btc: '0.0',
|
52
|
+
# balance_lbtc: '0.0',
|
53
|
+
# locked_lbtc: '0.0'
|
54
|
+
# }
|
55
|
+
# @param (see account_de)
|
56
|
+
# @return [Hash] saldos no paymium
|
57
|
+
def account_fr(uri = 'https://paymium.com/api/v1/user')
|
58
|
+
JSON.parse(
|
59
|
+
Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body,
|
60
|
+
symbolize_names: true
|
61
|
+
)
|
62
|
+
rescue StandardError
|
63
|
+
{}
|
64
|
+
end
|
65
|
+
|
66
|
+
# @example account_mt
|
67
|
+
# {
|
68
|
+
# balances: [
|
69
|
+
# { currency: 'BTC', balance: 0.0, trading_balance: 0.0 },
|
70
|
+
# { currency: 'ETH', balance: 0.0, trading_balance: 0.0 },
|
71
|
+
# { currency: 'EUR', balance: 0.0, trading_balance: 0.0 },
|
72
|
+
# { currency: 'DAI', balance: 0.0, trading_balance: 0.0 },
|
73
|
+
# ]
|
74
|
+
# }
|
75
|
+
# @param (see account_de)
|
76
|
+
# @return [Array<Hash>] lista saldos no therock
|
77
|
+
def account_mt(uri = 'https://api.therocktrading.com/v1/balances')
|
78
|
+
JSON.parse(
|
79
|
+
Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body,
|
80
|
+
symbolize_names: true
|
81
|
+
)[:balances]
|
82
|
+
.delete_if { |del| DC.include?(del[:currency]) }
|
83
|
+
.sort { |oba, obb| oba[:currency] <=> obb[:currency] }
|
84
|
+
rescue StandardError
|
85
|
+
[]
|
86
|
+
end
|
87
|
+
|
88
|
+
# @example account_us
|
89
|
+
# {
|
90
|
+
# error: [],
|
91
|
+
# result: {
|
92
|
+
# ZEUR: '0.0038',
|
93
|
+
# XXBT: '0.0000000000',
|
94
|
+
# XETH: '1.0000000000',
|
95
|
+
# XETC: '0.0000000000',
|
96
|
+
# EOS: '0.0000001700',
|
97
|
+
# BCH: '0.0000000000'
|
98
|
+
# }
|
99
|
+
# }
|
100
|
+
# @param [String] urb Uniform Resource Base do pedido HTTP
|
101
|
+
# @param uri (see account_de)
|
102
|
+
# @param non (see hde)
|
103
|
+
# @return [Hash] saldos no kraken
|
104
|
+
def account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc)
|
105
|
+
JSON.parse(
|
106
|
+
Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body,
|
107
|
+
symbolize_names: true
|
108
|
+
)[:result]
|
109
|
+
rescue StandardError
|
110
|
+
{}
|
111
|
+
end
|
112
|
+
|
12
113
|
# @example trades_de
|
13
114
|
# {
|
14
115
|
# trades: [{
|
@@ -319,5 +420,69 @@ module Cns
|
|
319
420
|
rescue StandardError
|
320
421
|
has
|
321
422
|
end
|
423
|
+
|
424
|
+
private
|
425
|
+
|
426
|
+
# @return [Integer] continually-increasing unsigned integer nonce from the current Unix Time
|
427
|
+
def nnc
|
428
|
+
Integer(Float(Time.now) * 1e6)
|
429
|
+
end
|
430
|
+
|
431
|
+
# @param [String] qde query a incluir no pedido HTTP
|
432
|
+
# @param [Integer] non continually-increasing unsigned integer
|
433
|
+
# @return [Hash] headers necessarios para pedido HTTP da exchange bitcoinde
|
434
|
+
def hde(qde, non = nnc)
|
435
|
+
key = ENV['BITCOINDE_API_KEY']
|
436
|
+
{
|
437
|
+
'X-API-KEY': key,
|
438
|
+
'X-API-NONCE': non,
|
439
|
+
'X-API-SIGNATURE': OpenSSL::HMAC.hexdigest(
|
440
|
+
'sha256',
|
441
|
+
ENV['BITCOINDE_API_SECRET'],
|
442
|
+
['GET', qde, key, non, Digest::MD5.hexdigest('')].join('#')
|
443
|
+
)
|
444
|
+
}
|
445
|
+
end
|
446
|
+
|
447
|
+
# @param [String] qfr query a incluir no pedido HTTP
|
448
|
+
# @param non (see hde)
|
449
|
+
# @return [Hash] headers necessarios para pedido HTTP da exchange paymium
|
450
|
+
def hfr(qfr, non = nnc)
|
451
|
+
{
|
452
|
+
content_type: 'application/json',
|
453
|
+
'Api-Key': ENV['PAYMIUM_API_KEY'],
|
454
|
+
'Api-Nonce': non,
|
455
|
+
'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qfr].join)
|
456
|
+
}
|
457
|
+
end
|
458
|
+
|
459
|
+
# @param [String] qmt query a incluir no pedido HTTP
|
460
|
+
# @param non (see hde)
|
461
|
+
# @return [Hash] headers necessarios para pedido HTTP da exchange therock
|
462
|
+
def hmt(qmt, non = nnc)
|
463
|
+
{
|
464
|
+
content_type: 'application/json',
|
465
|
+
'X-TRT-KEY': ENV['THEROCK_API_KEY'],
|
466
|
+
'X-TRT-NONCE': non,
|
467
|
+
'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qmt].join)
|
468
|
+
}
|
469
|
+
end
|
470
|
+
|
471
|
+
# @param [String] qus query a incluir no pedido HTTP
|
472
|
+
# @param [Hash] ops opcoes trabalho
|
473
|
+
# @option ops [Hash] :nonce continually-increasing unsigned integer
|
474
|
+
# @return [Hash] headers necessarios para pedido HTTP da exchange kraken
|
475
|
+
def hus(qus, ops)
|
476
|
+
{
|
477
|
+
'api-key': ENV['KRAKEN_API_KEY'],
|
478
|
+
'api-sign': Base64.strict_encode64(
|
479
|
+
OpenSSL::HMAC.digest(
|
480
|
+
'sha512',
|
481
|
+
Base64.decode64(ENV['KRAKEN_API_SECRET']),
|
482
|
+
['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
|
483
|
+
)
|
484
|
+
)
|
485
|
+
}
|
486
|
+
end
|
322
487
|
end
|
323
488
|
end
|
@@ -4,7 +4,7 @@ require('bigdecimal/util')
|
|
4
4
|
|
5
5
|
# @author Hernani Rodrigues Vaz
|
6
6
|
module Cns
|
7
|
-
#
|
7
|
+
# classe para processar historicos da beaconchain
|
8
8
|
class Beaconchain
|
9
9
|
# @return [Apibc] API blockchains
|
10
10
|
attr_reader :api
|
@@ -98,5 +98,88 @@ module Cns
|
|
98
98
|
eb: abc[:bx]
|
99
99
|
}
|
100
100
|
end
|
101
|
+
|
102
|
+
# @return [String] texto validadores & saldos historicos
|
103
|
+
def mostra_resumo
|
104
|
+
return unless dados.count.positive?
|
105
|
+
|
106
|
+
puts("\nindex address beaconchain blh bigquery blh")
|
107
|
+
dados.each { |obj| puts(formata_validador(obj)) }
|
108
|
+
mostra_saldos
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param [Hash] hjn dados juntos bigquery & beaconchain
|
112
|
+
# @return [String] texto formatado dum validador
|
113
|
+
def formata_validador(hjn)
|
114
|
+
format('%<s1>-5.5s %<s2>-34.34s ', s1: hjn[:id], s2: formata_endereco(hjn[:ax], 34)) + formata_valores(hjn)
|
115
|
+
end
|
116
|
+
|
117
|
+
# @param (see formata_validador)
|
118
|
+
# @return [String] texto formatado valores dum validador
|
119
|
+
def formata_valores(hjn)
|
120
|
+
format(
|
121
|
+
'%<v1>11.6f %<n1>3i %<v2>12.6f %<n2>6i %<ok>-3s',
|
122
|
+
v1: hjn[:es],
|
123
|
+
n1: hjn[:eb].count,
|
124
|
+
v2: hjn[:bs],
|
125
|
+
n2: hjn[:bb].count,
|
126
|
+
ok: ok?(hjn) ? 'OK' : 'NOK'
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
# @param (see formata_validador)
|
131
|
+
# @return [Boolean] validador tem historicos novos(sim=NOK, nao=OK)?
|
132
|
+
def ok?(hjn)
|
133
|
+
hjn[:bs] == hjn[:es]
|
134
|
+
end
|
135
|
+
|
136
|
+
# @example pubkey inicio..fim
|
137
|
+
# 0x10f3a0cf0b534c..c033cf32e8a03586
|
138
|
+
# @param [String] add chave publica validador
|
139
|
+
# @param [Integer] max chars a mostrar
|
140
|
+
# @return [String] pubkey formatada
|
141
|
+
def formata_endereco(add, max)
|
142
|
+
return 'erro' if max < 7
|
143
|
+
|
144
|
+
max -= 2
|
145
|
+
ini = Integer(max / 2)
|
146
|
+
inf = max % 2
|
147
|
+
"#{add[0, ini - 3]}..#{add[-inf - ini - 3..]}"
|
148
|
+
end
|
149
|
+
|
150
|
+
# @example
|
151
|
+
# {
|
152
|
+
# balance: 32_489_497_108,
|
153
|
+
# effectivebalance: 32_000_000_000,
|
154
|
+
# epoch: 8296,
|
155
|
+
# validatorindex: 11_766,
|
156
|
+
# week: 5
|
157
|
+
# }
|
158
|
+
# @param [Hash] hbh historico beaconchain
|
159
|
+
# @return [String] texto formatado historico beaconchain
|
160
|
+
def formata_saldos(hbh)
|
161
|
+
idx = hbh[:validatorindex]
|
162
|
+
epc = hbh[:epoch]
|
163
|
+
format(
|
164
|
+
'%<vi>5i %<vl>17.6f %<ep>6i %<id>9i',
|
165
|
+
vi: idx,
|
166
|
+
vl: (hbh[:balance].to_d / (10**9)).round(10),
|
167
|
+
ep: epc,
|
168
|
+
id: itx(epc, idx)
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
# @return [String] texto historico saldos
|
173
|
+
def mostra_saldos
|
174
|
+
return unless ops[:v] && nov.count.positive?
|
175
|
+
|
176
|
+
puts("\nindex saldo epoch itx")
|
177
|
+
sorbx.each { |obj| puts(formata_saldos(obj)) }
|
178
|
+
end
|
179
|
+
|
180
|
+
# @return [Array<Hash>] lista ordenada historico saldos
|
181
|
+
def sorbx
|
182
|
+
nov.sort { |ant, prx| ant[:itx] <=> prx[:itx] }
|
183
|
+
end
|
101
184
|
end
|
102
185
|
end
|