cns 0.6.0 → 0.7.0

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: 560dab16530bbcb5c17b1a0818eb6d709741c8c2ef9a46c0db7fe26408b99c76
4
- data.tar.gz: c756d10aa56e094b0011be04564df3e46cd13e6a632a1c9f3f541c230a5f0397
3
+ metadata.gz: 2831cc8463f48af9870a6d577be3161c608e4d5b410c8b0976fab2b2d7d9bbe9
4
+ data.tar.gz: 3de096f6a0d55a541731c67ed889c2134426f186bdc8d1e24b7d8cf8a6c4fd5f
5
5
  SHA512:
6
- metadata.gz: e6f7f0b5b041d410fb91f5b69fbcf945cda1d39b213d92990df15847644425dd5ad71a57dafeda64cd20ddf2c72c328b8f2562c683841e430529b6560a6ced2a
7
- data.tar.gz: bc3f09e26239e4d72190ea29c8c0f6416656af29b3045d6b25889fcf0b20ac0a6fa7b22a8c9c01d31f43862dc48a27f38ee0d904d7fff29df6ef25432e5656cf
6
+ metadata.gz: cdbcc626c2105243833bf26f447e5da36b113fe16ccd787f53c39fd800cb211cc159f49ff005936dff756070b0ecf2299e871874f212737569f0d1ed114e7844
7
+ data.tar.gz: d580a5ff25b83296c3f8376b9dde8a2cd56b07bf9cdea937257f05dc42c596d031f208cb10f9ac538a10b7cdd6e8f4a4cfdd41f3545d08d731f87cf95dfaa265
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.0)
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
@@ -167,12 +165,6 @@ 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(
@@ -218,9 +210,10 @@ 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 sum(btc) xxbt,sum(eth) xeth,sum(eos) eos,sum(eur) zeur from #{BD}.ussl")[0],
214
+ sl: sql("select * from #{BD}.ussl")[0],
215
+ nt: sql("select * from #{BD}.ust order by time,txid"),
216
+ nl: sql("select * from #{BD}.usl order by time,txid")
224
217
  },
225
218
  ops
226
219
  )
@@ -230,31 +223,9 @@ module Cns
230
223
  def apide
231
224
  @apide ||= Bitcoinde.new(
232
225
  {
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")
236
- },
237
- ops
238
- )
239
- end
240
-
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
- )
250
- end
251
-
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")
226
+ sl: sql("select * from #{BD}.desl")[0],
227
+ nt: sql("select * from #{BD}.det order by time,txid"),
228
+ nl: sql("select * from #{BD}.del order by time,txid")
258
229
  },
259
230
  ops
260
231
  )
@@ -354,11 +325,6 @@ module Cns
354
325
  "VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
355
326
  end
356
327
 
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
328
  # @example (see Apibc#norml_es)
363
329
  # @param [Hash] htx transacao norml etherscan
364
330
  # @return [String] valores formatados etht (norml parte1)
@@ -600,43 +566,76 @@ module Cns
600
566
  "cast(#{hlx[:fee]} as numeric))"
601
567
  end
602
568
 
569
+ # @return [Paymium] API exchange paymium
570
+ # def apifr
571
+ # @apifr ||= Paymium.new(
572
+ # {
573
+ # sl: sql("select * from #{BD}.frsl")[0],
574
+ # nl: sql("select uuid txid,tipo,valor,moe,time,dias from #{BD}.fr order by time,1")
575
+ # },
576
+ # ops
577
+ # )
578
+ # end
579
+ #
580
+ # @return [TheRock] API exchange therock
581
+ # def apimt
582
+ # @apimt ||= TheRock.new(
583
+ # {
584
+ # sl: sql("select sum(btc) btc,sum(eur) eur from #{BD}.mtsl")[0],
585
+ # nl: sql("select id txid,time,type,valor,moe,pair,note,dias from #{BD}.mt order by time,1")
586
+ # },
587
+ # ops
588
+ # )
589
+ # end
590
+ #
591
+ # @return [String] comando insert SQL formatado fr (ledger)
592
+ # def frl_ins
593
+ # "insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
594
+ # end
595
+ #
596
+ # @return [String] comando insert SQL formatado fr (ledger)
597
+ # def mtl_ins
598
+ # "insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
599
+ # "VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
600
+ # end
601
+ #
603
602
  # @example (see Apice#ledger_fr)
604
603
  # @param [Hash] hlx ledger paymium
605
604
  # @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
-
605
+ # def frl_val(hlx)
606
+ # uid = hlx[:uuid]
607
+ # "('#{uid}'," \
608
+ # "'#{hlx[:name]}'," \
609
+ # "cast(#{hlx[:amount]} as numeric)," \
610
+ # "'#{hlx[:currency]}'," \
611
+ # "PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
612
+ # "#{Integer(ops[:h][uid] || 0)})"
613
+ # end
614
+ #
616
615
  # @example (see Apice#ledger_mt)
617
616
  # @param [Hash] hlx ledger therock
618
617
  # @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
-
618
+ # def mtl_1val(hlx)
619
+ # fid = hlx[:fund_id].to_s
620
+ # "(#{hlx[:id]}," \
621
+ # "DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
622
+ # "'#{hlx[:type]}'," \
623
+ # "cast(#{hlx[:price]} as numeric)," \
624
+ # "'#{hlx[:currency]}'," \
625
+ # "#{fid.empty? ? 'null' : "'#{fid}'"}," \
626
+ # "#{mtl_2val(hlx)}"
627
+ # end
628
+ #
630
629
  # @param (see mtl_1val)
631
630
  # @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
-
631
+ # def mtl_2val(hlx)
632
+ # nte = hlx[:note].to_s
633
+ # tid = hlx[:trade_id].to_s
634
+ # "#{nte.empty? ? 'null' : "'#{nte}'"}," \
635
+ # "#{tid.empty? ? 'null' : tid.to_s}," \
636
+ # "#{Integer(ops[:h][String(hlx[:id])] || 0)})"
637
+ # end
638
+ #
640
639
  # @example (see Beaconchain#formata_saldos)
641
640
  # @param (see Beaconchain#formata_saldos)
642
641
  # @return [String] valores formatados etht (norml parte1)
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.0'
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.0
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-04 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