cns 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3b7d92c5d0783aab6b1400ba4bd7e397e4f7391cfbf83d1d7faf5a8c52349aa
4
- data.tar.gz: 43aa372a6d6f6d148f17c33065e8f0550647a2b0b78f213b00363c7ea2f74828
3
+ metadata.gz: 2133a6c91eacdca2448707ed31dfbb17ec295ebc245bf123aa748f4ee16c94a0
4
+ data.tar.gz: fbce4205347f06b47f7b7ad0bf3bc9d54ee95f92b02a022e5452a3fc25262812
5
5
  SHA512:
6
- metadata.gz: 22fb5e905b0469a4022c278d643bcf06b11afab7a011329775ab3cffee92bccfeb9392c676c993569ddd7404e090ab8d2a469c1aabfff4c833b873053f3f7435
7
- data.tar.gz: 0d7531ba08be4fe655a578475f4752d80330e41930b5d5d7732463838539357ae2936e6d11bcbe9bbd112508190404b523bceed6d4f1475853eb9f3b1b29c9e2
6
+ metadata.gz: f44eb068aeb057e71293033f362a41c4f967cbc32ee6a8fa4a9dd5b5054dbdbc9df7fa60a6b94fe96a73f7e94722626a561e2abc78791ffaf1334475864c55ca
7
+ data.tar.gz: 2a70f181fc35bc5a854862b6e3375e29c3e2df649b5c398e51d75b41e11a83e8b2e9015a273de1bcb710f25f8a05e401a1a5a3c83ee33a36fe1c0382fff0e595
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.1.1)
4
+ cns (0.1.2)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
@@ -19,7 +19,7 @@ GEM
19
19
  declarative-option (0.1.0)
20
20
  faraday (1.0.1)
21
21
  multipart-post (>= 1.2, < 3)
22
- google-api-client (0.44.2)
22
+ google-api-client (0.45.0)
23
23
  addressable (~> 2.5, >= 2.5.1)
24
24
  googleauth (~> 0.9)
25
25
  httpclient (>= 2.8.1, < 3.0)
@@ -28,7 +28,7 @@ GEM
28
28
  retriable (>= 2.0, < 4.0)
29
29
  rexml
30
30
  signet (~> 0.12)
31
- google-cloud-bigquery (1.22.0)
31
+ google-cloud-bigquery (1.23.0)
32
32
  concurrent-ruby (~> 1.0)
33
33
  google-api-client (~> 0.33)
34
34
  google-cloud-core (~> 1.2)
data/lib/cns.rb CHANGED
@@ -1,35 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require('thor')
4
- require('cns/apide')
5
- require('cns/apies')
6
- require('cns/apifr')
7
- require('cns/apigm')
8
- require('cns/apimt')
9
- require('cns/apius')
4
+ require('cns/apibc')
5
+ require('cns/apice1')
6
+ require('cns/apice2')
10
7
  require('cns/bigquery1')
11
8
  require('cns/bigquery2')
12
9
  require('cns/bigquery3')
13
10
  require('cns/bigquery4')
14
- require('cns/bitcoinde')
15
11
  require('cns/etherscan1')
16
12
  require('cns/etherscan2')
17
13
  require('cns/greymass1')
18
14
  require('cns/greymass2')
15
+ require('cns/bitcoinde')
19
16
  require('cns/kraken')
20
17
  require('cns/paymium')
21
18
  require('cns/therock')
22
19
  require('cns/version')
23
20
 
24
21
  module Cns
25
- # classe para erros desta gem
26
- class Erro < StandardError
27
- # @return [StandardError] personalizacao dos erros
28
- def initialize(msg)
29
- super(msg)
30
- end
31
- end
32
-
33
22
  # classe para carregar/mostrar dados transacoes eth & eos no bigquery
34
23
  class CLI < Thor
35
24
  desc 'work', 'carrega transacoes novas no bigquery'
@@ -47,6 +36,13 @@ module Cns
47
36
  Bigquery.new(options).mostra_tudo
48
37
  end
49
38
 
39
+ desc 'nn', 'mostra resumo transacoes'
40
+ # mostra resumo transacoes
41
+ def nn
42
+ c = Apice.new.ledger_fr
43
+ p(c)
44
+ end
45
+
50
46
  default_task :show
