cns 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 560dab16530bbcb5c17b1a0818eb6d709741c8c2ef9a46c0db7fe26408b99c76
4
- data.tar.gz: c756d10aa56e094b0011be04564df3e46cd13e6a632a1c9f3f541c230a5f0397
3
+ metadata.gz: 61b5bd4279e22a5bc61efb12f3717d805aaefa15d46b4f98ef45a05c052b701e
4
+ data.tar.gz: 34984d55f0b46e72097d5a589b0f3d2700dd89fc8877ba0c2e38ad55c553fed8
5
5
  SHA512:
6
- metadata.gz: e6f7f0b5b041d410fb91f5b69fbcf945cda1d39b213d92990df15847644425dd5ad71a57dafeda64cd20ddf2c72c328b8f2562c683841e430529b6560a6ced2a
7
- data.tar.gz: bc3f09e26239e4d72190ea29c8c0f6416656af29b3045d6b25889fcf0b20ac0a6fa7b22a8c9c01d31f43862dc48a27f38ee0d904d7fff29df6ef25432e5656cf
6
+ metadata.gz: 524fc4c7bd9170238499712ab47c7f994f350421955e6e85af4ba1695992825f491ed201bcc8c9942df3f9aa9c2eb65ab0b50d8156e932239db1ff59ee57117f
7
+ data.tar.gz: 836882fa7b8e372b62d3399004bd97993cedd74fd7fe8da423ee95b1493de28053beed1ea9405b4382c537ad6950c079ebd974b048f3130ecd8e1453d2fd23b0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (0.6.0)
4
+ cns (0.7.1)
5
5
  curb
6
6
  faraday
7
7
  google-cloud-bigquery
data/lib/cns/apice.rb CHANGED
@@ -38,53 +38,6 @@ module Cns
38
38
  {}
39
39
  end
40
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
41
  # @example account_us
89
42
  # {
90
43
  # error: [],
@@ -269,82 +222,6 @@ module Cns
269
222
  }.merge(tp: 'withdrawal', moe: 'btc')
270
223
  end
271
224
 
