cns 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @author Hernani Rodrigues Vaz
4
+ module Cns
5
+ # classe para processar transacoes do greymass
6
+ class Greymass
7
+ # @return [String] texto carteiras & transacoes & ajuste dias
8
+ def mostra_resumo
9
+ return unless dados.count.positive?
10
+
11
+ puts("\naddress greymass ntx bigquery ntx")
12
+ dados.each { |e| puts(formata_carteira(e)) }
13
+ mostra_transacoes_novas
14
+ mostra_configuracao_ajuste_dias
15
+ end
16
+
17
+ # @param [Hash] hjn dados juntos bigquery & greymass
18
+ # @return [String] texto formatado duma carteira
19
+ def formata_carteira(hjn)
20
+ format(
21
+ '%<s1>-12.12s %<v1>14.4f %<n1>4i %<v2>14.4f %<n2>4i %<ok>-3s',
22
+ s1: hjn[:ax],
23
+ v1: hjn[:es],
24
+ n1: hjn[:et].count,
25
+ v2: hjn[:bs],
26
+ n2: hjn[:bt].count,
27
+ ok: ok?(hjn) ? 'OK' : 'NOK'
28
+ )
29
+ end
30
+
31
+ # @param (see formata_carteira)
32
+ # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
33
+ def ok?(hjn)
34
+ hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
35
+ end
36
+
37
+ # @example (see Apibc#ledger_gm)
38
+ # @param [Hash] hlx ledger greymass
39
+ # @return [String] texto formatado ledger greymass
40
+ def formata_ledger(hlx)
41
+ format(
42
+ '%<bn>12i %<fr>-12.12s %<to>-12.12s %<ac>-10.10s %<dt>10.10s %<vl>12.4f %<sy>-6.6s',
43
+ bn: hlx[:itx],
44
+ fr: act_data(hlx)[:from],
45
+ to: act_data(hlx)[:to],
46
+ ac: act(hlx)[:name],
47
+ dt: Date.parse(hlx[:block_time]),
48
+ vl: act_data_quantity(hlx).to_d,
49
+ sy: act_data_quantity(hlx)[/[[:upper:]]+/]
50
+ )
51
+ end
52
+
53
+ # @param (see formata_ledger)
54
+ # @return [Hash] dados da acao
55
+ def act(hlx)
56
+ hlx[:action_trace][:act]
57
+ end
58
+
59
+ # @param (see formata_ledger)
60
+ # @return [Hash] dados da acao
61
+ def act_data(hlx)
62
+ act(hlx)[:data]
63
+ end
64
+
65
+ # @param (see formata_ledger)
66
+ # @return [String] dados da quantidade
67
+ def act_data_quantity(hlx)
68
+ act_data(hlx)[:quantity].to_s
69
+ end
70
+
71
+ # @return [String] texto transacoes
72
+ def mostra_transacoes_novas
73
+ return unless ops[:v] && novax.count.positive?
74
+
75
+ puts("\nsequence num from to accao data valor moeda")
76
+ sorax.each { |e| puts(formata_ledger(e)) }
77
+ end
78
+
79
+ # @return [String] texto configuracao ajuste dias das transacoes
80
+ def mostra_configuracao_ajuste_dias
81
+ return unless novax.count.positive?
82
+
83
+ puts("\nstring ajuste dias\n-h=#{sorax.map { |e| "#{e[:itx]}:0" }.join(' ')}")
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('bigdecimal/util')
4
+
5
+ # @author Hernani Rodrigues Vaz
6
+ module Cns
7
+ # classe para processar transacoes trades/ledger do kraken
8
+ class Kraken
9
+ # @return [Apius] API kraken
10
+ attr_reader :api
11
+ # @return [Array<Hash>] todos os dados bigquery
12
+ attr_reader :bqd
13
+ # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
14
+ attr_reader :ops
15
+
16
+ # @param [Hash] dad todos os dados bigquery
17
+ # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
18
+ # @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
19
+ # @option pop [Boolean] :v (false) mostra dados transacoes trades & ledger?
20
+ # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
21
+ # @return [Kraken] API kraken - obter saldos & transacoes trades e ledger
22
+ def initialize(dad, pop)
23
+ @api = Apice.new
24
+ @bqd = dad
25
+ @ops = pop
26
+ end
27
+
28
+ # @return [Hash] trades kraken novos
29
+ def trades
30
+ @trades ||= exd[:kt].select { |k, _| kyt.include?(k) }
31
+ end
32
+
33
+ # @return [Hash] ledger kraken novos
34
+ def ledger
35
+ @ledger ||= exd[:kl].select { |k, _| kyl.include?(k) }
36
+ end
37
+
38
+ # @return [String] texto saldos & transacoes & ajuste dias
39
+ def mostra_resumo
40
+ puts("\nKRAKEN\ntipo kraken bigquery")
41
+ exd[:sl].each { |k, v| puts(formata_saldos(k, v)) }
42
+ mostra_totais
43
+
44
+ mostra_trades
45
+ mostra_ledger
46
+ return if trades.empty?
47
+
48
+ puts("\nstring ajuste dias dos trades\n-h=#{kyt.map { |e| "#{e}:0" }.join(' ')}")
49
+ end
50
+
51
+ # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
52
+ def exd
53
+ @exd ||= {
54
+ sl: api.account_us,
55
+ kt: api.trades_us,
56
+ kl: api.ledger_us
57
+ }
58
+ end
59
+
60
+ # @return [Array<String>] lista txid dos trades novos
61
+ def kyt
62
+ @kyt ||= exd[:kt].keys - (ops[:t] ? [] : bqd[:nt].map { |e| e[:txid].to_sym })
63
+ end
64
+
65
+ # @return [Array<String>] lista txid dos ledger novos
66
+ def kyl
67
+ @kyl ||= exd[:kl].keys - (ops[:t] ? [] : bqd[:nl].map { |e| e[:txid].to_sym })
68
+ end
69
+
70
+ # @example (see Apice#account_us)
71
+ # @param [String] moe codigo kraken da moeda
72
+ # @param [BigDecimal] sal saldo kraken da moeda
73
+ # @return [String] texto formatado saldos
74
+ def formata_saldos(moe, sal)
75
+ t = bqd[:sl][moe.downcase.to_sym].to_d
76
+ format(
77
+ '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
78
+ mo: moe.upcase,
79
+ kr: sal.to_d,
80
+ bq: t,
81
+ ok: t == sal.to_d ? 'OK' : 'NOK'
82
+ )
83
+ end
84
+
85
+ # @example (see Apice#trades_us)
86
+ # @param (see Bigquery#ust_val1)
87
+ # @return [String] texto formatado trade
88
+ def formata_trades(idx, htx)
89
+ format(
90
+ '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-8.8s %<pr>8.2f %<vl>15.7f %<co>8.2f',
91
+ ky: idx,
92
+ dt: Time.at(htx[:time]),
93
+ ty: "#{htx[:type]}/#{htx[:ordertype]}",
94
+ mo: htx[:pair].upcase,
95
+ pr: htx[:price].to_d,
96
+ vl: htx[:vol].to_d,
97
+ co: htx[:cost].to_d
98
+ )
99
+ end
100
+
101
+ # @example (see Apice#ledger_us)
102
+ # @param (see Bigquery#usl_val)
103
+ # @return [String] texto formatado ledger
104
+ def formata_ledger(idx, hlx)
105
+ format(
106
+ '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-4.4s %<pr>18.7f %<vl>18.7f',
107
+ ky: idx,
108
+ dt: Time.at(hlx[:time]),
109
+ ty: hlx[:type],
110
+ mo: hlx[:asset].upcase,
111
+ pr: hlx[:amount].to_d,
112
+ vl: hlx[:fee].to_d
113
+ )
114
+ end
115
+
116
+ # @return [String] texto totais numero de transacoes
117
+ def mostra_totais
118
+ a = exd[:kt].count
119
+ b = bqd[:nt].count
120
+ c = exd[:kl].count
121
+ d = bqd[:nl].count
122
+
123
+ puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: a, b: b, o: a == b ? 'OK' : 'NOK')}")
124
+ puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: c, d: d, o: c == d ? 'OK' : 'NOK')}")
125
+ end
126
+
127
+ # @return [String] texto transacoes trades
128
+ def mostra_trades
129
+ return unless ops[:v] && trades.count.positive?
130
+
131
+ puts("\ntrade data hora tipo par ---preco ---------volume ---custo")
132
+ trades.sort { |a, b| b[1][:time] <=> a[1][:time] }.each { |k, v| puts(formata_trades(k, v)) }
133
+ end
134
+
135
+ # @return [String] texto transacoes ledger
136
+ def mostra_ledger
137
+ return unless ops[:v] && ledger.count.positive?
138
+
139
+ puts("\nledger data hora tipo moeda -------quantidade -------------custo")
140
+ ledger.sort { |a, b| b[1][:time] <=> a[1][:time] }.each { |k, v| puts(formata_ledger(k, v)) }
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('bigdecimal/util')
4
+
5
+ # @author Hernani Rodrigues Vaz
6
+ module Cns
7
+ # classe para processar transacoes ledger do paymium
8
+ class Paymium
9
+ # @return [Apius] API paymium
10
+ attr_reader :api
11
+ # @return [Array<Hash>] todos os dados bigquery
12
+ attr_reader :bqd
13
+ # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
14
+ attr_reader :ops
15
+
16
+ # @param [Hash] dad todos os dados bigquery
17
+ # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
18
+ # @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
19
+ # @option pop [Boolean] :v (false) mostra dados transacoes trades & ledger?
20
+ # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
21
+ # @return [Paymium] API paymium - obter saldos & transacoes ledger
22
+ def initialize(dad, pop)
23
+ @api = Apice.new
24
+ @bqd = dad
25
+ @ops = pop
26
+ end
27
+
28
+ # @return [Array<Hash>] lista ledger paymium novos
29
+ def ledger
30
+ @ledger ||= exd[:kl].map { |h| h[:account_operations].select { |o| kyl.include?(o[:uuid]) } }.flatten
31
+ end
32
+
33
+ # @return [String] texto saldos & transacoes & ajuste dias
34
+ def mostra_resumo
35
+ puts("\nPAYMIUM\ntipo paymium bigquery")
36
+ puts(formata_saldos(:btc))
37
+ puts(formata_saldos(:eur))
38
+ mostra_totais
39
+
40
+ mostra_ledger
41
+ return unless ledger.count.positive?
42
+
43
+ puts("\nstring ajuste dias da ledger\n-h=#{kyl.map { |e| "#{e}:0" }.join(' ')}")
44
+ end
45
+
46
+ # @return [Hash] dados exchange paymium - saldos & transacoes ledger
47
+ def exd
48
+ @exd ||= {
49
+ sl: api.account_fr,
50
+ kl: api.ledger_fr
51
+ }
52
+ end
53
+
54
+ # @return [Array<String>] lista txid dos ledger novos
55
+ def kyl
56
+ @kyl ||= exd[:kl].map { |h| h[:account_operations].map { |o| o[:uuid] } }.flatten -
57
+ (ops[:t] ? [] : bqd[:nl].map { |e| e[:txid] })
58
+ end
59
+
60
+ # @example (see Apice#account_fr)
61
+ # @param [Symbol] bqm symbol paymium da moeda
62
+ # @return [String] texto formatado saldos
63
+ def formata_saldos(bqm)
64
+ b = bqd[:sl][bqm].to_d
65
+ t = exd[:sl]["balance_#{bqm}".to_sym].to_d
66
+ format(
67
+ '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
68
+ mo: bqm.upcase,
69
+ kr: t,
70
+ bq: b,
71
+ ok: t == b ? 'OK' : 'NOK'
72
+ )
73
+ end
74
+
75
+ # @example (see Apice#ledger_fr)
76
+ # @param (see Bigquery#frl_val)
77
+ # @return [String] texto formatado ledger
78
+ def formata_ledger(hlx)
79
+ format(
80
+ '%<ky>-18.18s %<dt>19.19s %<ty>-17.17s %<mo>-4.4s %<vl>18.7f',
81
+ ky: formata_uuid(hlx[:uuid], 18),
82
+ dt: Time.at(hlx[:created_at_int]),
83
+ ty: hlx[:name],
84
+ mo: hlx[:currency].upcase,
85
+ vl: hlx[:amount].to_d
86
+ )
87
+ end
88
+
89
+ # @param [String] uid identificacor da ledger
90
+ # @param [Integer] max chars a mostrar
91
+ # @return [String] texto formatado identificacor da ledger
92
+ def formata_uuid(uid, max)
93
+ i = Integer(max / 2)
94
+ max < 7 ? 'erro' : "#{uid[0, i]}#{uid[-i..]}"
95
+ end
96
+
97
+ # @return [String] texto totais numero de transacoes
98
+ def mostra_totais
99
+ c = exd[:kl].map { |h| h[:account_operations].count }.flatten.inject(:+)
100
+ d = bqd[:nl].count
101
+
102
+ puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: c, d: d, o: c == d ? 'OK' : 'NOK')}")
103
+ end
104
+
105
+ # @return [String] texto transacoes ledger
106
+ def mostra_ledger
107
+ return unless ops[:v] && ledger.count.positive?
108
+
109
+ puts("\nledger data hora tipo moeda quantidade")
110
+ ledger.sort { |a, b| b[:created_at_int] <=> a[:created_at_int] }.each { |o| puts(formata_ledger(o)) }
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('bigdecimal/util')
4
+
5
+ # @author Hernani Rodrigues Vaz
6
+ module Cns
7
+ # classe para processar transacoes ledger do therock
8
+ class TheRock
9
+ # @return [Apius] API therock
10
+ attr_reader :api
11
+ # @return [Array<Hash>] todos os dados bigquery
12
+ attr_reader :bqd
13
+ # @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
14
+ attr_reader :ops
15
+
16
+ # @param [Hash] dad todos os dados bigquery
17
+ # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
18
+ # @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
19
+ # @option pop [Boolean] :v (false) mostra dados transacoes trades & ledger?
20
+ # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
21
+ # @return [TheRock] API therock - obter saldos & transacoes ledger
22
+ def initialize(dad, pop)
23
+ @api = Apice.new
24
+ @bqd = dad
25
+ @ops = pop
26
+ end
27
+
28
+ # @return [Array<Hash>] lista ledger therock novos
29
+ def ledger
30
+ @ledger ||= exd[:kl].select { |o| kyl.include?(o[:id]) }
31
+ end
32
+
33
+ # @return [String] texto saldos & transacoes & ajuste dias
34
+ def mostra_resumo
35
+ puts("\nTHEROCK\ntipo therock bigquery")
36
+ exd[:sl].each { |h| puts(formata_saldos(h)) }
37
+ mostra_totais
38
+
39
+ mostra_ledger
40
+ return unless ledger.count.positive?
41
+
42
+ puts("\nstring ajuste dias da ledger\n-h=#{kyl.map { |e| "#{e}:0" }.join(' ')}")
43
+ end
44
+
45
+ # @return [Hash] dados exchange therock - saldos & transacoes ledger
46
+ def exd
47
+ @exd ||= {
48
+ sl: api.account_mt,
49
+ kl: api.ledger_mt
50
+ }
51
+ end
52
+
53
+ # @return [Array<String>] lista txid dos ledger novos
54
+ def kyl
55
+ @kyl ||= exd[:kl].map { |h| h[:id] } - (ops[:t] ? [] : bqd[:nl].map { |e| e[:txid] })
56
+ end
57
+
58
+ # @example (see Apice#account_mt)
59
+ # @param [Hash] hsl saldo therock da moeda
60
+ # @return [String] texto formatado saldos
61
+ def formata_saldos(hsl)
62
+ b = bqd[:sl][hsl[:currency].downcase.to_sym].to_d
63
+ k = hsl[:balance].to_d
64
+ format(
65
+ '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
66
+ mo: hsl[:currency].upcase,
67
+ kr: k,
68
+ bq: b,
69
+ ok: k == b ? 'OK' : 'NOK'
70
+ )
71
+ end
72
+
73
+ # @example (see Apice#ledger_mt)
74
+ # @param (see Bigquery#mtl_val1)
75
+ # @return [String] texto formatado ledger
76
+ def formata_ledger(hlx)
77
+ format(
78
+ '%<ky>6i %<dt>19.19s %<ty>-27.27s %<mo>-4.4s %<vl>20.7f',
79
+ ky: hlx[:id],
80
+ dt: Time.parse(hlx[:date]),
81
+ ty: hlx[:type],
82
+ mo: hlx[:currency].upcase,
83
+ vl: hlx[:price].to_d
84
+ )
85
+ end
86
+
87
+ # @return [String] texto totais numero de transacoes
88
+ def mostra_totais
89
+ c = exd[:kl].count
90
+ d = bqd[:nl].count
91
+
92
+ puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: c, d: d, o: c == d ? 'OK' : 'NOK')}")
93
+ end
94
+
95
+ # @return [String] texto transacoes ledger
96
+ def mostra_ledger
97
+ return unless ops[:v] && ledger.count.positive?
98
+
99
+ puts("\nledger data hora tipo moeda ---------quantidade")
100
+ ledger.sort { |a, b| b[:id] <=> a[:id] }.each { |o| puts(formata_ledger(o)) }
101
+ end
102
+ end
103
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cns
2
- VERSION = "0.1.0"
4
+ VERSION = '0.1.5'
3
5
  end