Class: Cex::Apide

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

Overview

classe para processar dados no bitcoinde

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pky: ENV['BITCOINDE_API_KEY'], psc: ENV['BITCOINDE_API_SECRET'], ops: { www: 'https://api.bitcoin.de', ver: 4 }) ⇒ Apide

Returns API bitcoinde base.

Parameters:

  • pky (String) (defaults to: ENV['BITCOINDE_API_KEY'])

    API key

  • psc (String) (defaults to: ENV['BITCOINDE_API_SECRET'])

    API secret

  • ops (Hash) (defaults to: { www: 'https://api.bitcoin.de', ver: 4 })

    parametrizacao base da API



23
24
25
26
27
28
29
30
31
# File 'lib/cex/apide.rb', line 23

def initialize(
  pky: ENV['BITCOINDE_API_KEY'],
  psc: ENV['BITCOINDE_API_SECRET'],
  ops: { www: 'https://api.bitcoin.de', ver: 4 }
)
  @aky = pky
  @asc = psc
  @urb = "#{ops[:www]}/v#{ops[:ver]}"
end

Instance Attribute Details

#akyString (readonly)

Returns API key.

Returns:

  • (String)

    API key



13
14
15
# File 'lib/cex/apide.rb', line 13

def aky
  @aky
end

#ascString (readonly)

Returns API secret.

Returns:

  • (String)

    API secret



15
16
17
# File 'lib/cex/apide.rb', line 15

def asc
  @asc
end

#urbString (readonly)

Returns API url base.

Returns:

  • (String)

    API url base



17
18
19
# File 'lib/cex/apide.rb', line 17

def urb
  @urb
end

Instance Method Details

#accountHash

Returns saldos no 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
}

Returns:

  • (Hash)

    saldos no bitcoinde



50
51
52
# File 'lib/cex/apide.rb', line 50

def 
  api_get('account')[:data][:balances]
end

#deposit_hash(hde) ⇒ Hash

Returns deposit uniformizado.

Examples:

{
  deposit_id: '177245',
  txid: '84f9e85bc5709cd471e3d58a7d0f42d2c4a7bbd888cabf844e200efbf0a7fda2',
  address: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
  amount: '0.13283',
  confirmations: 6,
  state: 2,
  created_at: '2014-01-31T22:01:30+01:00'
}

Parameters:

  • hde (Hash)

    dados dum deposit

Returns:

  • (Hash)

    deposit uniformizado



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/cex/apide.rb', line 173

def deposit_hash(hde)
  {
    id: hde[:address],
    tp: 'deposit',
    qtxt: 'btc',
    fee: '0',
    time: Time.parse(hde[:created_at]),
    qt: hde[:amount],
    lgid: Integer(hde[:deposit_id])
  }
end

#deposits(pag = 0, ary = []) ⇒ Array<Hash>

Returns lista depositos no bitcoinde.

Examples:

{
  deposits: [{}, {}],
  page: { current: 1, last: 1 },
  errors: [],
  credits: 23
}

Parameters:

  • pag (Integer) (defaults to: 0)

    pagina dos dados a obter

  • ary (Array) (defaults to: [])

    lista acumuladora dos dados a obter

Returns:

  • (Array<Hash>)

    lista depositos no bitcoinde



110
111
112
113
114
115
116
# File 'lib/cex/apide.rb', line 110

def deposits(pag = 0, ary = [])
  r = api_get('btc/deposits', state: 2, page: pag + 1)
  ary += r[:deposits].map { |h| deposit_hash(h) }
  r[:page][:current] < r[:page][:last] ? deposits(pag + 1, ary) : ary
rescue StandardError
  ary
end

#trades(pag = 0, ary = []) ⇒ Array<Hash>

Returns lista trades no bitcoinde.

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:

  • pag (Integer) (defaults to: 0)

    pagina dos dados a obter

  • ary (Array) (defaults to: [])

    lista acumuladora dos dados a obter

Returns:

  • (Array<Hash>)

    lista trades no bitcoinde



93
94
95
96
97
98
99
# File 'lib/cex/apide.rb', line 93

def trades(pag = 0, ary = [])
  r = api_get('trades', state: 1, page: pag + 1)
  ary += r[:trades]
  r[:page][:current] < r[:page][:last] ? trades(pag + 1, ary) : ary
rescue StandardError
  ary
end

#withdrawal_hash(hwi) ⇒ Hash

Returns withdrawal unifirmizada.

Examples:

{
  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:

  • hwi (Hash)

    dados duma withdrawal

Returns:

  • (Hash)

    withdrawal unifirmizada



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/cex/apide.rb', line 149

def withdrawal_hash(hwi)
  {
    id: hwi[:address],
    tp: 'out',
    qtxt: 'btc',
    fee: hwi[:network_fee],
    time: Time.parse(hwi[:transferred_at]),
    qt: hwi[:amount],
    lgid: Integer(hwi[:withdrawal_id])
  }
end

#withdrawals(pag = 0, ary = []) ⇒ Array<Hash>

Returns lista withdrawals no bitcoinde.

Examples:

{
  withdrawals: [{}, {}],
  page: { current: 1, last: 2 },
  errors: [],
  credits: 23
}

Parameters:

  • pag (Integer) (defaults to: 0)

    pagina dos dados a obter

  • ary (Array) (defaults to: [])

    lista acumuladora dos dados a obter

Returns:

  • (Array<Hash>)

    lista withdrawals no bitcoinde



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

def withdrawals(pag = 0, ary = [])
  r = api_get('btc/withdrawals', state: 1, page: pag + 1)
  ary += r[:withdrawals].map { |h| withdrawal_hash(h) }
  r[:page][:current] < r[:page][:last] ? withdrawals(pag + 1, ary) : ary
rescue StandardError
  ary
end