272
- # @example ledger_fr
273
- # [
274
- # {
275
- # uuid: '50551e61-4e74-4ae7-85fd-9c2040542818',
276
- # currency_amount: nil,
277
- # state: 'executed',
278
- # btc_fee: '0.0',
279
- # currency_fee: '0.0',
280
- # created_at: '2014-03-04T09:00Z',
281
- # updated_at: '2014-03-04T09:00Z',
282
- # currency: 'EUR',
283
- # comment: '5723',
284
- # amount: '100.0',
285
- # type: 'WireDeposit',
286
- # account_operations: [{
287
- # uuid: 'b5058a68-cf99-4438-86d3-e773eba418ec',
288
- # name: 'wire_deposit',
289
- # amount: '100.0',
290
- # currency: 'EUR',
291
- # created_at: '2014-03-04T09:00Z',
292
- # created_at_int: 1_393_923_644,
293
- # is_trading_account: false
294
- # }, {}]
295
- # },
296
- # {}
297
- # ]
298
- # @param (see trades_de)
299
- # @return [Array<Hash>] lista ledger paymium
300
- def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders')
301
- res = JSON.parse(
302
- Curl.get(uri, offset: pag) { |obj| obj.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body,
303
- symbolize_names: true
304
- )
305
- res.empty? ? ary : ledger_fr(pag + res.size, ary + res)
306
- rescue StandardError
307
- ary
308
- end
309
-
310
- # @example ledger_mt
311
- # {
312
- # transactions: [
313
- # {
314
- # id: 305_445,
315
- # date: '2014-03-06T10:59:13.000Z',
316
- # type: 'withdraw',
317
- # price: 97.47,
318
- # currency: 'EUR',
319
- # fund_id: nil,
320
- # order_id: nil,
321
- # trade_id: nil,
322
- # note: 'BOV withdraw',
323
- # transfer_detail: nil
324
- # },
325
- # {}
326
- # ],
327
- # meta: {
328
- # total_count: nil,
329
- # first: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
330
- # previous: nil,
331
- # current: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
332
- # next: { page: 2, href: 'https://api.therocktrading.com/v1/transactions?page=2' },
333
- # last: nil
334
- # }
335
- # }
336
- # @param (see trades_de)
337
- # @return [Array<Hash>] lista ledger therock
338
- def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions')
339
- res = JSON.parse(
340
- Curl.get(uri, page: pag) { |obj| obj.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body,
341
- symbolize_names: true
342
- )[:transactions]
343
- res.empty? ? ary : ledger_mt(pag + res.size, ary + res)
344
- rescue StandardError
345
- ary
346
- end
347
-
348
225
  # @example trades_us
349
226
  # {
350
227
  # error: [],
@@ -423,6 +300,129 @@ module Cns
423
300
  has
424
301
  end
425
302
 
303
+ # @example account_fr
304
+ # {
305
+ # name: '...',
306
+ # email: '...',
307
+ # locale: 'en',
308
+ # channel_id: '...',
309
+ # meta_state: 'approved',
310
+ # balance_eur: '0.0',
311
+ # locked_eur: '0.0',
312
+ # balance_btc: '0.0',
313
+ # locked_btc: '0.0',
314
+ # balance_lbtc: '0.0',
315
+ # locked_lbtc: '0.0'
316
+ # }
317
+ # @param (see account_de)
318
+ # @return [Hash] saldos no paymium
319
+ # def account_fr(uri = 'https://paymium.com/api/v1/user')
320
+ # JSON.parse(
321
+ # Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body,
322
+ # symbolize_names: true
323
+ # )
324
+ # rescue StandardError
325
+ # {}
326
+ # end
327
+ #
328
+ # @example account_mt
329
+ # {
330
+ # balances: [
331
+ # { currency: 'BTC', balance: 0.0, trading_balance: 0.0 },
332
+ # { currency: 'ETH', balance: 0.0, trading_balance: 0.0 },
333
+ # { currency: 'EUR', balance: 0.0, trading_balance: 0.0 },
334
+ # { currency: 'DAI', balance: 0.0, trading_balance: 0.0 },
335
+ # ]
336
+ # }
337
+ # @param (see account_de)
338
+ # @return [Array<Hash>] lista saldos no therock
339
+ # def account_mt(uri = 'https://api.therocktrading.com/v1/balances')
340
+ # JSON.parse(
341
+ # Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body,
342
+ # symbolize_names: true
343
+ # )[:balances]
344
+ # .delete_if { |del| DC.include?(del[:currency]) }
345
+ # .sort { |oba, obb| oba[:currency] <=> obb[:currency] }
346
+ # rescue StandardError
347
+ # []
348
+ # end
349
+ #
350
+ # @example ledger_fr
351
+ # [
352
+ # {
353
+ # uuid: '50551e61-4e74-4ae7-85fd-9c2040542818',
354
+ # currency_amount: nil,
355
+ # state: 'executed',
356
+ # btc_fee: '0.0',
357
+ # currency_fee: '0.0',
358
+ # created_at: '2014-03-04T09:00Z',
359
+ # updated_at: '2014-03-04T09:00Z',
360
+ # currency: 'EUR',
361
+ # comment: '5723',
362
+ # amount: '100.0',
363
+ # type: 'WireDeposit',
364
+ # account_operations: [{
365
+ # uuid: 'b5058a68-cf99-4438-86d3-e773eba418ec',
366
+ # name: 'wire_deposit',
367
+ # amount: '100.0',
368
+ # currency: 'EUR',
369
+ # created_at: '2014-03-04T09:00Z',
370
+ # created_at_int: 1_393_923_644,
371
+ # is_trading_account: false
372
+ # }, {}]
373
+ # },
374
+ # {}
375
+ # ]
376
+ # @param (see trades_de)
377
+ # @return [Array<Hash>] lista ledger paymium
378
+ # def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders')
379
+ # res = JSON.parse(
380
+ # Curl.get(uri, offset: pag) { |obj| obj.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body,
381
+ # symbolize_names: true
382
+ # )
383
+ # res.empty? ? ary : ledger_fr(pag + res.size, ary + res)
384
+ # rescue StandardError
385
+ # ary
386
+ # end
387
+ #
388
+ # @example ledger_mt
389
+ # {
390
+ # transactions: [
391
+ # {
392
+ # id: 305_445,
393
+ # date: '2014-03-06T10:59:13.000Z',
394
+ # type: 'withdraw',
395
+ # price: 97.47,
396
+ # currency: 'EUR',
397
+ # fund_id: nil,
398
+ # order_id: nil,
399
+ # trade_id: nil,
400
+ # note: 'BOV withdraw',
401
+ # transfer_detail: nil
402
+ # },
403
+ # {}
404
+ # ],
405
+ # meta: {
406
+ # total_count: nil,
407
+ # first: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
408
+ # previous: nil,
409
+ # current: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
410
+ # next: { page: 2, href: 'https://api.therocktrading.com/v1/transactions?page=2' },
411
+ # last: nil
412
+ # }
413
+ # }
414
+ # @param (see trades_de)
415
+ # @return [Array<Hash>] lista ledger therock
416
+ # def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions')
417
+ # res = JSON.parse(
418
+ # Curl.get(uri, page: pag) { |obj| obj.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body,
419
+ # symbolize_names: true
420
+ # )[:transactions]
421
+ # res.empty? ? ary : ledger_mt(pag + res.size, ary + res)
422
+ # rescue StandardError
423
+ # ary
424
+ # end
425
+
426
426
  private
427
427
 
428
428
  # @return [Integer] continually-increasing unsigned integer nonce from the current Unix Time
@@ -449,26 +449,26 @@ module Cns
449
449
  # @param [String] qfr query a incluir no pedido HTTP
450
450
  # @param non (see hde)
451
451
  # @return [Hash] headers necessarios para pedido HTTP da exchange paymium
452
- def hfr(qfr, non = nnc)
453
- {
454
- content_type: 'application/json',
455
- 'Api-Key': ENV['PAYMIUM_API_KEY'],
456
- 'Api-Nonce': non,
457
- 'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qfr].join)
458
- }
459
- end
460
-
452
+ # def hfr(qfr, non = nnc)
453
+ # {
454
+ # content_type: 'application/json',
455
+ # 'Api-Key': ENV['PAYMIUM_API_KEY'],
456
+ # 'Api-Nonce': non,
457
+ # 'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qfr].join)
458
+ # }
459
+ # end
460
+ #
461
461
  # @param [String] qmt query a incluir no pedido HTTP
462
462
  # @param non (see hde)
463
463
  # @return [Hash] headers necessarios para pedido HTTP da exchange therock
464
- def hmt(qmt, non = nnc)
465
- {
466
- content_type: 'application/json',
467
- 'X-TRT-KEY': ENV['THEROCK_API_KEY'],
468
- 'X-TRT-NONCE': non,
469
- 'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qmt].join)
470
- }
471
- end
464
+ # def hmt(qmt, non = nnc)
465
+ # {
466
+ # content_type: 'application/json',
467
+ # 'X-TRT-KEY': ENV['THEROCK_API_KEY'],
468
+ # 'X-TRT-NONCE': non,
469
+ # 'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qmt].join)
470
+ # }
471
+ # end
472
472
 
473
473
  # @param [String] qus query a incluir no pedido HTTP
474
474
  # @param [Hash] ops opcoes trabalho
data/lib/cns/bigquery.rb CHANGED
@@ -35,8 +35,6 @@ module Cns
35
35
  def mostra_tudo
36
36
  apius.mostra_resumo
37
37
  apide.mostra_resumo
38
- #apifr.mostra_resumo
39
- #apimt.mostra_resumo
40
38
  apies.mostra_resumo
41
39
  apigm.mostra_resumo
42
40
  end
@@ -44,7 +42,7 @@ module Cns
44
42
  # mostra situacao completa entre kraken/etherscan & bigquery
45
43
  def mostra_skrk
46
44
  apius.mostra_resumo
47
- apies.mostra_resumo_simples
45
+ apies.mostra_resumo
48
46
  end
49
47
 
50
48
  # mostra situacao completa entre etherscan & bigquery
@@ -83,29 +81,29 @@ module Cns
83
81
 
84
82
  private
85
83
 
86
- # insere transacoes blockchain novas nas tabelas etht (norml), ethi (internas), ethp (block), ethw (withdrawals), ethk (token)
84
+ # insere transacoes blockchain novas nas tabelas netht (norml), nethi (internas), nethp (block), nethw (withdrawals), nethk (token)
87
85
  #
88
86
  # @return [String] linhas & tabelas afetadas
89
87
  def processa_eth
90
88
  str = "ETH"
91
- str += format(" %<n>i etht", n: dml(etht_ins)) if apies.novtx.count > 0
92
- str += format(" %<n>i ethi", n: dml(ethi_ins)) if apies.novix.count > 0
93
- str += format(" %<n>i ethp", n: dml(ethp_ins)) if apies.novpx.count > 0
94
- str += format(" %<n>i ethw", n: dml(ethw_ins)) if apies.novwx.count > 0
95
- str += format(" %<n>i ethk", n: dml(ethk_ins)) if apies.novkx.count > 0
89
+ str += format(" %<n>i netht", n: dml(netht_ins)) if apies.novtx.count > 0
90
+ str += format(" %<n>i nethi", n: dml(nethi_ins)) if apies.novix.count > 0
91
+ str += format(" %<n>i nethp", n: dml(nethp_ins)) if apies.novpx.count > 0
92
+ str += format(" %<n>i nethw", n: dml(nethw_ins)) if apies.novwx.count > 0
93
+ str += format(" %<n>i nethk", n: dml(nethk_ins)) if apies.novkx.count > 0
96
94
  str
97
95
  end
98
96
 
99
- # insere transacoes blockchain novas nas tabelas etht (norml), ethi (internas), ethp (block), ethw (withdrawals), ethk (token)
97
+ # insere transacoes blockchain novas nas tabelas netht (norml), nethi (internas), nethp (block), nethw (withdrawals), nethk (token)
100
98
  #
101
99
  # @return [String] linhas & tabelas afetadas
102
100
  def processa_ethc
103
101
  str = "ETH"
104
- str += format(" %<n>i etht", n: dml(ethtc_ins)) if apiesc.novtx.count > 0
105
- str += format(" %<n>i ethi", n: dml(ethic_ins)) if apiesc.novix.count > 0
106
- str += format(" %<n>i ethp", n: dml(ethpc_ins)) if apiesc.novpx.count > 0
107
- str += format(" %<n>i ethw", n: dml(ethwc_ins)) if apiesc.novwx.count > 0
108
- str += format(" %<n>i ethk", n: dml(ethkc_ins)) if apiesc.novkx.count > 0
102
+ str += format(" %<n>i netht", n: dml(netbt_ins)) if apiesc.novtx.count > 0
103
+ str += format(" %<n>i nethi", n: dml(netbi_ins)) if apiesc.novix.count > 0
104
+ str += format(" %<n>i nethp", n: dml(netbp_ins)) if apiesc.novpx.count > 0
105
+ str += format(" %<n>i nethw", n: dml(netbw_ins)) if apiesc.novwx.count > 0
106
+ str += format(" %<n>i nethk", n: dml(netbk_ins)) if apiesc.novkx.count > 0
109
107
  str
110
108
  end
111
109
 
@@ -167,22 +165,16 @@ module Cns
167
165
  job?(cmd) ? 0 : job.num_dml_affected_rows
168
166
  end
169
167
 
170
- # @return [String] comando insert SQL formatado fr (ledger)
171
- def mtl_ins
172
- "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
173
- "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
174
- end
175
-
176
168
  # @return [Etherscan] API blockchain ETH
177
169
  def apies
178
170
  @apies ||= Etherscan.new(
179
171
  {
180
- wb: sql("select * from #{BD}.walletEth order by 2"),
181
- nt: sql("select * from #{BD}.ethtx"),
182
- ni: sql("select * from #{BD}.ethix"),
183
- np: sql("select * from #{BD}.ethpx"),
184
- nw: sql("select * from #{BD}.ethwx"),
185
- nk: sql("select * from #{BD}.ethkx")
172
+ wb: sql("select * from #{BD}.weth order by 2"),
173
+ ni: sql("select * from #{BD}.netai"),
174
+ nk: sql("select * from #{BD}.netak"),
175
+ np: sql("select * from #{BD}.netap"),
176
+ nt: sql("select * from #{BD}.netat"),
177
+ nw: sql("select * from #{BD}.netaw")
186
178
  },
187
179
  ops
188
180
  )
@@ -192,12 +184,12 @@ module Cns
192
184
  def apiesc
193
185
  @apies ||= Etherscan.new(
194
186
  {
195
- wb: sql("select * from #{BD}.walletEthc order by 2"),
196
- nt: sql("select * from #{BD}.ethtxc"),
197
- ni: sql("select * from #{BD}.ethixc"),
198
- np: sql("select * from #{BD}.ethpxc"),
199
- nw: sql("select * from #{BD}.ethwxc"),
200
- nk: sql("select * from #{BD}.ethkxc")
187
+ wb: sql("select * from #{BD}.wetc order by 2"),
188
+ ni: sql("select * from #{BD}.netbi"),
189
+ nk: sql("select * from #{BD}.netbk"),
190
+ np: sql("select * from #{BD}.netbp"),
191
+ nt: sql("select * from #{BD}.netbt"),
192
+ nw: sql("select * from #{BD}.netbw")
201
193
  },
202
194
  ops
203
195
  )
@@ -207,8 +199,8 @@ module Cns
207
199
  def apigm
208
200
  @apigm ||= Greymass.new(
209
201
  {
210
- wb: sql("select * from #{BD}.walletEos order by 2"),
211
- nt: sql("select * from #{BD}.eostx")
202
+ wb: sql("select * from #{BD}.weos order by 2"),
203
+ nt: sql("select * from #{BD}.neosx")
212
204
  },
213
205
  ops
214
206
  )
@@ -218,9 +210,9 @@ module Cns
218
210
  def apius
219
211
  @apius ||= Kraken.new(
220
212
  {
221
- sl: sql("select sum(btc) xxbt,sum(eth) xeth,sum(eos) eos,sum(eur) zeur from #{BD}.ussl")[0],
222
- nt: sql("select * from #{BD}.ustx order by time,txid"),
223
- nl: sql("select * from #{BD}.uslx order by time,txid")
213
+ sl: sql("select * from #{BD}.cuss")[0],
214
+ nt: sql("select * from #{BD}.cust order by time,txid"),
215
+ nl: sql("select * from #{BD}.cusl order by time,txid")
224
216
  },
225
217
  ops
226
218
  )
@@ -230,139 +222,124 @@ module Cns
230
222
  def apide
231
223
  @apide ||= Bitcoinde.new(
232
224
  {
233
- sl: sql("select sum(btc) btc from #{BD}.desl")[0],
234
- nt: sql("select * from #{BD}.detx order by time,txid"),
235
- nl: sql("select * from #{BD}.delx order by time,txid")
225
+ sl: sql("select * from #{BD}.cdes")[0],
226
+ nt: sql("select * from #{BD}.cdet order by time,txid"),
227
+ nl: sql("select * from #{BD}.cdel order by time,txid")
236
228
  },
237
229
  ops
238
230
  )
239
231
  end
240
232
 
241
- # @return [Paymium] API exchange paymium
242
- def apifr
243
- @apifr ||= Paymium.new(
244
- {
245
- sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.frsl")[0],
246
- nl: sql("select * from #{BD}.frlx order by time,txid")
247
- },
248
- ops
249
- )
233
+ # @return [String] comando insert SQL formatado netht (norml)
234
+ def bnetht_ins
235
+ "insert #{BD}.netht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
236
+ 'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias) VALUES'
250
237
  end
251
238
 
252
- # @return [TheRock] API exchange therock
253
- def apimt
254
- @apimt ||= TheRock.new(
255
- {
256
- sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.mtsl")[0],
257
- nl: sql("select * from #{BD}.mtlx order by time,txid")
258
- },
259
- ops
260
- )
239
+ # @return [String] comando insert SQL formatado nethi (internas)
240
+ def bnethi_ins
241
+ "insert #{BD}.nethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
242
+ 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode) VALUES'
261
243
  end
262
244
 
263
- # @return [String] comando insert SQL formatado etht (norml)
264
- def etht_ins
265
- "insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
266
- 'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias' \
267
- ") VALUES#{apies.novtx.map { |obj| etht_1val(obj) }.join(',')}"
245
+ # @return [String] comando insert SQL formatado nethp (block)
246
+ def bnethp_ins
247
+ "insert #{BD}.nethp(blocknumber,timestamp,blockreward,iax) VALUES"
268
248
  end
269
249
 
270
- # @return [String] comando insert SQL formatado ethi (internas)
271
- def ethi_ins
272
- "insert #{BD}.ethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
273
- 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode' \
274
- ") VALUES#{apies.novix.map { |obj| ethi_1val(obj) }.join(',')}"
250
+ # @return [String] comando insert SQL formatado nethw (withdrawals)
251
+ def bnethw_ins
252
+ "insert #{BD}.nethw(withdrawalindex,validatorindex,address,amount,blocknumber,timestamp) VALUES"
275
253
  end
276
254
 
277
- # @return [String] comando insert SQL formatado ethp (block)
278
- def ethp_ins
279
- "insert #{BD}.ethp(blocknumber,timestamp,blockreward,iax" \
280
- ") VALUES#{apies.novpx.map { |obj| ethp_1val(obj) }.join(',')}"
255
+ # @return [String] comando insert SQL formatado nethk (token)
256
+ def bnethk_ins
257
+ "insert #{BD}.nethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
258
+ 'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias) VALUES'
281
259
  end
282
260
 
283
- # @return [String] comando insert SQL formatado ethw (withdrawals)
284
- def ethw_ins
285
- "insert #{BD}.ethw(withdrawalindex,validatorindex,address,amount,blocknumber,timestamp" \
286
- ") VALUES#{apies.novwx.map { |obj| ethw_1val(obj) }.join(',')}"
261
+ # @return [String] comando insert SQL formatado netht (norml)
262
+ def netht_ins
263
+ "#{bnetht_ins}#{apies.novtx.map { |obj| netht_1val(obj) }.join(',')}"
287
264
  end
288
265
 
289
- # @return [String] comando insert SQL formatado ethk (token)
290
- def ethk_ins
291
- "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
292
- 'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
293
- ") VALUES#{apies.novkx.map { |obj| ethk_1val(obj) }.join(',')}"
266
+ # @return [String] comando insert SQL formatado nethi (internas)
267
+ def nethi_ins
268
+ "#{bnethi_ins}#{apies.novix.map { |obj| nethi_1val(obj) }.join(',')}"
294
269
  end
295
270
 
296
- # @return [String] comando insert SQL formatado etht (norml)
297
- def ethtc_ins
298
- "insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
299
- 'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias' \
300
- ") VALUES#{apiesc.novtx.map { |obj| etht_1val(obj) }.join(',')}"
271
+ # @return [String] comando insert SQL formatado nethp (block)
272
+ def nethp_ins
273
+ "#{bnethp_ins}#{apies.novpx.map { |obj| nethp_1val(obj) }.join(',')}"
301
274
  end
302
275
 
303
- # @return [String] comando insert SQL formatado ethi (internas)
304
- def ethic_ins
305
- "insert #{BD}.ethi(blocknumber,timestamp,txhash,axfrom,axto,iax," \
306
- 'value,contractaddress,input,type,gas,gasused,traceid,iserror,errcode' \
307
- ") VALUES#{apiesc.novix.map { |obj| ethi_1val(obj) }.join(',')}"
276
+ # @return [String] comando insert SQL formatado nethw (withdrawals)
277
+ def nethw_ins
278
+ "#{bnethw_ins}#{apies.novwx.map { |obj| nethw_1val(obj) }.join(',')}"
308
279
  end
309
280
 
310
- # @return [String] comando insert SQL formatado ethp (block)
311
- def ethpc_ins
312
- "insert #{BD}.ethp(blocknumber,timestamp,blockreward,iax" \
313
- ") VALUES#{apiesc.novpx.map { |obj| ethp_1val(obj) }.join(',')}"
281
+ # @return [String] comando insert SQL formatado nethk (token)
282
+ def nethk_ins
283
+ "#{bnethk_ins}#{apies.novkx.map { |obj| nethk_1val(obj) }.join(',')}"
314
284
  end
315
285
 
316
- # @return [String] comando insert SQL formatado ethw (withdrawals)
317
- def ethwc_ins
318
- "insert #{BD}.ethw(withdrawalindex,validatorindex,address,amount,blocknumber,timestamp" \
319
- ") VALUES#{apiesc.novwx.map { |obj| ethw_1val(obj) }.join(',')}"
286
+ # @return [String] comando insert SQL formatado netht (norml)
287
+ def netbt_ins
288
+ "#{bnetht_ins}#{apiesc.novtx.map { |obj| netht_1val(obj) }.join(',')}"
320
289
  end
321
290
 
322
- # @return [String] comando insert SQL formatado ethk (token)
323
- def ethkc_ins
324
- "insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
325
- 'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
326
- ") VALUES#{apiesc.novkx.map { |obj| ethk_1val(obj) }.join(',')}"
291
+ # @return [String] comando insert SQL formatado nethi (internas)
292
+ def netbi_ins
293
+ "#{bnethi_ins}#{apiesc.novix.map { |obj| nethi_1val(obj) }.join(',')}"
294
+ end
295
+
296
+ # @return [String] comando insert SQL formatado nethp (block)
297
+ def netbp_ins
298
+ "#{bnethp_ins}#{apiesc.novpx.map { |obj| nethp_1val(obj) }.join(',')}"
299
+ end
300
+
301
+ # @return [String] comando insert SQL formatado nethw (withdrawals)
302
+ def netbw_ins
303
+ "#{bnethw_ins}#{apiesc.novwx.map { |obj| nethw_1val(obj) }.join(',')}"
304
+ end
305
+
306
+ # @return [String] comando insert SQL formatado nethk (token)
307
+ def netbk_ins
308
+ "#{bnethk_ins}#{apiesc.novkx.map { |obj| nethk_1val(obj) }.join(',')}"
327
309
  end
328
310
 
329
311
  # @return [String] comando insert SQL formatado eos
330
312
  def eost_ins
331
- "insert #{BD}.eos(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
313
+ "insert #{BD}.neost(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
332
314
  ") VALUES#{apigm.novax.map { |obj| eost_1val(obj) }.join(',')}"
333
315
  end
334
316
 
335
317
  # @return [String] comando insert SQL formatado det (trades)
336
318
  def det_ins
337
- "insert #{BD}.det(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
319
+ "insert #{BD}.cdet(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
338
320
  end
339
321
 
340
322
  # @return [String] comando insert SQL formatado del (ledger)
341
323
  def del_ins
342
- "insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
324
+ "insert #{BD}.cdel(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
343
325
  end
344
326
 
345
327
  # @return [String] comando insert SQL formatado ust (trades)
346
328
  def ust_ins
347
- "insert #{BD}.ust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
329
+ "insert #{BD}.cust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
348
330
  "VALUES#{apius.trades.map { |key, val| ust_1val(key, val) }.join(',')}"
349
331
  end
350
332
 
351
333
  # @return [String] comando insert SQL formatado usl (ledger)
352
334
  def usl_ins
353
- "insert #{BD}.usl(txid,refid,time,type,aclass,asset,amount,fee) " \
335
+ "insert #{BD}.cusl(txid,refid,time,type,aclass,asset,amount,fee) " \
354
336
  "VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
355
337
  end
356
338
 
357
- # @return [String] comando insert SQL formatado fr (ledger)
358
- def frl_ins
359
- "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
360
- end
361
-
362
339
  # @example (see Apibc#norml_es)
363
340
  # @param [Hash] htx transacao norml etherscan
364
- # @return [String] valores formatados etht (norml parte1)
365
- def etht_1val(htx)
341
+ # @return [String] valores formatados netht (norml parte1)
342
+ def netht_1val(htx)
366
343
  "(#{Integer(htx[:blockNumber])}," \
367
344
  "#{Integer(htx[:timeStamp])}," \
368
345
  "'#{htx[:hash]}'," \
@@ -372,12 +349,12 @@ module Cns
372
349
  "'#{htx[:from]}'," \
373
350
  "'#{htx[:to]}'," \
374
351
  "'#{htx[:iax]}'," \
375
- "#{etht_2val(htx)}"
352
+ "#{netht_2val(htx)}"
376
353
  end
377
354
 
378
- # @param (see etht_1val)
379
- # @return [String] valores formatados etht (norml parte2)
380
- def etht_2val(htx)
355
+ # @param (see netht_1val)
356
+ # @return [String] valores formatados netht (norml parte2)
357
+ def netht_2val(htx)
381
358
  txr = htx[:txreceipt_status]
382
359
  "cast('#{htx[:value]}' as numeric)," \
383
360
  "cast('#{htx[:gas]}' as numeric)," \
@@ -385,12 +362,12 @@ module Cns
385
362
  "cast('#{htx[:gasUsed]}' as numeric)," \
386
363
  "#{Integer(htx[:isError])}," \
387
364
  "#{txr.length.zero? ? 'null' : txr}," \
388
- "#{etht_3val(htx)}"
365
+ "#{netht_3val(htx)}"
389
366
  end
390
367
 
391
- # @param (see etht_1val)
392
- # @return [String] valores formatados etht (norml parte3)
393
- def etht_3val(htx)
368
+ # @param (see netht_1val)
369
+ # @return [String] valores formatados netht (norml parte3)
370
+ def netht_3val(htx)
394
371
  cta = htx[:contractAddress]
395
372
  inp = htx[:input]
396
373
  "#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
@@ -400,8 +377,8 @@ module Cns
400
377
 
401
378
  # @example (see Apibc#inter_es)
402
379
  # @param [Hash] htx transacao internas etherscan
403
- # @return [String] valores formatados ethi (internas parte1)
404
- def ethi_1val(htx)
380
+ # @return [String] valores formatados nethi (internas parte1)
381
+ def nethi_1val(htx)
405
382
  cta = htx[:contractAddress]
406
383
  "(#{Integer(htx[:blockNumber])}," \
407
384
  "#{Integer(htx[:timeStamp])}," \
@@ -411,12 +388,12 @@ module Cns
411
388
  "'#{htx[:iax]}'," \
412
389
  "cast('#{htx[:value]}' as numeric)," \
413
390
  "#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
414
- "#{ethi_2val(htx)}"
391
+ "#{nethi_2val(htx)}"
415
392
  end
416
393
 
417
- # @param (see ethi_1val)
418
- # @return [String] valores formatados ethi (internas parte2)
419
- def ethi_2val(htx)
394
+ # @param (see nethi_1val)
395
+ # @return [String] valores formatados nethi (internas parte2)
396
+ def nethi_2val(htx)
420
397
  inp = htx[:input]
421
398
  tid = htx[:traceId]
422
399
  txr = htx[:errCode]
@@ -431,8 +408,8 @@ module Cns
431
408
 
432
409
  # @example (see Apibc#block_es)
433
410
  # @param [Hash] htx transacao block etherscan
434
- # @return [String] valores formatados ethi (block parte1)
435
- def ethp_1val(htx)
411
+ # @return [String] valores formatados nethi (block parte1)
412
+ def nethp_1val(htx)
436
413
  "(#{Integer(htx[:blockNumber])}," \
437
414
  "#{Integer(htx[:timeStamp])}," \
438
415
  "cast('#{htx[:blockReward]}' as numeric)," \
@@ -441,8 +418,8 @@ module Cns
441
418
 
442
419
  # @example (see Apibc#block_es)
443
420
  # @param [Hash] htx transacao withdrawals etherscan
444
- # @return [String] valores formatados ethi (withdrawals parte1)
445
- def ethw_1val(htx)
421
+ # @return [String] valores formatados nethi (withdrawals parte1)
422
+ def nethw_1val(htx)
446
423
  "(#{Integer(htx[:withdrawalIndex])}," \
447
424
  "#{Integer(htx[:validatorIndex])}," \
448
425
  "'#{htx[:address]}'," \
@@ -453,8 +430,8 @@ module Cns
453
430
 
454
431
  # @example (see Apibc#token_es)
455
432
  # @param [Hash] hkx token event etherscan
456
- # @return [String] valores formatados ethk (token parte1)
457
- def ethk_1val(hkx)
433
+ # @return [String] valores formatados nethk (token parte1)
434
+ def nethk_1val(hkx)
458
435
  "(#{Integer(hkx[:blockNumber])}," \
459
436
  "#{Integer(hkx[:timeStamp])}," \
460
437
  "'#{hkx[:hash]}'," \
@@ -464,12 +441,12 @@ module Cns
464
441
  "'#{hkx[:from]}'," \
465
442
  "'#{hkx[:to]}'," \
466
443
  "'#{hkx[:iax]}'," \
467
- "#{ethk_2val(hkx)}"
444
+ "#{nethk_2val(hkx)}"
468
445
  end
469
446
 
470
- # @param (see ethk_1val)
471
- # @return [String] valores formatados ethk (token parte2)
472
- def ethk_2val(hkx)
447
+ # @param (see nethk_1val)
448
+ # @return [String] valores formatados nethk (token parte2)
449
+ def nethk_2val(hkx)
473
450
  "cast('#{hkx[:value]}' as numeric)," \
474
451
  "'#{hkx[:tokenName]}'," \
475
452
  "'#{hkx[:tokenSymbol]}'," \
@@ -477,12 +454,12 @@ module Cns
477
454
  "cast('#{hkx[:gas]}' as numeric)," \
478
455
  "cast('#{hkx[:gasPrice]}' as numeric)," \
479
456
  "cast('#{hkx[:gasUsed]}' as numeric)," \
480
- "#{ethk_3val(hkx)}"
457
+ "#{nethk_3val(hkx)}"
481
458
  end
482
459
 
483
- # @param (see ethk_1val)
484
- # @return [String] valores formatados ethk (token parte3)
485
- def ethk_3val(hkx)
460
+ # @param (see nethk_1val)
461
+ # @return [String] valores formatados nethk (token parte3)
462
+ def nethk_3val(hkx)
486
463
  cta = hkx[:contractAddress]
487
464
  inp = hkx[:input]
488
465
  "#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
@@ -600,43 +577,76 @@ module Cns
600
577
  "cast(#{hlx[:fee]} as numeric))"
601
578
  end
602
579
 
580
+ # @return [Paymium] API exchange paymium
581
+ # def apifr
582
+ # @apifr ||= Paymium.new(
583
+ # {
584
+ # sl: sql("select * from #{BD}.frsl")[0],
585
+ # nl: sql("select uuid txid,tipo,valor,moe,time,dias from #{BD}.fr order by time,1")
586
+ # },
587
+ # ops
588
+ # )
589
+ # end
590
+ #
591
+ # @return [TheRock] API exchange therock
592
+ # def apimt
593
+ # @apimt ||= TheRock.new(
594
+ # {
595
+ # sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.mtsl")[0],
596
+ # nl: sql("select id txid,time,type,valor,moe,pair,note,dias from #{BD}.mt order by time,1")
597
+ # },
598
+ # ops
599
+ # )
600
+ # end
601
+ #
602
+ # @return [String] comando insert SQL formatado fr (ledger)
603
+ # def frl_ins
604
+ # "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
605
+ # end
606
+ #
607
+ # @return [String] comando insert SQL formatado fr (ledger)
608
+ # def mtl_ins
609
+ # "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
610
+ # "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
611
+ # end
612
+ #
603
613
  # @example (see Apice#ledger_fr)
604
614
  # @param [Hash] hlx ledger paymium
605
615
  # @return [String] valores formatados frl (ledger)
606
- def frl_val(hlx)
607
- uid = hlx[:uuid]
608
- "('#{uid}'," \
609
- "'#{hlx[:name]}'," \
610
- "cast(#{hlx[:amount]} as numeric)," \
611
- "'#{hlx[:currency]}'," \
612
- "PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
613
- "#{Integer(ops[:h][uid] || 0)})"
614
- end
615
-
616
+ # def frl_val(hlx)
617
+ # uid = hlx[:uuid]
618
+ # "('#{uid}'," \
619
+ # "'#{hlx[:name]}'," \
620
+ # "cast(#{hlx[:amount]} as numeric)," \
621
+ # "'#{hlx[:currency]}'," \
622
+ # "PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
623
+ # "#{Integer(ops[:h][uid] || 0)})"
624
+ # end
625
+ #
616
626
  # @example (see Apice#ledger_mt)
617
627
  # @param [Hash] hlx ledger therock
618
628
  # @return [String] valores formatados mtl (ledger parte1)
619
- def mtl_1val(hlx)
620
- fid = hlx[:fund_id].to_s
621
- "(#{hlx[:id]}," \
622
- "DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
623
- "'#{hlx[:type]}'," \
624
- "cast(#{hlx[:price]} as numeric)," \
625
- "'#{hlx[:currency]}'," \
626
- "#{fid.empty? ? 'null' : "'#{fid}'"}," \
627
- "#{mtl_2val(hlx)}"
628
- end
629
-
629
+ # def mtl_1val(hlx)
630
+ # fid = hlx[:fund_id].to_s
631
+ # "(#{hlx[:id]}," \
632
+ # "DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
633
+ # "'#{hlx[:type]}'," \
634
+ # "cast(#{hlx[:price]} as numeric)," \
635
+ # "'#{hlx[:currency]}'," \
636
+ # "#{fid.empty? ? 'null' : "'#{fid}'"}," \
637
+ # "#{mtl_2val(hlx)}"
638
+ # end
639
+ #
630
640
  # @param (see mtl_1val)
631
641
  # @return [String] valores formatados mtl (ledger parte2)
632
- def mtl_2val(hlx)
633
- nte = hlx[:note].to_s
634
- tid = hlx[:trade_id].to_s
635
- "#{nte.empty? ? 'null' : "'#{nte}'"}," \
636
- "#{tid.empty? ? 'null' : tid.to_s}," \
637
- "#{Integer(ops[:h][String(hlx[:id])] || 0)})"
638
- end
639
-
642
+ # def mtl_2val(hlx)
643
+ # nte = hlx[:note].to_s
644
+ # tid = hlx[:trade_id].to_s
645
+ # "#{nte.empty? ? 'null' : "'#{nte}'"}," \
646
+ # "#{tid.empty? ? 'null' : tid.to_s}," \
647
+ # "#{Integer(ops[:h][String(hlx[:id])] || 0)})"
648
+ # end
649
+ #
640
650
  # @example (see Beaconchain#formata_saldos)
641
651
  # @param (see Beaconchain#formata_saldos)
642
652
  # @return [String] valores formatados etht (norml parte1)
data/lib/cns/etherscan.rb CHANGED
@@ -259,24 +259,6 @@ module Cns
259
259
  )
