cns 0.9.2 → 0.9.4
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 +3 -3
- data/lib/cns/bigquery.rb +42 -20
- data/lib/cns/bitcoinde.rb +78 -72
- data/lib/cns/etherscan.rb +178 -183
- data/lib/cns/greymass.rb +85 -86
- data/lib/cns/kraken.rb +82 -73
- data/lib/cns/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70ccf3bf3c61dccaf39f5fe5e34b3f629efd8182fbd036f1d1193e2e0d842e4
|
4
|
+
data.tar.gz: 969e4c7d275aa2b14a6e9b1324e007b84d9f61522b099fdbb6c6d8a9bc129708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c406b44bacdf24f32dc6babc0c08d51cf5fe4f88724466e1af7d8770b08ae23da74c8811cc9f0bea0bdb11cf13ffb9fe3d8080de2626f8f3a0d6f22739e1e82f
|
7
|
+
data.tar.gz: 47e0b4e735ac2c3b11a11018ac5a9830ec1cf24c253b4cb7ab0b353bc2c262f55c572938668ccd00618bf367b5d1019381a30037789fecf13dd2a3b5e5a698b9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cns (0.9.
|
4
|
+
cns (0.9.4)
|
5
5
|
curb
|
6
6
|
faraday
|
7
7
|
google-cloud-bigquery
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
google-cloud-errors (~> 1.0)
|
80
80
|
google-cloud-env (2.2.1)
|
81
81
|
faraday (>= 1.0, < 3.a)
|
82
|
-
google-cloud-errors (1.
|
82
|
+
google-cloud-errors (1.5.0)
|
83
83
|
google-logging-utils (0.1.0)
|
84
84
|
googleauth (1.13.1)
|
85
85
|
faraday (>= 1.0, < 3.a)
|
@@ -137,7 +137,7 @@ GEM
|
|
137
137
|
reverse_markdown (3.0.0)
|
138
138
|
nokogiri
|
139
139
|
rexml (3.4.1)
|
140
|
-
rubocop (1.73.
|
140
|
+
rubocop (1.73.2)
|
141
141
|
json (~> 2.3)
|
142
142
|
language_server-protocol (~> 3.17.0.2)
|
143
143
|
lint_roller (~> 1.1.0)
|
data/lib/cns/bigquery.rb
CHANGED
@@ -9,16 +9,16 @@ module Cns
|
|
9
9
|
FO = File.expand_path("~/#{File.basename($PROGRAM_NAME)}.log")
|
10
10
|
EM = %i[EOS XETH ZEUR btc eth]
|
11
11
|
TB = {
|
12
|
-
netht: %w[blocknumber timestamp
|
13
|
-
hetht: %i[blockNumber timeStamp
|
14
|
-
nethi: %w[blocknumber timestamp
|
15
|
-
hethi: %i[blockNumber timeStamp
|
12
|
+
netht: %w[txhash blocknumber timestamp nonce blockhash transactionindex axfrom axto iax value gas gasprice gasused iserror txreceipt_status input contractaddress dias],
|
13
|
+
hetht: %i[hash blockNumber timeStamp nonce blockHash transactionIndex from to iax value gas gasPrice gasUsed isError txreceipt_status input contractAddress],
|
14
|
+
nethi: %w[txhash blocknumber timestamp axfrom axto iax value contractaddress input type gas gasused traceid iserror errcode dias],
|
15
|
+
hethi: %i[hash blockNumber timeStamp from to iax value contractAddress input type gas gasUsed traceId isError errCode],
|
16
16
|
nethp: %w[blocknumber timestamp blockreward iax dias],
|
17
17
|
hethp: %i[blockNumber timeStamp blockReward iax],
|
18
18
|
nethw: %w[withdrawalindex validatorindex address amount blocknumber timestamp dias],
|
19
19
|
hethw: %i[withdrawalIndex validatorIndex address amount blockNumber timeStamp],
|
20
|
-
nethk: %w[blocknumber timestamp
|
21
|
-
hethk: %i[blockNumber timeStamp
|
20
|
+
nethk: %w[txhash blocknumber timestamp nonce blockhash transactionindex axfrom axto iax value tokenname tokensymbol tokendecimal gas gasprice gasused input contractaddress dias],
|
21
|
+
hethk: %i[hash blockNumber timeStamp nonce blockHash transactionIndex from to iax value tokenName tokenSymbol tokenDecimal gas gasPrice gasUsed input contractAddress],
|
22
22
|
neost: %w[gseq aseq bnum time contract action acfrom acto iax amount moeda memo dias],
|
23
23
|
heost: %i[global_action_seq account_action_seq block_num block_time account name from to iax quantity moe memo],
|
24
24
|
cdet: %w[txid time tp user btc eur dtc dias],
|
@@ -30,6 +30,21 @@ module Cns
|
|
30
30
|
cusl: %w[txid refid time type aclass asset amount fee],
|
31
31
|
husl: %i[txid refid time type aclass asset amount fee]
|
32
32
|
}
|
33
|
+
# para testes bigquery
|
34
|
+
TL = {
|
35
|
+
ins: 'INSERT',
|
36
|
+
exo: false,
|
37
|
+
est: '', # ' limit 226',
|
38
|
+
esi: '', # ' limit 22',
|
39
|
+
esp: '', # ' limit 72',
|
40
|
+
esw: '', # ' limit 2299',
|
41
|
+
esk: '', # ' limit 20',
|
42
|
+
gmt: '', # ' limit 1091',
|
43
|
+
ust: '', # ' limit 182',
|
44
|
+
usl: '', # ' limit 448',
|
45
|
+
det: '', # ' limit 27',
|
46
|
+
del: '' # ' limit 16'
|
47
|
+
}
|
33
48
|
|
34
49
|
# classe para processar bigquery
|
35
50
|
class Bigquery
|
@@ -154,11 +169,11 @@ module Cns
|
|
154
169
|
Etherscan.new(
|
155
170
|
{
|
156
171
|
wb: sql("SELECT * FROM #{BD}.wet#{prx[-1]} ORDER BY ax"),
|
157
|
-
|
158
|
-
|
159
|
-
np: sql("SELECT * FROM #{BD}.#{prx}p"),
|
160
|
-
|
161
|
-
|
172
|
+
nt: sql("SELECT * FROM #{BD}.#{prx}t#{TL[:est]}"),
|
173
|
+
ni: sql("SELECT * FROM #{BD}.#{prx}i#{TL[:esi]}"),
|
174
|
+
np: sql("SELECT * FROM #{BD}.#{prx}p#{TL[:esp]}"),
|
175
|
+
nw: sql("SELECT * FROM #{BD}.#{prx}w#{TL[:esw]}"),
|
176
|
+
nk: sql("SELECT * FROM #{BD}.#{prx}k#{TL[:esk]}")
|
162
177
|
},
|
163
178
|
ops
|
164
179
|
)
|
@@ -176,32 +191,39 @@ module Cns
|
|
176
191
|
|
177
192
|
# @return [Greymass] API blockchain EOS
|
178
193
|
def apigm
|
179
|
-
@apigm ||= Greymass.new({wb: sql("select * from #{BD}.weos ORDER BY ax"), nt: sql("select * from #{BD}.neosx")}, ops)
|
194
|
+
@apigm ||= Greymass.new({wb: sql("select * from #{BD}.weos ORDER BY ax"), nt: sql("select * from #{BD}.neosx#{TL[:gmt]}")}, ops)
|
180
195
|
end
|
181
196
|
|
182
197
|
# @return [Kraken] API exchange kraken
|
183
198
|
def apius
|
184
|
-
@apius ||= Kraken.new({sl: sql("select * from #{BD}.cuss").first, nt: sql("select * from #{BD}.cust"), nl: sql("select * from #{BD}.cusl")}, ops)
|
199
|
+
@apius ||= Kraken.new({sl: sql("select * from #{BD}.cuss").first, nt: sql("select * from #{BD}.cust#{TL[:ust]}"), nl: sql("select * from #{BD}.cusl#{TL[:usl]}")}, ops)
|
185
200
|
end
|
186
201
|
|
187
202
|
# @return [Bitcoinde] API exchange bitcoinde
|
188
203
|
def apide
|
189
|
-
@apide ||= Bitcoinde.new({sl: sql("select * from #{BD}.cdes").first, nt: sql("select * from #{BD}.cdet"), nl: sql("select * from #{BD}.cdel")}, ops)
|
204
|
+
@apide ||= Bitcoinde.new({sl: sql("select * from #{BD}.cdes").first, nt: sql("select * from #{BD}.cdet#{TL[:det]}"), nl: sql("select * from #{BD}.cdel#{TL[:del]}")}, ops)
|
190
205
|
end
|
191
206
|
|
192
207
|
# @return [String] comando insert SQL formatado
|
193
208
|
def ins_sql(tbl, lin)
|
194
|
-
|
209
|
+
# para testes bigquery
|
210
|
+
if TL[:exo]
|
211
|
+
exl = lin.map { |i| send("#{tbl}_val", i)[1..-2] }
|
212
|
+
exi = exl.map { |f| f.split(',').first }.join(',')
|
213
|
+
exo = "SELECT #{TB[tbl].join(',')} FROM #{BD}.#{tbl} WHERE #{TB[tbl].first} IN (#{exi}) union all select "
|
214
|
+
puts(exo + exl.join(' union all select ') + ' order by 1')
|
215
|
+
end
|
216
|
+
"#{TL[:ins]} #{BD}.#{tbl} (#{TB[tbl].join(',')}) VALUES #{lin.map { |i| send("#{tbl}_val", i) }.join(',')}"
|
195
217
|
end
|
196
218
|
|
197
219
|
# @return [String] relatorio execucao dml
|
198
220
|
def dml_out(src, str, ltb)
|
199
221
|
str.concat(
|
200
|
-
ltb.filter_map do |
|
201
|
-
novx = src.send("nov#{
|
222
|
+
ltb.filter_map do |i|
|
223
|
+
novx = src.send("nov#{i}")
|
202
224
|
next if novx.empty?
|
203
225
|
|
204
|
-
format(' %<n>i %<t>s', n: dml(ins_sql(
|
226
|
+
format(' %<n>i %<t>s', n: dml(ins_sql(i, %i[cust cusl].include?(i) ? novx.values : novx)), t: "#{i}")
|
205
227
|
end
|
206
228
|
)
|
207
229
|
str.join
|
@@ -290,7 +312,7 @@ module Cns
|
|
290
312
|
# @param [Hash] htx ledger greymass
|
291
313
|
# @return [String] valores formatados neost
|
292
314
|
def neost_val(htx)
|
293
|
-
fvals(htx, TB[:heost], :
|
315
|
+
fvals(htx, TB[:heost], :global_action_seq)
|
294
316
|
end
|
295
317
|
|
296
318
|
# @param [Hash] htx trades bitcoinde
|
@@ -308,7 +330,7 @@ module Cns
|
|
308
330
|
# @param [Hash] htx trades kraken
|
309
331
|
# @return [String] valores formatados cust
|
310
332
|
def cust_val(htx)
|
311
|
-
fvals(htx.merge(ledgers: apius.
|
333
|
+
fvals(htx.merge(ledgers: apius.uskl.select { |_, o| o[:refid] == htx[:txid] }.keys.join(',')), TB[:hust], :txid)
|
312
334
|
end
|
313
335
|
|
314
336
|
# @param [Hash] htx ledger kraken
|
data/lib/cns/bitcoinde.rb
CHANGED
@@ -7,11 +7,9 @@ module Cns
|
|
7
7
|
# classe para processar transacoes trades/ledger do bitcoinde
|
8
8
|
class Bitcoinde
|
9
9
|
# @return [Apius] API bitcoinde
|
10
|
-
attr_reader :api
|
11
10
|
# @return [Array<Hash>] todos os dados bigquery
|
12
|
-
attr_reader :bqd
|
13
11
|
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
14
|
-
attr_reader :ops
|
12
|
+
attr_reader :api, :bqd, :ops
|
15
13
|
|
16
14
|
# @param [Hash] dad todos os dados bigquery
|
17
15
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
@@ -25,15 +23,10 @@ module Cns
|
|
25
23
|
@ops = pop.transform_keys(&:to_sym)
|
26
24
|
end
|
27
25
|
|
28
|
-
# @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
|
29
|
-
def exd
|
30
|
-
@exd ||= {sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de)}
|
31
|
-
end
|
32
|
-
|
33
26
|
# @return [String] texto saldos & transacoes & ajuste dias
|
34
27
|
def mresumo
|
35
28
|
puts("\nBITCOINDE\ntipo bitcoinde bigquery")
|
36
|
-
|
29
|
+
ded[:sl].sort.each { |k, v| puts(fos(k, v)) }
|
37
30
|
mtotais
|
38
31
|
|
39
32
|
mtrades
|
@@ -45,42 +38,37 @@ module Cns
|
|
45
38
|
|
46
39
|
private
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
41
|
+
# mosta contadores transacoes
|
42
|
+
def mtotais
|
43
|
+
vtt = ded[:tt].count
|
44
|
+
vnt = bqd[:nt].count
|
45
|
+
vtl = ded[:tl].count
|
46
|
+
vnl = bqd[:nl].count
|
55
47
|
|
56
|
-
|
57
|
-
|
48
|
+
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
|
49
|
+
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vtl, d: vnl, o: vtl == vnl ? 'OK' : 'NOK')}")
|
58
50
|
end
|
59
51
|
|
60
|
-
#
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
52
|
+
# mosta transacoes trades
|
53
|
+
def mtrades
|
54
|
+
return unless ops[:v] && novcdet.any?
|
64
55
|
|
65
|
-
|
66
|
-
|
67
|
-
@kyl ||= exd[:tl].map { |oex| oex[:txid] } - bqkyl
|
56
|
+
puts("\ntrades data hora dt criacao tipo par btc eur")
|
57
|
+
novcdet.sort_by { |i| -i[:srx] }.each { |o| puts(fot(o)) }
|
68
58
|
end
|
69
59
|
|
70
|
-
#
|
71
|
-
def
|
72
|
-
|
73
|
-
end
|
60
|
+
# mosta transacoes ledger
|
61
|
+
def mledger
|
62
|
+
return unless ops[:v] && novcdel.any?
|
74
63
|
|
75
|
-
|
76
|
-
|
77
|
-
@novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
64
|
+
puts("\nledger data hora tipo moe quantidade custo")
|
65
|
+
novcdel.sort_by { |i| -i[:srx] }.each { |o| puts(fol(o)) }
|
78
66
|
end
|
79
67
|
|
80
68
|
# @param [String] moe codigo bitcoinde da moeda
|
81
69
|
# @param [Hash] hsx saldo bitcoinde da moeda
|
82
70
|
# @return [String] texto formatado saldos
|
83
|
-
def
|
71
|
+
def fos(moe, hsx)
|
84
72
|
vbq = bqd[:sl][moe.downcase.to_sym].to_d
|
85
73
|
vex = hsx[:total_amount]
|
86
74
|
format(
|
@@ -92,9 +80,9 @@ module Cns
|
|
92
80
|
)
|
93
81
|
end
|
94
82
|
|
95
|
-
# @param
|
83
|
+
# @param [Hash] htn trades bitcoinde
|
96
84
|
# @return [String] texto formatado trade
|
97
|
-
def
|
85
|
+
def fot(htx)
|
98
86
|
format(
|
99
87
|
'%<ky>-6.6s %<dt>19.19s %<dp>10.10s %<ty>-5.5s %<mo>-8.8s %<vl>18.8f %<co>8.2f',
|
100
88
|
ky: htx[:trade_id],
|
@@ -107,9 +95,9 @@ module Cns
|
|
107
95
|
)
|
108
96
|
end
|
109
97
|
|
110
|
-
# @param
|
98
|
+
# @param [Hash] htn ledger bitcoinde
|
111
99
|
# @return [String] texto formatado ledger
|
112
|
-
def
|
100
|
+
def fol(hlx)
|
113
101
|
format(
|
114
102
|
'%<ky>6i %<dt>19.19s %<ty>-10.10s %<mo>-3.3s %<pr>19.8f %<vl>18.8f',
|
115
103
|
ky: hlx[:txid],
|
@@ -121,51 +109,34 @@ module Cns
|
|
121
109
|
)
|
122
110
|
end
|
123
111
|
|
124
|
-
# @return [
|
125
|
-
def
|
126
|
-
|
127
|
-
vnt = bqd[:nt].count
|
128
|
-
vtl = exd[:tl].count
|
129
|
-
vnl = bqd[:nl].count
|
130
|
-
|
131
|
-
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
|
132
|
-
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vtl, d: vnl, o: vtl == vnl ? 'OK' : 'NOK')}")
|
133
|
-
end
|
134
|
-
|
135
|
-
# @return [String] texto transacoes trades
|
136
|
-
def mtrades
|
137
|
-
return unless ops[:v] && novcdet.any?
|
138
|
-
|
139
|
-
puts("\ntrades data hora dt criacao tipo par btc eur")
|
140
|
-
novcdet.sort_by { |i| -i[:srx] }.each { |o| puts(formata_trades(o)) }
|
141
|
-
end
|
142
|
-
|
143
|
-
# @return [String] texto transacoes ledger
|
144
|
-
def mledger
|
145
|
-
return unless ops[:v] && novcdel.any?
|
146
|
-
|
147
|
-
puts("\nledger data hora tipo moe quantidade custo")
|
148
|
-
novcdel.sort_by { |i| -i[:srx] }.each { |o| puts(formata_ledger(o)) }
|
112
|
+
# @return [Boolean] mostra todas/novas transacoes
|
113
|
+
def show_all?
|
114
|
+
ops[:t] || false
|
149
115
|
end
|
150
116
|
|
151
|
-
#
|
117
|
+
# @param [Hash] itm recursos bitcoinde
|
118
|
+
# @return [Hash<BigDecimal>] moedas & sados
|
152
119
|
def pdea(itm)
|
153
120
|
itm.select { |k, _| EM.include?(k) }.transform_values { |o| o.merge(total_amount: o[:total_amount].to_d) }
|
154
121
|
end
|
155
122
|
|
156
|
-
#
|
157
|
-
|
158
|
-
|
123
|
+
# @param [Object] val time bitcoinde
|
124
|
+
# @return [Time] processa time (somtimes is string)
|
125
|
+
def ptm(val)
|
126
|
+
val.is_a?(String) ? Time.parse(val) : val
|
159
127
|
end
|
160
128
|
|
129
|
+
# @param [Hash] itm transacao bitcoinde
|
130
|
+
# @return [Hash] transaccao filtrada
|
161
131
|
def pdes(key, itm)
|
162
132
|
tym = ptm(itm[key])
|
163
133
|
itm.merge(srx: Integer(tym), key => tym)
|
164
134
|
end
|
165
135
|
|
166
|
-
#
|
167
|
-
|
168
|
-
|
136
|
+
# @param [Array<Hash>] htx trade bitcoinde
|
137
|
+
# @return [Array<Hash>] transaccao filtrada
|
138
|
+
def pdet(htx)
|
139
|
+
htx.map do |t|
|
169
140
|
pdes(:successfully_finished_at, t).merge(
|
170
141
|
trade_marked_as_paid_at: ptm(t[:trade_marked_as_paid_at]),
|
171
142
|
username: t[:trading_partner_information][:username],
|
@@ -176,10 +147,45 @@ module Cns
|
|
176
147
|
end
|
177
148
|
end
|
178
149
|
|
179
|
-
#
|
150
|
+
# @param [Array<Hash>] hlx ledger bitcoinde
|
151
|
+
# @return [Array<Hash>] transaccao filtrada
|
152
|
+
def pdel(hlx)
|
153
|
+
hlx.map { |t| pdes(:time, t).merge(qtd: (t[:tp] == 'withdrawal' ? -1 : 1) * t[:qt].to_d, nxid: t[:txid], fee: t[:fee].to_d, moe: t[:moe].upcase) }
|
154
|
+
end
|
180
155
|
|
181
|
-
|
182
|
-
|
156
|
+
# @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
|
157
|
+
def ded
|
158
|
+
@ded ||= {sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de)}
|
159
|
+
end
|
160
|
+
|
161
|
+
# @return [Array<String>] indices trades bigquery
|
162
|
+
def bqkyt
|
163
|
+
@bqkyt ||= show_all? ? [] : bqd[:nt].map { |t| t[:txid] }
|
164
|
+
end
|
165
|
+
|
166
|
+
# @return [Array<Integer>] indices ledger bigquery
|
167
|
+
def bqkyl
|
168
|
+
@bqkyl ||= show_all? ? [] : bqd[:nl].map { |l| l[:txid] }
|
169
|
+
end
|
170
|
+
|
171
|
+
# @return [Array<String>] lista txid trades novos
|
172
|
+
def kyt
|
173
|
+
@kyt ||= ded[:tt].map { |t| t[:trade_id] } - bqkyt
|
174
|
+
end
|
175
|
+
|
176
|
+
# @return [Array<Integer>] lista txid ledger novos
|
177
|
+
def kyl
|
178
|
+
@kyl ||= ded[:tl].map { |t| t[:txid] } - bqkyl
|
179
|
+
end
|
180
|
+
|
181
|
+
# @return [Array<Hash>] lista trades bitcoinde novos
|
182
|
+
def novcdet
|
183
|
+
@novcdet ||= ded[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
|
184
|
+
end
|
185
|
+
|
186
|
+
# @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
|
187
|
+
def novcdel
|
188
|
+
@novcdel ||= ded[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
183
189
|
end
|
184
190
|
end
|
185
191
|
end
|