Class: Cex::Paymium

Inherits:
Object
  • Object
show all
Defined in:
lib/cex/paymium.rb

Overview

classe para processar saldos & transacoes ledger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dad, pop) ⇒ Paymium

Returns API paymium - obter saldos & transacoes ledger.

Parameters:

  • dad (Hash)

    todos os dados bigquery

  • pop (Thor::CoreExt::HashWithIndifferentAccess)

    opcoes trabalho

Options Hash (pop):

  • :h (Hash) — default: {}

    configuracao dias ajuste reposicionamento temporal

  • :v (Boolean) — default: false

    mostra dados transacoes trades & ledger?

  • :t (Boolean) — default: false

    mostra transacoes todas ou somente novas?



22
23
24
25
26
27
# File 'lib/cex/paymium.rb', line 22

def initialize(dad, pop)
  # API paymium base
  @api = Apifr.new
  @dbq = dad
  @ops = pop
end

Instance Attribute Details

#apiApius (readonly)

Returns API paymium.

Returns:

  • (Apius)

    API paymium



10
11
12
# File 'lib/cex/paymium.rb', line 10

def api
  @api
end

#dbqArray<Hash> (readonly)

Returns todos os dados bigquery.

Returns:

  • (Array<Hash>)

    todos os dados bigquery



12
13
14
# File 'lib/cex/paymium.rb', line 12

def dbq
  @dbq
end

#opsThor::CoreExt::HashWithIndifferentAccess (readonly)

Returns opcoes trabalho.

Returns:

  • (Thor::CoreExt::HashWithIndifferentAccess)

    opcoes trabalho



14
15
16
# File 'lib/cex/paymium.rb', line 14

def ops
  @ops
end

Instance Method Details

#exdHash

Returns dados exchange paymium - saldos & transacoes ledger.

Returns:

  • (Hash)

    dados exchange paymium - saldos & transacoes ledger



30
31
32
33
34
35
# File 'lib/cex/paymium.rb', line 30

def exd
  @exd ||= {
    sl: api.,
    kl: api.ledger
  }
end

#formata_ledger(hlx) ⇒ String

Returns texto formatado transacao ledger.

Examples:

[
  {
    uuid: '50551e61-4e74-4ae7-85fd-9c2040542818',
    currency_amount: nil,
    state: 'executed',
    btc_fee: '0.0',
    currency_fee: '0.0',
    created_at: '2014-03-04T09:00Z',
    updated_at: '2014-03-04T09:00Z',
    currency: 'EUR',
    comment: '5723',
    amount: '100.0',
    type: 'WireDeposit',
    account_operations: [{
      uuid: 'b5058a68-cf99-4438-86d3-e773eba418ec',
      name: 'wire_deposit',
      amount: '100.0',
      currency: 'EUR',
      created_at: '2014-03-04T09:00Z',
      created_at_int: 1_393_923_644,
      is_trading_account: false
    }, {}]
  }, {}
]

Parameters:

  • hlx (Hash)

    transacao ledger apifr

Returns:

  • (String)

    texto formatado transacao ledger



66
67
68
69
70
71
72
73
74
75
# File 'lib/cex/paymium.rb', line 66

def formata_ledger(hlx)
  format(
    '%<ky>-18.18s %<dt>19.19s %<ty>-17.17s %<mo>-4.4s %<vl>18.7f',
    ky: formata_uuid(hlx[:uuid], 18),
    dt: Time.at(hlx[:created_at_int]),
    ty: hlx[:name],
    mo: hlx[:currency].upcase,
    vl: hlx[:amount].to_d
  )
end

#formata_saldos(bqm) ⇒ String

Returns texto formatado saldos (paymium/bigquery) & iguais/ok/nok?.

Examples:

{
  name: '...',
  email: '...',
  locale: 'en',
  channel_id: '...',
  meta_state: 'approved',
  balance_eur: '0.0',
  locked_eur: '0.0',
  balance_btc: '0.0',
  locked_btc: '0.0',
  balance_lbtc: '0.0',
  locked_lbtc: '0.0'
}