260
260
  end
261
261
 
262
- # @param (see formata_carteira)
263
- # @example set hjn
264
- # {
265
- # id: wbq[:id],
266
- # ax: xbq = wbq[:ax],
267
- # bs: wbq[:sl], INPORTANTE saldo bigquery
268
- # bt: bqd[:nt].select { |ont| ont[:axfrom].casecmp?(xbq) },
269
- # bi: bqd[:ni].select { |oni| oni[:iax].casecmp?(xbq) },
270
- # bp: bqd[:np].select { |onp| onp[:iax].casecmp?(xbq) },
271
- # bw: bqd[:nw].select { |onw| onw[:iax].casecmp?(xbq) },
272
- # bk: bqd[:nk].select { |onk| onk[:iax].casecmp?(xbq) },
273
- # es: hbc[:sl], INPORTANTE saldo etherscan
274
- # et: hbc[:tx],
275
- # ei: hbc[:ix],
276
- # ep: hbc[:px],
277
- # ew: hbc[:wx],
278
- # ek: hbc[:kx]
279
- # }
280
262
  # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
281
263
  def ok?(hjn)
282
264
  hjn[:es].round(4) == hjn[:bs].round(4) && hjn[:bi].count == hjn[:ei].count && hjn[:bp].count == hjn[:ep].count && hjn[:bw].count == hjn[:ew].count
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.1'
5
5
  end
