Class: Cex::Bitcoinde

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

Overview

classe para processar saldos & transacoes trades e ledger do bitcoinde

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dad, pop) ⇒ Bitcoinde

Returns API bitcoinde - obter saldos & transacoes trades e 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/bitcoinde.rb', line 22

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

Instance Attribute Details

#apiApius (readonly)

Returns API bitcoinde.

Returns:

  • (Apius)

    API bitcoinde



10
11
12
# File 'lib/cex/bitcoinde.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/bitcoinde.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/bitcoinde.rb', line 14

def ops
  @ops
end

Instance Method Details

#exdHash

Returns dados exchange bitcoinde - saldos & transacoes trades e ledger.

Returns:

  • (Hash)

    dados exchange bitcoinde - saldos & transacoes trades e ledger



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

def exd
  @exd ||= {
    sl: api.,
    tt: api.trades,
    tl: api.deposits + api.withdrawals
  }
end

#formata_ledger(hlx) ⇒ String

Returns texto formatado transacao ledger.

Examples:

{
  deposit_id: '177245',
  txid: '84f9e85bc5709cd471e3d58a7d0f42d2c4a7bbd888cabf844e200efbf0a7fda2',
  address: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
  amount: '0.13283',
  confirmations: 6,
  state: 2,
  created_at: '2014-01-31T22:01:30+01:00'
}
{
  withdrawal_id: '136605',
  address: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
  amount: '0.120087',
  network_fee: '0',
  comment: '',
  created_at: '2014-02-05T13:01:09+01:00',
  txid: '6264fe528116fcb87c812a306ca8409eecfec8fa941546c86f98984b882c8042',
  transferred_at: '2014-02-05T13:05:17+01:00',
  state: 1
}

Parameters:

  • hlx (Hash)

    transacao uniformizada deposits + withdrawals apide

Returns:

  • (String)

    texto formatado transacao ledger



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cex/bitcoinde.rb', line 94

def formata_ledger(hlx)
  format(
    '%<ky>6i %<dt>19.19s %<ty>-10.10s %<mo>-3.3s %<pr>19.8f %<vl>18.8f',
    ky: hlx[:lgid],
    dt: hlx[:time],
    ty: hlx[:tp],
    mo: hlx[:qtxt].upcase,
    pr: hlx[:qt].to_d,
    vl: hlx[:fee].to_d
  )
end

#formata_saldos(moe, hsx) ⇒ String

Returns texto formatado saldos (bitcoinde).

Examples:

{
  data: {
    balances: {
      btc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
      bch: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
      btg: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
      eth: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
      bsv: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
      ltc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' }
    },
    encrypted_information: { uid: '0y...', bic_short: '0y...', bic_full: '0y...' }
  },
  errors: [],
  credits: 23
}

Parameters:

  • moe (String)

    codigo bitcoinde da moeda

  • hsx (Hash)

    saldo bitcoinde da moeda

Returns:

  • (String)

    texto formatado saldos (bitcoinde)



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cex/bitcoinde.rb', line 62

def formata_saldos(moe, hsx)
  b = dbq[:sl][moe.downcase.to_sym].to_d
  e = hsx[:total_amount].to_d
  format(
    '%<mo>-5.5s %<ex>21.9f %<bq>21.9f %<ok>3.3s',
    mo: moe.upcase,
    ex: e,
    bq: b,
    ok: e == b ? 'OK' : 'NOK'
  )
end

#formata_trades(htx) ⇒ String

Returns texto formatado transacao trade.

Examples:

{
  trades: [{
    trade_id: 'XUWWD3',
    trading_pair: 'btceur',
    is_external_wallet_trade: false,
    type: 'sell',
    amount_currency_to_trade: '0.1',
    price: 430,
    volume_currency_to_pay: 43,
    volume_currency_to_pay_after_fee: 42.79,
    amount_currency_to_trade_after_fee: 0.099,
    fee_currency_to_pay: 0.22,
    fee_currency_to_trade: '0.00100000',
    created_at: '2014-03-22T08:14:48+01:00',
    successfully_finished_at: '2014-03-25T14:03:22+01:00',
    state: 1,
    is_trade_marked_as_paid: true,
    trade_marked_as_paid_at: '2014-03-22T08:20:01+01:00',
    payment_method: 1,
    my_rating_for_trading_partner: 'positive',
    trading_partner_information: {
      username: 'emax2000',
      is_kyc_full: false,
      trust_level: 'bronze',
      amount_trades: 4,
      rating: 100,
      bank_name: 'CASSA DI RISPARMIO DI CIVITAVECCHIA SPA',
      bic: 'CRFIIT2CXXX',
      seat_of_bank: 'IT'
    }
  }, {}],
  page: { current: 1, last: 2 },
  errors: [],
  credits: 22
}

Parameters:

  • htx (Hash)

    transacao trade apide

Returns:

  • (String)

    texto formatado transacao trade



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cex/bitcoinde.rb', line 77

def formata_trades(htx)
  format(
    '%<ky>-6.6s %<dt>19.19s %<dp>10.10s %<ty>-5.5s %<mo>-8.8s %<vl>18.8f %<co>8.2f',
    ky: htx[:trade_id],
    dt: Time.parse(htx[:successfully_finished_at]),
    dp: Time.parse(htx[:trade_marked_as_paid_at]),
    ty: htx[:type],
    mo: htx[:trading_pair].upcase,
    vl: htx[:amount_currency_to_trade].to_d,
    co: htx[:volume_currency_to_pay].to_d
  )
end

#kylArray<Integer>

Returns lista txid de transacoes ledger.

Returns:

  • (Array<Integer>)

    lista txid de transacoes ledger



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

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

#kytArray<String>

Returns lista txid de transacoes trades.

Returns:

  • (Array<String>)

    lista txid de transacoes trades



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

def kyt
  @kyt ||= exd[:tt].map { |h| h[:trade_id] }.flatten - (ops[:t] ? [] : dbq[:nt].map { |e| e[:txid] })
end

#ledgerHash

Returns transacoes ledger.

Returns:

  • (Hash)

    transacoes ledger



54
55
56
# File 'lib/cex/bitcoinde.rb', line 54

def ledger
  @ledger ||= exd[:tl].select { |h| kyl.include?(h[:lgid]) }
end

#mostra_ledgerString

Returns texto transacoes ledger.

Returns:

  • (String)

    texto transacoes ledger



128
129
130
131
132
133
# File 'lib/cex/bitcoinde.rb', line 128

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

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

#mostra_resumoString

Returns texto saldos & transacoes & ajuste dias.

Returns:

  • (String)

    texto saldos & transacoes & ajuste dias



107
108
109
110
111
112
113
114
115
116
# File 'lib/cex/bitcoinde.rb', line 107

def mostra_resumo
  puts("\nBITCOINDE\nmoeda       saldo bitcoinde        saldo bigquery")
  exd[:sl].each { |k, v| puts(formata_saldos(k, v)) }

  mostra_trades
  mostra_ledger
  return unless trades.count.positive?

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

#mostra_tradesString

Returns texto transacoes trades.

Returns:

  • (String)

    texto transacoes trades



119
120
121
122
123
124
125
# File 'lib/cex/bitcoinde.rb', line 119

def mostra_trades
  return unless ops[:v] && trades.count.positive?

  puts("\ntrades data       hora     dt criacao tipo  par      ---------------qtd -----eur")
  trades.sort { |a, b| Time.parse(b[:successfully_finished_at]) <=> Time.parse(a[:successfully_finished_at]) }
        .each { |h| puts(formata_trades(h)) }
end

#tradesHash

Returns transacoes trades.

Returns:

  • (Hash)

    transacoes trades



49
50
51
# File 'lib/cex/bitcoinde.rb', line 49

def trades
  @trades ||= exd[:tt].select { |h| kyt.include?(h[:trade_id]) }
end