Parameters:

  • bqm (Symbol)

    symbol paymium da moeda

Returns:

  • (String)

    texto formatado saldos (paymium/bigquery) & iguais/ok/nok?



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cex/paymium.rb', line 51

def formata_saldos(bqm)
  b = dbq[:sl][bqm].to_d
  t = exd[:sl]["balance_#{bqm}".to_sym].to_d
  format(
    '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
    mo: bqm.upcase,
    kr: t,
    bq: b,
    ok: t == b ? 'OK' : 'NOK'
  )
end

#formata_uuid(uid, max) ⇒ String

Returns texto formatado identificacor da ledger apifr.

Examples:

[
  {
    uuid: '50551e61-4e74-4ae7-85fd-9c2040542818',
    currency_amount: nil,
    state: 'executed',
    btc_fee: '0.0',
    currency_fee: '0.0',
    created_at: '2014-03-04T09:00Z',
    updated_at: '2014-03-04T09:00Z',
    currency: 'EUR',
    comment: '5723',
    amount: '100.0',
    type: 'WireDeposit',
    account_operations: [{
      uuid: 'b5058a68-cf99-4438-86d3-e773eba418ec',
      name: 'wire_deposit',
      amount: '100.0',
      currency: 'EUR',
      created_at: '2014-03-04T09:00Z',
      created_at_int: 1_393_923_644,
      is_trading_account: false
    }, {}]
  }, {}
]

Parameters:

  • uid (String)

    identificacor da ledger apifr

  • max (Integer)

    chars a mostrar

Returns:

  • (String)

    texto formatado identificacor da ledger apifr



81
82
83
84
# File 'lib/cex/paymium.rb', line 81

def formata_uuid(uid, max)
  i = Integer(max / 2)
  max < 7 ? 'erro' : "#{uid[0, i]}#{uid[-i..]}"
end

#kylArray<String>

Returns lista txid de transacoes ledger.

Returns:

  • (Array<String>)

    lista txid de transacoes ledger



38
39
40
41
# File 'lib/cex/paymium.rb', line 38

def kyl
  @kyl ||= exd[:kl].map { |h| h[:account_operations].map { |o| o[:uuid] } }.flatten -
           (ops[:t] ? [] : dbq[:nl].map { |e| e[:txid] })
end

#ledgerHash

Returns transacoes ledger.

Returns:

  • (Hash)

    transacoes ledger



44
45
46
# File 'lib/cex/paymium.rb', line 44

def ledger
  @ledger ||= exd[:kl].map { |h| h[:account_operations].select { |o| kyl.include?(o[:uuid]) } }.flatten
end

#mostra_ledgerString

Returns texto transacoes ledger.

Returns:

  • (String)

    texto transacoes ledger



99
100
101
102
103
104
# File 'lib/cex/paymium.rb', line 99

def mostra_ledger
  return unless ops[:v] && ledger.count.positive?

  puts("\nledger             data       hora     tipo              moeda -------quantidade")
  ledger.sort { |a, b| b[:created_at_int] <=> a[:created_at_int] }.each { |o| puts(formata_ledger(o)) }
end

#mostra_resumoString

Returns texto saldos & transacoes & ajuste dias.

Returns:

  • (String)

    texto saldos & transacoes & ajuste dias



87
88
89
90
91
92
93
94
95
96
# File 'lib/cex/paymium.rb', line 87

def mostra_resumo
  puts("\nPAYMIUM\nmoeda         saldo paymium        saldo bigquery")
  puts(formata_saldos(:btc))
  puts(formata_saldos(:eur))

  mostra_ledger
  return unless ledger.count.positive?

  puts("\nstring ajuste dias da ledger\n-h=#{kyl.map { |e| "#{e}:0" }.join(' ')}")
end