51
47
  end
52
48
  end
@@ -0,0 +1,280 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('faraday')
4
+ require('json')
5
+
6
+ # @author Hernani Rodrigues Vaz
7
+ module Cns
8
+ # classe para acesso dados blockchains
9
+ class Apibc
10
+ # @example account_es
11
+ # {
12
+ # status: '1',
13
+ # message: 'OK',
14
+ # result: [
15
+ # { account: '0x...', balance: '4000000000000000000' },
16
+ # { account: '0x...', balance: '87000000000000000000' }
17
+ # ]
18
+ # }
19
+ # @param [String] ads lista enderecos ETH (max 20)
20
+ # @param [Hash] par parametros base do pedido HTTP
21
+ # @return [Array<Hash>] lista enderecos e seus saldos
22
+ def account_es(ads, par = { module: 'account', action: 'balancemulti', tag: 'latest' })
23
+ JSON.parse(
24
+ (conn_es.get('api') do |o|
25
+ o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
26
+ o.params = par.merge(address: ads.join(','), apikey: ENV['ETHERSCAN_API_KEY'])
27
+ end).body,
28
+ symbolize_names: true
29
+ )[:result]
30
+ rescue StandardError
31
+ []
32
+ end
33
+
34
+ # @example account_gm
35
+ # {
36
+ # account_name: '...',
37
+ # head_block_num: 141_391_122,
38
+ # head_block_time: '2020-09-11T16:05:51.000',
39
+ # privileged: false,
40
+ # last_code_update: '1970-01-01T00:00:00.000',
41
+ # created: '2018-06-09T13:14:37.000',
42
+ #
43
+ # core_liquid_balance: '1232.0228 EOS',
44
+ # total_resources: { owner: '...', net_weight: '1000.1142 EOS', cpu_weight: '1000.1144 EOS', ram_bytes: 8148 },
45
+ #
46
+ # ram_quota: 9548,
47
+ # net_weight: 10_001_142,
48
+ # cpu_weight: 10_001_144,
49
+ # net_limit: { used: 0, available: 1_066_648_346, max: 1_066_648_346 },
50
+ # cpu_limit: { used: 338, available: 88_498, max: 88_836 },
51
+ # ram_usage: 3574,
52
+ # permissions: [
53
+ # {
54
+ # perm_name: 'active',
55
+ # parent: 'owner',
56
+ # required_auth: {
57
+ # threshold: 1, keys: [{ key: 'EOS...', weight: 1 }], accounts: [], waits: []
58
+ # }
59
+ # },
60
+ # {
61
+ # perm_name: 'owner',
62
+ # parent: '',
63
+ # required_auth: {
64
+ # threshold: 1, keys: [{ key: 'EOS...', weight: 1 }], accounts: [], waits: []
65
+ # }
66
+ # }
67
+ # ],
68
+ # self_delegated_bandwidth: { from: '...', to: '...', net_weight: '1000.1142 EOS', cpu_weight: '1000.1144 EOS' },
69
+ # refund_request: nil,
70
+ # voter_info: {
71
+ # owner: '...',
72
+ # proxy: '...',
73
+ # producers: [],
74
+ # staked: 20_002_286,
75
+ # last_vote_weight: '17172913021904.12109375000000000',
76
+ # proxied_vote_weight: '0.00000000000000000',
77
+ # is_proxy: 0,
78
+ # flags1: 0,
79
+ # reserved2: 0,
80
+ # reserved3: '0.0000 EOS'
81
+ # },
82
+ # rex_info: nil
83
+ # }
84
+ # @param [String] add endereco EOS
85
+ # @param [String] uri Uniform Resource Identifier do pedido HTTP
86
+ # @return [Hash] endereco e seus saldo/recursos
87
+ def account_gm(add, uri = '/v1/chain/get_account')
88
+ JSON.parse(
89
+ conn_gm.post(
90
+ uri, { account_name: add }.to_json, content_type: 'application/json'
91
+ ).body,
92
+ symbolize_names: true
93
+ )
94
+ rescue StandardError
95
+ { core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
96
+ end
97
+
98
+ # @example norml_es
99
+ # {
100
+ # status: '1',
101
+ # message: 'OK',
102
+ # result: [
103
+ # {
104
+ # blockNumber: '4984535',
105
+ # timeStamp: '1517094794',
106
+ # hash: '0x...',
107
+ # nonce: '10',
108
+ # blockHash: '0x...',
109
+ # transactionIndex: '17',
110
+ # from: '0x...',
111
+ # to: '0x...',
112
+ # value: '52627271000000000000',
113
+ # gas: '21000',
114
+ # gasPrice: '19000000000',
115
+ # isError: '0',
116
+ # txreceipt_status: '1',
117
+ # input: '0x',
118
+ # contractAddress: '',
119
+ # gasUsed: '21000',
120
+ # cumulativeGasUsed: '566293',
121
+ # confirmations: '5848660'
122
+ # },
123
+ # {}
124
+ # ]
125
+ # }
126
+ # @param [String] add endereco ETH
127
+ # @param [Integer] pag pagina transacoes
128
+ # @param [Array<Hash>] ary acumulador transacoes
129
+ # @param par (see account_es)
130
+ # @return [Array<Hash>] lista completa transacoes etherscan
131
+ def norml_es(add, pag = 0, ary = [], par = { module: 'account', action: 'txlist', offset: 10_000 })
132
+ r = JSON.parse(
133
+ (conn_es.get('api') do |o|
134
+ o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
135
+ o.params = par.merge(address: add, page: pag + 1, apikey: ENV['ETHERSCAN_API_KEY'])
136
+ end).body,
137
+ symbolize_names: true
138
+ )[:result]
139
+ r.count < 10_000 ? ary + r : norml_es(add, pag + 1, ary + r)
140
+ rescue StandardError
141
+ ary
142
+ end
143
+
144
+ # @example token_es
145
+ # {
146
+ # status: '1',
147
+ # message: 'OK',
148
+ # result: [
149
+ # {
150
+ # blockNumber: '3967652',
151
+ # timeStamp: '1499081515',
152
+ # hash: '0x registo duplicado com todos os dados iguais',
153
+ # nonce: '3',
154
+ # blockHash: '0x00a49e999036dc13dc6c4244bb1d51d3146fe7f00bfb500a7624d82e299c7328',
155
+ # from: '0xd0a6e6c54dbc68db5db3a091b171a77407ff7ccf',
156
+ # contractAddress: '0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0',
157
+ # to: '0x...',
158
+ # value: '0',
159
+ # tokenName: 'EOS',
160
+ # tokenSymbol: 'EOS',
161
+ # tokenDecimal: '18',
162
+ # transactionIndex: '83',
163
+ # gas: '173399',
164
+ # gasPrice: '21000000000',
165
+ # gasUsed: '173398',
166
+ # input: 'deprecated',
167
+ # cumulativeGasUsed: '7484878',
168
+ # confirmations: '3442641'
169
+ # },
170
+ # {}
171
+ # ]
172
+ # }
173
+ # @param (see norml_es)
174
+ # @return [Array<Hash>] lista completa token transfer events etherscan
175
+ def token_es(add, pag = 0, ary = [], par = { module: 'account', action: 'tokentx', offset: 10_000 })
176
+ # registos duplicados aparecem em token events (ver exemplo acima)
177
+ # -quando ha erros na blockchain (acho)
178
+ # -quando ha token events identicos no mesmo block (acho)
179
+ r = JSON.parse(
180
+ (conn_es.get('api') do |o|
181
+ o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
182
+ o.params = par.merge(address: add, page: pag + 1, apikey: ENV['ETHERSCAN_API_KEY'])
183
+ end).body,
184
+ symbolize_names: true
185
+ )[:result]
186
+ r.count < 10_000 ? ary + r : token_es(add, pag + 1, ary + r)
187
+ rescue StandardError
188
+ ary
189
+ end
190
+
191
+ # @example ledger_gm
192
+ # {
193
+ # actions: [
194
+ # {
195
+ # account_action_seq: 964,
196
+ # action_trace: {
197
+ # account_ram_deltas: [],
198
+ # act: {
199
+ # account: 'voicebestapp',
200
+ # authorization: [
201
+ # { actor: 'thetruevoice', permission: 'active' },
202
+ # { actor: 'voicebestapp', permission: 'active' }
203
+ # ],
204
+ # data: { from: 'voicebestapp', memo: '...', quantity: '1.0001 MESSAGE', to: '...' },
205
+ # hex_data: '...',
206
+ # name: 'transfer'
207
+ # },
208
+ # action_ordinal: 10,
209
+ # block_num: 141_345_345,
210
+ # block_time: '2020-09-11T09:44:04.500',
211
+ # closest_unnotified_ancestor_action_ordinal: 5,
212
+ # context_free: false,
213
+ # creator_action_ordinal: 5,
214
+ # elapsed: 6,
215
+ # producer_block_id: '...',
216
+ # receipt: {
217
+ # abi_sequence: 1,
218
+ # act_digest: '...',
219
+ # auth_sequence: [['thetruevoice', 6_778_215], ['voicebestapp', 435_346]],
220
+ # code_sequence: 1,
221
+ # global_sequence: 233_283_589_258,
222
+ # receiver: '...',
223
+ # recv_sequence: 927
224
+ # },
225
+ # receiver: '...',
226
+ # trx_id: '...'
227
+ # },
228
+ # block_num: 141_345_345,
229
+ # block_time: '2020-09-11T09:44:04.500',
230
+ # global_action_seq: 233_283_589_258,
231
+ # irreversible: true
232
+ # },
233
+ # {}
234
+ # ],
235
+ # head_block_num: 141_721_698,
236
+ # last_irreversible_block: 141_721_371
237
+ # }
238
+ # @param add (see account_gm)
239
+ # @param [Integer] pos posicao transacoes
240
+ # @param [Array<Hash>] ary acumulador transacoes
241
+ # @param uri (see account_gm)
242
+ # @return [Array<Hash>] lista completa transacoes greymass
243
+ def ledger_gm(add, pos = 0, ary = [], uri = '/v1/history/get_actions')
244
+ r = JSON.parse(
245
+ conn_gm.post(
246
+ uri, { account_name: add, pos: pos, offset: 100 }.to_json, content_type: 'application/json'
247
+ ).body,
248
+ symbolize_names: true
249
+ )[:actions]
250
+ r.count < 100 ? ary + r : ledger_gm(add, pos + r.count, ary + r)
251
+ rescue StandardError
252
+ ary
253
+ end
254
+
255
+ private
256
+
257
+ # @return [<Symbol>] adapter for the connection - default :net_http
258
+ def adapter
259
+ @adapter ||= Faraday.default_adapter
260
+ end
261
+
262
+ # @return [<Faraday::Connection>] connection object for etherscan
263
+ def conn_es
264
+ @conn_es ||=
265
+ Faraday.new(url: 'https://api.etherscan.io/') do |c|
266
+ c.request(:url_encoded)
267
+ c.adapter(adapter)
268
+ end
269
+ end
270
+
271
+ # @return [<Faraday::Connection>] connection object for greymass
272
+ def conn_gm
273
+ @conn_gm ||=
274
+ Faraday.new(url: 'https://eos.greymass.com') do |c|
275
+ c.request(:url_encoded)
276
+ c.adapter(adapter)
277
+ end
278
+ end
279
+ end
280
+ end
@@ -0,0 +1,227 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('openssl')
4
+ require('base64')
5
+ require('curb')
6
+ require('json')
7
+
8
+ # @author Hernani Rodrigues Vaz
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
+
12
+ # (see Apice)
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) { |r| r.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) { |h| h.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) { |h| h.headers = hmt(uri) }.body,
80
+ symbolize_names: true
81
+ )[:balances]
82
+ .delete_if { |e| DC.include?(e[:currency]) }
83
+ .sort { |a, b| a[:currency] <=> b[: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) { |h| h.headers = hus(uri, nonce: non) }.body,
107
+ symbolize_names: true
108
+ )[:result]
109
+ rescue StandardError
110
+ {}
111
+ end
112
+
113
+ private
114
+
115
+ # @example deposits_unif_de
116
+ # [
117
+ # {
118
+ # txid: 177_245,
119
+ # time: '2014-01-31T22:01:30+01:00',
120
+ # tp: 'deposit',
121
+ # add: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
122
+ # qt: '0.13283',
123
+ # moe: 'btc',
124
+ # fee: '0'
125
+ # },
126
+ # {}
127
+ # ]
128
+ # @param [Hash] hde pagina depositos bitcoinde
129
+ # @return [Array<Hash>] lista uniformizada pagina depositos bitcoinde
130
+ def deposits_unif_de(hde)
131
+ hde[:deposits].map do |h|
132
+ {
133
+ add: h[:address],
134
+ time: Time.parse(h[:created_at]),
135
+ qt: h[:amount],
136
+ txid: Integer(h[:deposit_id])
137
+ }.merge(tp: 'deposit', moe: 'btc', fee: '0')
138
+ end
139
+ end
140
+
141
+ # @example withdrawals_unif_de
142
+ # [
143
+ # {
144
+ # txid: 136_605,
145
+ # time: '2014-02-05T13:05:17+01:00',
146
+ # tp: 'withdrawal',
147
+ # add: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
148
+ # qt: '0.120087',
149
+ # fee: '0',
150
+ # moe: 'btc'
151
+ # },
152
+ # {}
153
+ # ]
154
+ # @param [Hash] hwi pagina withdrawals bitcoinde
155
+ # @return [Array<Hash>] lista uniformizada pagina withdrawals bitcoinde
156
+ def withdrawals_unif_de(hwi)
157
+ hwi[:withdrawals].map do |h|
158
+ {
159
+ add: h[:address],
160
+ time: Time.parse(h[:transferred_at]),
161
+ qt: h[:amount],
162
+ fee: h[:network_fee],
163
+ txid: Integer(h[:withdrawal_id])
164
+ }.merge(tp: 'withdrawal', moe: 'btc')
165
+ end
166
+ end
167
+
168
+ # @return [Integer] continually-increasing unsigned integer nonce from the current Unix Time
169
+ def nnc
170
+ Integer(Float(Time.now) * 1e6)
171
+ end
172
+
173
+ # @param [String] qry query a incluir no pedido HTTP
174
+ # @param [Integer] non continually-increasing unsigned integer
175
+ # @return [Hash] headers necessarios para pedido HTTP da exchange bitcoinde
176
+ def hde(qry, non = nnc)
177
+ {
178
+ 'X-API-KEY': ENV['BITCOINDE_API_KEY'],
179
+ 'X-API-NONCE': non,
180
+ 'X-API-SIGNATURE': OpenSSL::HMAC.hexdigest(
181
+ 'sha256',
182
+ ENV['BITCOINDE_API_SECRET'],
183
+ ['GET', qry, ENV['BITCOINDE_API_KEY'], non, Digest::MD5.hexdigest('')].join('#')
184
+ )
185
+ }
186
+ end
187
+
188
+ # @param (see hde)
189
+ # @return [Hash] headers necessarios para pedido HTTP da exchange paymium
190
+ def hfr(qry, non = nnc)
191
+ {
192
+ content_type: 'application/json',
193
+ 'Api-Key': ENV['PAYMIUM_API_KEY'],
194
+ 'Api-Nonce': non,
195
+ 'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qry].join)
196
+ }
197
+ end
198
+
199
+ # @param (see hde)
200
+ # @return [Hash] headers necessarios para pedido HTTP da exchange therock
201
+ def hmt(qry, non = nnc)
202
+ {
203
+ content_type: 'application/json',
204
+ 'X-TRT-KEY': ENV['THEROCK_API_KEY'],
205
+ 'X-TRT-NONCE': non,
206
+ 'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qry].join)
207
+ }
208
+ end
209
+
210
+ # @param qry (see hde)
211
+ # @param [Hash] ops opcoes trabalho
212
+ # @option ops [Hash] :nonce continually-increasing unsigned integer
213
+ # @return [Hash] headers necessarios para pedido HTTP da exchange kraken
214
+ def hus(qry, ops)
215
+ {
216
+ 'api-key': ENV['KRAKEN_API_KEY'],
217
+ 'api-sign': Base64.strict_encode64(
218
+ OpenSSL::HMAC.digest(
219
+ 'sha512',
220
+ Base64.decode64(ENV['KRAKEN_API_SECRET']),
221
+ ['/0/private/', qry, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
222
+ )
223
+ )
224
+ }
225
+ end
226
+ end
227
+ end