data/lib/cns.rb CHANGED
@@ -8,8 +8,6 @@ require('cns/etherscan')
8
8
  require('cns/greymass')
9
9
  require('cns/bitcoinde')
10
10
  require('cns/kraken')
11
- require('cns/paymium')
12
- require('cns/therock')
13
11
  require('cns/version')
14
12
 
15
13
  module Cns
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-02 00:00:00.000000000 Z
11
+ date: 2025-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -209,8 +209,6 @@ files:
209
209
  - lib/cns/etherscan.rb
210
210
  - lib/cns/greymass.rb
211
211
  - lib/cns/kraken.rb
212
- - lib/cns/paymium.rb
213
- - lib/cns/therock.rb
214
212
  - lib/cns/version.rb
215
213
  - ruby-lint.yml
216
214
  homepage: https://github.com/hernanirvaz/cns
data/lib/cns/paymium.rb DELETED
@@ -1,113 +0,0 @@
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 { |map| map[:account_operations].select { |obj| kyl.include?(obj[: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 { |obj| "#{obj}: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 { |oex| oex[:account_operations].map { |obj| obj[:uuid] } }.flatten -
57
- (ops[:t] ? [] : bqd[:nl].map { |obq| obq[: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
- vbq = bqd[:sl][bqm].to_d
65
- vkr = 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: vkr,
70
- bq: vbq,
71
- ok: vkr == vbq ? '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
- int = Integer(max / 2)
94
- max < 7 ? 'erro' : "#{uid[0, int]}#{uid[-int..]}"
95
- end
96
-
97
- # @return [String] texto totais numero de transacoes
98
- def mostra_totais
99
- vkl = exd[:kl].map { |obj| obj[:account_operations].count }.flatten.inject(:+)
100
- vnl = bqd[:nl].count
101
-
102
- puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vkl, d: vnl, o: vkl == vnl ? '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 { |ant, prx| prx[:created_at_int] <=> ant[:created_at_int] }.each { |obj| puts(formata_ledger(obj)) }
111
- end
112
- end
113
- end
data/lib/cns/therock.rb DELETED
@@ -1,104 +0,0 @@
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 { |obj| kyl.include?(obj[: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 { |obj| puts(formata_saldos(obj)) }
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 { |obj| "#{obj}: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 { |oex| oex[:id] } - (ops[:t] ? [] : bqd[:nl].map { |obq| obq[: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
- cur = hsl[:currency]
63
- vbq = bqd[:sl][cur.downcase.to_sym].to_d
64
- vkr = hsl[:balance].to_d
65
- format(
66
- '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
67
- mo: cur.upcase,
68
- kr: vkr,
69
- bq: vbq,
70
- ok: vkr == vbq ? 'OK' : 'NOK'
71
- )
72
- end
73
-
74
- # @example (see Apice#ledger_mt)
75
- # @param (see Bigquery#mtl_val1)
76
- # @return [String] texto formatado ledger
77
- def formata_ledger(hlx)
78
- format(
79
- '%<ky>6i %<dt>19.19s %<ty>-27.27s %<mo>-4.4s %<vl>20.7f',
80
- ky: hlx[:id],
81
- dt: Time.parse(hlx[:date]),
82
- ty: hlx[:type],
83
- mo: hlx[:currency].upcase,
84
- vl: hlx[:price].to_d
85
- )
86
- end
87
-
88
- # @return [String] texto totais numero de transacoes
89
- def mostra_totais
90
- vkl = exd[:kl].count
91
- vnl = bqd[:nl].count
92
-
93
- puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vkl, d: vnl, o: vkl == vnl ? 'OK' : 'NOK')}")
94
- end
95
-
96
- # @return [String] texto transacoes ledger
97
- def mostra_ledger
98
- return unless ops[:v] && ledger.count.positive?
99
-
100
- puts("\nledger data hora tipo moeda quantidade")
101
- ledger.sort { |ant, prx| prx[:id] <=> ant[:id] }.each { |obj| puts(formata_ledger(obj)) }
102
- end
103
- end
104
- end