cns 0.8.9 → 0.8.10
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 +2 -2
- data/lib/cns/bigquery.rb +4 -18
- data/lib/cns/bitcoinde.rb +29 -26
- data/lib/cns/etherscan.rb +184 -146
- data/lib/cns/greymass.rb +56 -53
- data/lib/cns/kraken.rb +24 -19
- 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: 867a92f29645226b50d14524ebe09fac049968d037d99427778742a92e8fba1c
|
4
|
+
data.tar.gz: '03930aae6c757152fcaf20f6c02c509819b6b53b0941e8f4ddfa9b05370c1d22'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e014d93d603bb89e74cbe9f17f814c2f717183d77c654688fba7417bc9c2685e1d318b01c013d341d69addba0793c9497e84a5e56bf30272dea76569a005e473
|
7
|
+
data.tar.gz: 86f502cca84614606f28f025723be61b0acfa289072590890b39aa1e6c4aa5f6e3ebaa5aab12f207eb4ac7751dac8d7656b19fc43ca54bb8e89d0b34226c51b8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cns (0.8.
|
4
|
+
cns (0.8.10)
|
5
5
|
curb
|
6
6
|
faraday
|
7
7
|
google-cloud-bigquery
|
@@ -148,7 +148,7 @@ GEM
|
|
148
148
|
rubocop-ast (>= 1.38.0, < 2.0)
|
149
149
|
ruby-progressbar (~> 1.7)
|
150
150
|
unicode-display_width (>= 2.4.0, < 4.0)
|
151
|
-
rubocop-ast (1.38.
|
151
|
+
rubocop-ast (1.38.1)
|
152
152
|
parser (>= 3.3.1.0)
|
153
153
|
rubocop-rake (0.7.1)
|
154
154
|
lint_roller (~> 1.1)
|
data/lib/cns/bigquery.rb
CHANGED
@@ -45,8 +45,8 @@ module Cns
|
|
45
45
|
def mtudo
|
46
46
|
apius.mresumo
|
47
47
|
apide.mresumo
|
48
|
-
|
49
|
-
|
48
|
+
apies.mresumo
|
49
|
+
apigm.mresumo
|
50
50
|
end
|
51
51
|
|
52
52
|
# mostra situacao completa entre kraken/etherscan & bigquery
|
@@ -183,26 +183,12 @@ module Cns
|
|
183
183
|
|
184
184
|
# @return [Kraken] API exchange kraken
|
185
185
|
def apius
|
186
|
-
@apius ||= Kraken.new(
|
187
|
-
{
|
188
|
-
sl: sql("select * from #{BD}.cuss").first,
|
189
|
-
nt: sql("select * from #{BD}.cust order by time,txid"),
|
190
|
-
nl: sql("select * from #{BD}.cusl order by time,txid")
|
191
|
-
},
|
192
|
-
ops
|
193
|
-
)
|
186
|
+
@apius ||= Kraken.new({ sl: sql("select * from #{BD}.cuss").first, nt: sql("select * from #{BD}.cust"), nl: sql("select * from #{BD}.cusl") }, ops)
|
194
187
|
end
|
195
188
|
|
196
189
|
# @return [Bitcoinde] API exchange bitcoinde
|
197
190
|
def apide
|
198
|
-
@apide ||= Bitcoinde.new(
|
199
|
-
{
|
200
|
-
sl: sql("select * from #{BD}.cdes").first,
|
201
|
-
nt: sql("select * from #{BD}.cdet order by time,txid"),
|
202
|
-
nl: sql("select * from #{BD}.cdel order by time,txid")
|
203
|
-
},
|
204
|
-
ops
|
205
|
-
)
|
191
|
+
@apide ||= Bitcoinde.new({ sl: sql("select * from #{BD}.cdes").first, nt: sql("select * from #{BD}.cdet"), nl: sql("select * from #{BD}.cdel") }, ops)
|
206
192
|
end
|
207
193
|
|
208
194
|
def tabelas_cus(src, str, ltb, prx = '')
|
data/lib/cns/bitcoinde.rb
CHANGED
@@ -30,16 +30,6 @@ module Cns
|
|
30
30
|
@exd ||= { sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de) }
|
31
31
|
end
|
32
32
|
|
33
|
-
# @return [Array<Hash>] lista trades bitcoinde novos
|
34
|
-
def novcdet
|
35
|
-
@novcdet ||= exd[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
|
36
|
-
end
|
37
|
-
|
38
|
-
# @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
|
39
|
-
def novcdel
|
40
|
-
@novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
41
|
-
end
|
42
|
-
|
43
33
|
# @return [String] texto saldos & transacoes & ajuste dias
|
44
34
|
def mresumo
|
45
35
|
puts("\nBITCOINDE\ntipo bitcoinde bigquery")
|
@@ -60,11 +50,11 @@ module Cns
|
|
60
50
|
end
|
61
51
|
|
62
52
|
def bqkyt
|
63
|
-
show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid] } || [])
|
53
|
+
@bqkyt ||= show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid] } || [])
|
64
54
|
end
|
65
55
|
|
66
56
|
def bqkyl
|
67
|
-
show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid] } || [])
|
57
|
+
@bqkyl ||= show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid] } || [])
|
68
58
|
end
|
69
59
|
|
70
60
|
# @return [Array<String>] lista txid dos trades novos
|
@@ -77,6 +67,16 @@ module Cns
|
|
77
67
|
@kyl ||= exd[:tl].map { |oex| oex[:txid] } - bqkyl
|
78
68
|
end
|
79
69
|
|
70
|
+
# @return [Array<Hash>] lista trades bitcoinde novos
|
71
|
+
def novcdet
|
72
|
+
@novcdet ||= exd[:tt].select { |obj| kyt.include?(obj[:trade_id]) }
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Array<Hash>] lista ledger (deposits + withdrawals) bitcoinde novos
|
76
|
+
def novcdel
|
77
|
+
@novcdel ||= exd[:tl].select { |obj| kyl.include?(obj[:txid]) }
|
78
|
+
end
|
79
|
+
|
80
80
|
# @param [String] moe codigo bitcoinde da moeda
|
81
81
|
# @param [Hash] hsx saldo bitcoinde da moeda
|
82
82
|
# @return [String] texto formatado saldos
|
@@ -134,31 +134,39 @@ module Cns
|
|
134
134
|
|
135
135
|
# @return [String] texto transacoes trades
|
136
136
|
def mtrades
|
137
|
-
return unless ops[:v] &&
|
137
|
+
return unless ops[:v] && novcdet.any?
|
138
138
|
|
139
139
|
puts("\ntrades data hora dt criacao tipo par qtd eur")
|
140
|
-
novcdet.sort_by { |
|
140
|
+
novcdet.sort_by { |i| -i[:srx] }.each { |o| puts(formata_trades(o)) }
|
141
141
|
end
|
142
142
|
|
143
143
|
# @return [String] texto transacoes ledger
|
144
144
|
def mledger
|
145
|
-
return unless ops[:v] &&
|
145
|
+
return unless ops[:v] && novcdel.any?
|
146
146
|
|
147
147
|
puts("\nledger data hora tipo moe quantidade custo")
|
148
|
-
novcdel.sort_by { |
|
148
|
+
novcdel.sort_by { |i| -i[:srx] }.each { |o| puts(formata_ledger(o)) }
|
149
149
|
end
|
150
150
|
|
151
151
|
# Processa os trades para garantir que as datas estejam no formato correto
|
152
152
|
def pdea(itm)
|
153
|
-
itm.select { |
|
153
|
+
itm.select { |k, _| EM.include?(k) }.transform_values { |o| o.merge(total_amount: o[:total_amount].to_d) }
|
154
|
+
end
|
155
|
+
|
156
|
+
# Processa time field somtimes is string
|
157
|
+
def ptm(itm)
|
158
|
+
itm.is_a?(String) ? Time.parse(itm) : itm
|
159
|
+
end
|
160
|
+
|
161
|
+
def pdes(key, itm)
|
162
|
+
tym = ptm(itm[key])
|
163
|
+
itm.merge(srx: Integer(tym), key => tym)
|
154
164
|
end
|
155
165
|
|
156
166
|
# Processa os trades para garantir que as datas estejam no formato correto
|
157
167
|
def pdet(itm)
|
158
168
|
itm.map do |t|
|
159
|
-
t.merge(
|
160
|
-
successfully_finished_at: srx = ptm(t[:successfully_finished_at]),
|
161
|
-
srx: Integer(srx),
|
169
|
+
pdes(:successfully_finished_at, t).merge(
|
162
170
|
trade_marked_as_paid_at: ptm(t[:trade_marked_as_paid_at]),
|
163
171
|
amount_currency_to_trade: t[:amount_currency_to_trade].to_d,
|
164
172
|
volume_currency_to_pay: t[:volume_currency_to_pay].to_d,
|
@@ -169,12 +177,7 @@ module Cns
|
|
169
177
|
|
170
178
|
# Processa os ledger entries para garantir que as datas estejam no formato correto
|
171
179
|
def pdel(itm)
|
172
|
-
itm.map { |t|
|
173
|
-
end
|
174
|
-
|
175
|
-
# Processa time field somtimes is string
|
176
|
-
def ptm(itm)
|
177
|
-
itm.is_a?(String) ? Time.parse(itm) : itm
|
180
|
+
itm.map { |t| pdes(:time, t).merge(qt: t[:qt].to_d, fee: t[:fee].to_d, moe: t[:moe].upcase) }
|
178
181
|
end
|
179
182
|
end
|
180
183
|
end
|
data/lib/cns/etherscan.rb
CHANGED
@@ -27,137 +27,9 @@ module Cns
|
|
27
27
|
@ops = pop.transform_keys(&:to_sym)
|
28
28
|
end
|
29
29
|
|
30
|
-
# @return [Array<Hash>] lista transacoes normais novas
|
31
|
-
def novnetht
|
32
|
-
@novnetht ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [Array<Hash>] lista transacoes internas novas
|
36
|
-
def novnethi
|
37
|
-
@novnethi ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
38
|
-
end
|
39
|
-
|
40
|
-
# @return [Array<Hash>] lista transacoes block novas
|
41
|
-
def novnethp
|
42
|
-
@novnethp ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [Array<Hash>] lista transacoes withdrawals novas
|
46
|
-
def novnethw
|
47
|
-
@novnethw ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
48
|
-
end
|
49
|
-
|
50
|
-
# @return [Array<Hash>] lista transacoes token novas
|
51
|
-
def novnethk
|
52
|
-
@novnethk ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [Array<String>] lista dos meus enderecos
|
56
|
-
def lax
|
57
|
-
@lax ||= bqd[:wb].map { |obj| obj[:ax] }
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
|
61
|
-
def bcd
|
62
|
-
@bcd ||= api.account_es(lax).map { |obj| base_bc(obj) }
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [Array<Hash>] todos os dados juntos bigquery & etherscan
|
66
|
-
def dados
|
67
|
-
@dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obc| obq[:ax] == obc[:ax] }.first) }
|
68
|
-
end
|
69
|
-
|
70
|
-
# @return [Array<Integer>] lista indices transacoes normais novas
|
71
|
-
def idt
|
72
|
-
@idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
|
73
|
-
end
|
74
|
-
|
75
|
-
# @return [Array<Integer>] lista indices transacoes internas novas
|
76
|
-
def idi
|
77
|
-
@idi ||= bcd.map { |obc| obc[:ix].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:ni].map { |obq| obq[:itx] })
|
78
|
-
end
|
79
|
-
|
80
|
-
# @return [Array<Integer>] lista indices transacoes block novas
|
81
|
-
def idp
|
82
|
-
@idp ||= bcd.map { |obc| obc[:px].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] })
|
83
|
-
end
|
84
|
-
|
85
|
-
# @return [Array<Integer>] lista indices transacoes withdrawals novas
|
86
|
-
def idw
|
87
|
-
@idw ||= bcd.map { |obc| obc[:wx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nw].map { |obq| obq[:itx] })
|
88
|
-
end
|
89
|
-
|
90
|
-
# @return [Array<Integer>] lista indices transacoes token novas
|
91
|
-
def idk
|
92
|
-
@idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nk].map { |obq| obq[:itx] })
|
93
|
-
end
|
94
|
-
|
95
|
-
# @example (see Apibc#account_es)
|
96
|
-
# @param [Hash] abc account etherscan
|
97
|
-
# @return [Hash] dados etherscan - address, saldo & transacoes
|
98
|
-
def base_bc(abc)
|
99
|
-
acc = abc[:account].downcase
|
100
|
-
{
|
101
|
-
ax: acc,
|
102
|
-
sl: abc[:balance].to_d / (10**18),
|
103
|
-
tx: ftik(acc, api.norml_es(acc)),
|
104
|
-
ix: ftik(acc, api.inter_es(acc)),
|
105
|
-
px: fppp(acc, api.block_es(acc)),
|
106
|
-
wx: fwww(acc, api.withw_es(acc)),
|
107
|
-
kx: ftik(acc, api.token_es(acc))
|
108
|
-
}
|
109
|
-
end
|
110
|
-
|
111
|
-
# @param [Hash] wbq wallet bigquery
|
112
|
-
# @param [Hash] hbc dados etherscan - address, saldo & transacoes
|
113
|
-
# @return [Hash] dados juntos bigquery & etherscan
|
114
|
-
def bq_bc(wbq, hbc)
|
115
|
-
{
|
116
|
-
id: wbq[:id],
|
117
|
-
ax: xbq = wbq[:ax],
|
118
|
-
bs: wbq[:sl],
|
119
|
-
bt: bqd[:nt].select { |ont| ont[:iax].casecmp?(xbq) },
|
120
|
-
bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
|
121
|
-
bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
|
122
|
-
bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
|
123
|
-
bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
|
124
|
-
es: hbc[:sl],
|
125
|
-
et: hbc[:tx],
|
126
|
-
ei: hbc[:ix],
|
127
|
-
ep: hbc[:px],
|
128
|
-
ew: hbc[:wx],
|
129
|
-
ek: hbc[:kx]
|
130
|
-
}
|
131
|
-
end
|
132
|
-
|
133
|
-
# @return [Array<Hash>] lista ordenada transacoes normais novas
|
134
|
-
def sortx
|
135
|
-
novnetht.sort_by { |itm| -itm[:srx] }
|
136
|
-
end
|
137
|
-
|
138
|
-
# @return [Array<Hash>] lista ordenada transacoes internas novas
|
139
|
-
def sorix
|
140
|
-
novnethi.sort_by { |itm| -itm[:srx] }
|
141
|
-
end
|
142
|
-
|
143
|
-
# @return [Array<Hash>] lista ordenada transacoes block novas
|
144
|
-
def sorpx
|
145
|
-
novnethp.sort_by { |itm| -itm[:itx] }
|
146
|
-
end
|
147
|
-
|
148
|
-
# @return [Array<Hash>] lista ordenada transacoes withdrawals novas
|
149
|
-
def sorwx
|
150
|
-
novnethw.sort_by { |itm| -itm[:itx] }
|
151
|
-
end
|
152
|
-
|
153
|
-
# @return [Array<Hash>] lista ordenada transacoes token novas
|
154
|
-
def sorkx
|
155
|
-
novnethk.sort_by { |itm| -itm[:srx] }
|
156
|
-
end
|
157
|
-
|
158
30
|
# @return [String] texto carteiras & transacoes & ajuste dias
|
159
31
|
def mresumo_simples
|
160
|
-
return unless dados.
|
32
|
+
return unless dados.any?
|
161
33
|
|
162
34
|
puts("\nid address etherscan bigquery")
|
163
35
|
dados.each { |obj| puts(formata_carteira_simples(obj)) }
|
@@ -171,7 +43,7 @@ module Cns
|
|
171
43
|
|
172
44
|
# @return [String] texto carteiras & transacoes & ajuste dias
|
173
45
|
def mresumo
|
174
|
-
return unless dados.
|
46
|
+
return unless dados.any?
|
175
47
|
|
176
48
|
puts("\nid address etherscan tn ti tb tk tw bigquery tn ti tb tk tw")
|
177
49
|
dados.each { |obj| puts(formata_carteira(obj)) }
|
@@ -183,6 +55,8 @@ module Cns
|
|
183
55
|
mconfiguracao_ajuste_dias
|
184
56
|
end
|
185
57
|
|
58
|
+
private
|
59
|
+
|
186
60
|
# @param [Hash] hjn dados juntos bigquery & etherscan
|
187
61
|
# @return [String] texto formatado duma carteira
|
188
62
|
def formata_carteira_simples(hjn)
|
@@ -224,7 +98,16 @@ module Cns
|
|
224
98
|
|
225
99
|
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
226
100
|
def ok?(hjn)
|
227
|
-
|
101
|
+
oks?(hjn) && okipw?(hjn) && hjn[:bt].count == hjn[:et].count && hjn[:bk].count == hjn[:ek].count
|
102
|
+
end
|
103
|
+
|
104
|
+
def okipw?(hjn)
|
105
|
+
oks?(hjn) && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bw].count == hjn[:ew].count
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
109
|
+
def oks?(hjn)
|
110
|
+
hjn[:es].round(6) == hjn[:bs].round(6)
|
228
111
|
end
|
229
112
|
|
230
113
|
# @example ether address inicio..fim
|
@@ -274,8 +157,8 @@ module Cns
|
|
274
157
|
# @return [String] texto formatado transacao token etherscan
|
275
158
|
def formata_tx_token(hkx)
|
276
159
|
format(
|
277
|
-
'%<hx>-
|
278
|
-
hx: formata_enderec1(hkx[:hash],
|
160
|
+
'%<hx>-20.20s %<fr>-15.15s %<to>-15.15s %<dt>10.10s %<vl>10.3f %<sy>-5.5s',
|
161
|
+
hx: formata_enderec1(hkx[:hash], 20),
|
279
162
|
fr: formata_enderec2(hkx[:from], 15),
|
280
163
|
to: formata_enderec2(hkx[:to], 15),
|
281
164
|
dt: hkx[:timeStamp].strftime('%F'),
|
@@ -306,7 +189,7 @@ module Cns
|
|
306
189
|
|
307
190
|
# @return [String] texto transacoes normais
|
308
191
|
def mtx_norml
|
309
|
-
return unless ops[:v] && novnetht.
|
192
|
+
return unless ops[:v] && novnetht.any?
|
310
193
|
|
311
194
|
puts("\ntx normal from to data valor")
|
312
195
|
sortx.each { |obj| puts(formata_tx_ti(obj)) }
|
@@ -314,7 +197,7 @@ module Cns
|
|
314
197
|
|
315
198
|
# @return [String] texto transacoes internas
|
316
199
|
def mtx_inter
|
317
|
-
return unless ops[:v] && novnethi.
|
200
|
+
return unless ops[:v] && novnethi.any?
|
318
201
|
|
319
202
|
puts("\ntx intern from to data valor")
|
320
203
|
sorix.each { |obj| puts(formata_tx_ti(obj)) }
|
@@ -322,7 +205,7 @@ module Cns
|
|
322
205
|
|
323
206
|
# @return [String] texto transacoes block
|
324
207
|
def mtx_block
|
325
|
-
return unless ops[:v] && novnethp.
|
208
|
+
return unless ops[:v] && novnethp.any?
|
326
209
|
|
327
210
|
puts("\ntx block address data valor")
|
328
211
|
sorpx.each { |obj| puts(formata_tx_block(obj)) }
|
@@ -330,15 +213,15 @@ module Cns
|
|
330
213
|
|
331
214
|
# @return [String] texto transacoes token
|
332
215
|
def mtx_token
|
333
|
-
return unless ops[:v] && novnethk.
|
216
|
+
return unless ops[:v] && novnethk.any?
|
334
217
|
|
335
|
-
puts("\ntx token
|
218
|
+
puts("\ntx token from to data valor moeda")
|
336
219
|
sorkx.each { |obj| puts(formata_tx_token(obj)) }
|
337
220
|
end
|
338
221
|
|
339
222
|
# @return [String] texto transacoes withdrawals
|
340
223
|
def mtx_withw
|
341
|
-
return unless ops[:v] && novnethw.
|
224
|
+
return unless ops[:v] && novnethw.any?
|
342
225
|
|
343
226
|
puts("\nwithdrawal validator data valor")
|
344
227
|
sorwx.each { |obj| puts(formata_tx_withw(obj)) }
|
@@ -346,20 +229,175 @@ module Cns
|
|
346
229
|
|
347
230
|
# @return [String] texto configuracao ajuste dias das transacoes (normais & token)
|
348
231
|
def mconfiguracao_ajuste_dias
|
349
|
-
puts("\najuste dias transacoes normais \n-h=#{sortx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnetht.
|
350
|
-
puts("\najuste dias transacoes internas \n-h=#{sorix.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethi.
|
351
|
-
puts("\najuste dias transacoes block \n-h=#{sorpx.map { |obj| "#{obj[:blockNumber]}:0" }.join(' ')}") if novnethp.
|
352
|
-
puts("\najuste dias transacoes token \n-h=#{sorkx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethk.
|
353
|
-
puts("\najuste dias transacoes withdrawals\n-h=#{sorwx.map { |obj| "#{obj[:withdrawalIndex]}:0" }.join(' ')}") if novnethw.
|
232
|
+
puts("\najuste dias transacoes normais \n-h=#{sortx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnetht.any?
|
233
|
+
puts("\najuste dias transacoes internas \n-h=#{sorix.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethi.any?
|
234
|
+
puts("\najuste dias transacoes block \n-h=#{sorpx.map { |obj| "#{obj[:blockNumber]}:0" }.join(' ')}") if novnethp.any?
|
235
|
+
puts("\najuste dias transacoes token \n-h=#{sorkx.map { |obj| "#{obj[:hash]}:0" }.join(' ')}") if novnethk.any?
|
236
|
+
puts("\najuste dias transacoes withdrawals\n-h=#{sorwx.map { |obj| "#{obj[:withdrawalIndex]}:0" }.join(' ')}") if novnethw.any?
|
354
237
|
end
|
355
238
|
|
356
|
-
|
239
|
+
# @return [Array<String>] lista dos meus enderecos
|
240
|
+
def lax
|
241
|
+
@lax ||= bqd[:wb].map { |obj| obj[:ax] }
|
242
|
+
end
|
243
|
+
|
244
|
+
# @return [Array<Hash>] todos os dados etherscan - saldos & transacoes
|
245
|
+
def bcd
|
246
|
+
@bcd ||= api.account_es(lax).map { |obj| base_bc(obj) }
|
247
|
+
end
|
248
|
+
|
249
|
+
# @return [Array<Hash>] todos os dados juntos bigquery & etherscan
|
250
|
+
def dados
|
251
|
+
@dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obc| obq[:ax] == obc[:ax] }.first) }
|
252
|
+
end
|
253
|
+
|
254
|
+
def show_all?
|
255
|
+
ops[:t] || false
|
256
|
+
end
|
257
|
+
|
258
|
+
def bqidt
|
259
|
+
@bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
|
260
|
+
end
|
261
|
+
|
262
|
+
# @return [Array<Integer>] lista indices transacoes novas
|
263
|
+
def idt
|
264
|
+
@idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
265
|
+
end
|
266
|
+
|
267
|
+
def bqidi
|
268
|
+
@bqidi ||= show_all? ? [] : (bqd[:ni]&.map { |i| i[:itx] } || [])
|
269
|
+
end
|
270
|
+
|
271
|
+
# @return [Array<Integer>] lista indices transacoes novas
|
272
|
+
def idi
|
273
|
+
@idi ||= bcd.map { |o| o[:ix].map { |i| i[:itx] } }.flatten - bqidi
|
274
|
+
end
|
275
|
+
|
276
|
+
def bqidp
|
277
|
+
@bqidp ||= show_all? ? [] : (bqd[:np]&.map { |i| i[:itx] } || [])
|
278
|
+
end
|
279
|
+
|
280
|
+
# @return [Array<Integer>] lista indices transacoes novas
|
281
|
+
def idp
|
282
|
+
@idp ||= bcd.map { |o| o[:px].map { |i| i[:itx] } }.flatten - bqidp
|
283
|
+
end
|
284
|
+
|
285
|
+
def bqidw
|
286
|
+
@bqidw ||= show_all? ? [] : (bqd[:nw]&.map { |i| i[:itx] } || [])
|
287
|
+
end
|
288
|
+
|
289
|
+
# @return [Array<Integer>] lista indices transacoes novas
|
290
|
+
def idw
|
291
|
+
@idw ||= bcd.map { |o| o[:wx].map { |i| i[:itx] } }.flatten - bqidw
|
292
|
+
end
|
293
|
+
|
294
|
+
def bqidk
|
295
|
+
@bqidk ||= show_all? ? [] : (bqd[:nk]&.map { |i| i[:itx] } || [])
|
296
|
+
end
|
297
|
+
|
298
|
+
# @return [Array<Integer>] lista indices transacoes novas
|
299
|
+
def idk
|
300
|
+
@idk ||= bcd.map { |o| o[:kx].map { |i| i[:itx] } }.flatten - bqidk
|
301
|
+
end
|
302
|
+
|
303
|
+
# @example (see Apibc#account_es)
|
304
|
+
# @param [Hash] abc account etherscan
|
305
|
+
# @return [Hash] dados etherscan - address, saldo & transacoes
|
306
|
+
def base_bc(abc)
|
307
|
+
acc = abc[:account].downcase
|
308
|
+
{
|
309
|
+
ax: acc,
|
310
|
+
sl: abc[:balance].to_d / (10**18),
|
311
|
+
tx: ftik(acc, api.norml_es(acc)),
|
312
|
+
ix: ftik(acc, api.inter_es(acc)),
|
313
|
+
px: fppp(acc, api.block_es(acc)),
|
314
|
+
wx: fwww(acc, api.withw_es(acc)),
|
315
|
+
kx: ftik(acc, api.token_es(acc))
|
316
|
+
}
|
317
|
+
end
|
318
|
+
|
319
|
+
# @param [Hash] wbq wallet bigquery
|
320
|
+
# @param [Hash] hbc dados etherscan - address, saldo & transacoes
|
321
|
+
# @return [Hash] dados juntos bigquery & etherscan
|
322
|
+
def bq_bc(wbq, hbc)
|
323
|
+
{
|
324
|
+
id: wbq[:id],
|
325
|
+
ax: xbq = wbq[:ax],
|
326
|
+
bs: wbq[:sl],
|
327
|
+
bt: bqd[:nt].select { |ont| ont[:iax].casecmp?(xbq) },
|
328
|
+
bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
|
329
|
+
bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
|
330
|
+
bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
|
331
|
+
bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
|
332
|
+
es: hbc[:sl],
|
333
|
+
et: hbc[:tx],
|
334
|
+
ei: hbc[:ix],
|
335
|
+
ep: hbc[:px],
|
336
|
+
ew: hbc[:wx],
|
337
|
+
ek: hbc[:kx]
|
338
|
+
}
|
339
|
+
end
|
340
|
+
|
341
|
+
# @return [Array<Hash>] lista transacoes normais novas
|
342
|
+
def novnetht
|
343
|
+
@novnetht ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
344
|
+
end
|
345
|
+
|
346
|
+
# @return [Array<Hash>] lista transacoes internas novas
|
347
|
+
def novnethi
|
348
|
+
@novnethi ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
349
|
+
end
|
350
|
+
|
351
|
+
# @return [Array<Hash>] lista transacoes block novas
|
352
|
+
def novnethp
|
353
|
+
@novnethp ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
354
|
+
end
|
355
|
+
|
356
|
+
# @return [Array<Hash>] lista transacoes withdrawals novas
|
357
|
+
def novnethw
|
358
|
+
@novnethw ||= bcd.map { |obc| obc[:wx].select { |obj| idw.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
359
|
+
end
|
360
|
+
|
361
|
+
# @return [Array<Hash>] lista transacoes token novas
|
362
|
+
def novnethk
|
363
|
+
@novnethk ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten.uniq { |itm| itm[:itx] }
|
364
|
+
end
|
365
|
+
|
366
|
+
# @return [Array<Hash>] lista ordenada transacoes normais novas
|
367
|
+
def sortx
|
368
|
+
novnetht.sort_by { |i| -i[:srx] }
|
369
|
+
end
|
370
|
+
|
371
|
+
# @return [Array<Hash>] lista ordenada transacoes internas novas
|
372
|
+
def sorix
|
373
|
+
novnethi.sort_by { |i| -i[:srx] }
|
374
|
+
end
|
375
|
+
|
376
|
+
# @return [Array<Hash>] lista ordenada transacoes block novas
|
377
|
+
def sorpx
|
378
|
+
novnethp.sort_by { |i| -i[:itx] }
|
379
|
+
end
|
380
|
+
|
381
|
+
# @return [Array<Hash>] lista ordenada transacoes withdrawals novas
|
382
|
+
def sorwx
|
383
|
+
novnethw.sort_by { |i| -i[:itx] }
|
384
|
+
end
|
385
|
+
|
386
|
+
# @return [Array<Hash>] lista ordenada transacoes token novas
|
387
|
+
def sorkx
|
388
|
+
novnethk.sort_by { |i| -i[:srx] }
|
389
|
+
end
|
390
|
+
|
391
|
+
def pess(itm)
|
392
|
+
tym = Integer(itm[:timeStamp])
|
393
|
+
itm.merge(srx: tym, timeStamp: Time.at(tym))
|
394
|
+
end
|
357
395
|
|
358
396
|
# @param add (see Apibc#norml_es)
|
359
397
|
# @param [Array<Hash>] ary lista transacoes/token events
|
360
398
|
# @return [Array<Hash>] lista transacoes/token events filtrada
|
361
399
|
def ftik(add, ary)
|
362
|
-
ary.map { |o| o.merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d
|
400
|
+
ary.map { |o| pess(o).merge(itx: String(o[:hash]), iax: add, value: o[:value].to_d) }
|
363
401
|
end
|
364
402
|
|
365
403
|
# @param add (see Apibc#norml_es)
|
data/lib/cns/greymass.rb
CHANGED
@@ -25,57 +25,9 @@ module Cns
|
|
25
25
|
@ops = pop.transform_keys(&:to_sym)
|
26
26
|
end
|
27
27
|
|
28
|
-
# @return [Array<Hash>] lista transacoes novas
|
29
|
-
def novneost
|
30
|
-
@novneost ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [Array<String>] lista dos meus enderecos
|
34
|
-
def lax
|
35
|
-
@lax ||= bqd[:wb].map { |obj| obj[:ax] }
|
36
|
-
end
|
37
|
-
|
38
|
-
# @return [Array<Hash>] todos os dados greymass - saldos & transacoes
|
39
|
-
def bcd
|
40
|
-
@bcd ||= bqd[:wb].map { |obj| base_bc(obj) }
|
41
|
-
end
|
42
|
-
|
43
|
-
# @return [Array<Hash>] todos os dados juntos bigquery & greymass
|
44
|
-
def dados
|
45
|
-
@dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obj| obq[:ax] == obj[:ax] }.first) }
|
46
|
-
end
|
47
|
-
|
48
|
-
# @return [Array<Integer>] lista indices transacoes novas
|
49
|
-
def idt
|
50
|
-
@idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] })
|
51
|
-
end
|
52
|
-
|
53
|
-
# @example (see Apibc#account_gm)
|
54
|
-
# @param [Hash] wbq wallet bigquery
|
55
|
-
# @return [Hash] dados greymass - address, saldo & transacoes
|
56
|
-
def base_bc(wbq)
|
57
|
-
xbq = wbq[:ax]
|
58
|
-
{ ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq)) }
|
59
|
-
end
|
60
|
-
|
61
|
-
# @param wbq (see base_bc)
|
62
|
-
# @param [Hash] hbc dados greymass - address, saldo & transacoes
|
63
|
-
# @return [Hash] dados juntos bigquery & greymass
|
64
|
-
def bq_bc(wbq, hbc)
|
65
|
-
xbq = wbq[:ax]
|
66
|
-
{
|
67
|
-
id: wbq[:id],
|
68
|
-
ax: xbq,
|
69
|
-
bs: wbq[:sl],
|
70
|
-
bt: bqd[:nt].select { |obj| obj[:iax] == xbq },
|
71
|
-
es: hbc[:sl],
|
72
|
-
et: hbc[:tx]
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
28
|
# @return [String] texto carteiras & transacoes & ajuste dias
|
77
29
|
def mresumo
|
78
|
-
return unless dados.
|
30
|
+
return unless dados.any?
|
79
31
|
|
80
32
|
puts("\naddress greymass ntx bigquery ntx")
|
81
33
|
dados.each { |obj| puts(formata_carteira(obj)) }
|
@@ -83,6 +35,8 @@ module Cns
|
|
83
35
|
mconfiguracao_ajuste_dias
|
84
36
|
end
|
85
37
|
|
38
|
+
private
|
39
|
+
|
86
40
|
# @param [Hash] hjn dados juntos bigquery & greymass
|
87
41
|
# @return [String] texto formatado duma carteira
|
88
42
|
def formata_carteira(hjn)
|
@@ -121,7 +75,7 @@ module Cns
|
|
121
75
|
|
122
76
|
# @return [String] texto transacoes
|
123
77
|
def mtransacoes_novas
|
124
|
-
return unless ops[:v] && novneost.
|
78
|
+
return unless ops[:v] && novneost.any?
|
125
79
|
|
126
80
|
puts("\nsequence num from to accao data valor moeda")
|
127
81
|
soreost.each { |obj| puts(formata_ledger(obj)) }
|
@@ -129,16 +83,65 @@ module Cns
|
|
129
83
|
|
130
84
|
# @return [String] texto configuracao ajuste dias das transacoes
|
131
85
|
def mconfiguracao_ajuste_dias
|
132
|
-
return unless novneost.
|
86
|
+
return unless novneost.any?
|
133
87
|
|
134
88
|
puts("\nstring ajuste dias\n-h=#{soreost.map { |obj| "#{obj[:itx]}:0" }.join(' ')}")
|
135
89
|
end
|
136
90
|
|
137
|
-
|
91
|
+
# @return [Array<Hash>] todos os dados greymass - saldos & transacoes
|
92
|
+
def bcd
|
93
|
+
@bcd ||= bqd[:wb].map { |obj| base_bc(obj) }
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [Array<Hash>] todos os dados juntos bigquery & greymass
|
97
|
+
def dados
|
98
|
+
@dados ||= bqd[:wb].map { |obq| bq_bc(obq, bcd.select { |obj| obq[:ax] == obj[:ax] }.first) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def show_all?
|
102
|
+
ops[:t] || false
|
103
|
+
end
|
104
|
+
|
105
|
+
def bqidt
|
106
|
+
@bqidt ||= show_all? ? [] : (bqd[:nt]&.map { |i| i[:itx] } || [])
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [Array<Integer>] lista indices transacoes novas
|
110
|
+
def idt
|
111
|
+
@idt ||= bcd.map { |o| o[:tx].map { |i| i[:itx] } }.flatten - bqidt
|
112
|
+
end
|
113
|
+
|
114
|
+
# @example (see Apibc#account_gm)
|
115
|
+
# @param [Hash] wbq wallet bigquery
|
116
|
+
# @return [Hash] dados greymass - address, saldo & transacoes
|
117
|
+
def base_bc(wbq)
|
118
|
+
xbq = wbq[:ax]
|
119
|
+
{ ax: xbq, sl: peosa(xbq).reduce(:+), tx: peost(xbq, api.ledger_gm(xbq)) }
|
120
|
+
end
|
121
|
+
|
122
|
+
# @param wbq (see base_bc)
|
123
|
+
# @param [Hash] hbc dados greymass - address, saldo & transacoes
|
124
|
+
# @return [Hash] dados juntos bigquery & greymass
|
125
|
+
def bq_bc(wbq, hbc)
|
126
|
+
xbq = wbq[:ax]
|
127
|
+
{
|
128
|
+
id: wbq[:id],
|
129
|
+
ax: xbq,
|
130
|
+
bs: wbq[:sl],
|
131
|
+
bt: bqd[:nt].select { |obj| obj[:iax] == xbq },
|
132
|
+
es: hbc[:sl],
|
133
|
+
et: hbc[:tx]
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
# @return [Array<Hash>] lista transacoes novas
|
138
|
+
def novneost
|
139
|
+
@novneost ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten
|
140
|
+
end
|
138
141
|
|
139
142
|
# @return [Array<Hash>] lista ordenada transacoes
|
140
143
|
def soreost
|
141
|
-
novneost.sort_by { |
|
144
|
+
novneost.sort_by { |i| -i[:itx] }
|
142
145
|
end
|
143
146
|
|
144
147
|
# @return [Array<BigDecimal>] lista recursos - liquido, net, spu
|
data/lib/cns/kraken.rb
CHANGED
@@ -30,16 +30,6 @@ module Cns
|
|
30
30
|
@exd ||= { sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us) }
|
31
31
|
end
|
32
32
|
|
33
|
-
# @return [Hash] trades kraken novos
|
34
|
-
def novcust
|
35
|
-
@novcust ||= exd[:kt].slice(*kyt)
|
36
|
-
end
|
37
|
-
|
38
|
-
# @return [Hash] ledger kraken novos
|
39
|
-
def novcusl
|
40
|
-
@novcusl ||= exd[:kl].slice(*kyl)
|
41
|
-
end
|
42
|
-
|
43
33
|
# @return [String] texto saldos & transacoes & ajuste dias
|
44
34
|
def mresumo
|
45
35
|
puts("\nKRAKEN\ntipo kraken bigquery")
|
@@ -60,11 +50,11 @@ module Cns
|
|
60
50
|
end
|
61
51
|
|
62
52
|
def bqkyt
|
63
|
-
show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid].to_sym } || [])
|
53
|
+
@bqkyt ||= show_all? ? [] : (bqd[:nt]&.map { |t| t[:txid].to_sym } || [])
|
64
54
|
end
|
65
55
|
|
66
56
|
def bqkyl
|
67
|
-
show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid].to_sym } || [])
|
57
|
+
@bqkyl ||= show_all? ? [] : (bqd[:nl]&.map { |l| l[:txid].to_sym } || [])
|
68
58
|
end
|
69
59
|
|
70
60
|
# @return [Array<String>] lista txid dos trades novos
|
@@ -77,6 +67,16 @@ module Cns
|
|
77
67
|
@kyl ||= exd[:kl].keys - bqkyl
|
78
68
|
end
|
79
69
|
|
70
|
+
# @return [Hash] trades kraken novos
|
71
|
+
def novcust
|
72
|
+
@novcust ||= exd[:kt].slice(*kyt)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Hash] ledger kraken novos
|
76
|
+
def novcusl
|
77
|
+
@novcusl ||= exd[:kl].slice(*kyl)
|
78
|
+
end
|
79
|
+
|
80
80
|
# @example (see Apice#account_us)
|
81
81
|
# @param [String] moe codigo kraken da moeda
|
82
82
|
# @param [BigDecimal] sal saldo kraken da moeda
|
@@ -136,33 +136,38 @@ module Cns
|
|
136
136
|
|
137
137
|
# @return [String] texto transacoes trades
|
138
138
|
def mtrades
|
139
|
-
return unless ops[:v] && novcust.
|
139
|
+
return unless ops[:v] && novcust.any?
|
140
140
|
|
141
141
|
puts("\ntrade data hora tipo par preco volume custo")
|
142
|
-
novcust.sort_by { |
|
142
|
+
novcust.sort_by { |_, v| -v[:srx] }.each { |i, t| puts(formata_trades(i, t)) }
|
143
143
|
end
|
144
144
|
|
145
145
|
# @return [String] texto transacoes ledger
|
146
146
|
def mledger
|
147
|
-
return unless ops[:v] && novcusl.
|
147
|
+
return unless ops[:v] && novcusl.any?
|
148
148
|
|
149
149
|
puts("\nledger data hora tipo moeda quantidade custo")
|
150
|
-
novcusl.sort_by { |
|
150
|
+
novcusl.sort_by { |_, v| -v[:srx] }.each { |i, t| puts(formata_ledger(i, t)) }
|
151
151
|
end
|
152
152
|
|
153
153
|
# Processa os trades para garantir que as datas estejam no formato correto
|
154
154
|
def pusa(itm)
|
155
|
-
itm.select { |
|
155
|
+
itm.select { |k, _| EM.include?(k) }.transform_values { |v| v.to_d }
|
156
|
+
end
|
157
|
+
|
158
|
+
def puss(itm)
|
159
|
+
tym = Integer(itm[:time])
|
160
|
+
itm.merge(srx: tym, time: Time.at(tym))
|
156
161
|
end
|
157
162
|
|
158
163
|
# Processa os trades para garantir que as datas estejam no formato correto
|
159
164
|
def pust(itm)
|
160
|
-
itm.transform_values { |t|
|
165
|
+
itm.transform_values { |t| puss(t).merge(pair: t[:pair].upcase, price: t[:price].to_d, vol: t[:vol].to_d, cost: t[:cost].to_d) }
|
161
166
|
end
|
162
167
|
|
163
168
|
# Processa os ledger entries para garantir que as datas estejam no formato correto
|
164
169
|
def pusl(itm)
|
165
|
-
itm.transform_values { |t|
|
170
|
+
itm.transform_values { |t| puss(t).merge(asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
|
166
171
|
end
|
167
172
|
end
|
168
173
|
end
|
data/lib/cns/version.rb
CHANGED