Class: Cns::Apice

Inherits:
Object
  • Object
show all
Defined in:
lib/cns/apice.rb

Overview

classe para acesso dados centralized exchanges

Instance Method Summary collapse

Instance Method Details

#account_de(uri = 'https://api.bitcoin.de/v4/account') ⇒ Hash

Returns saldos no bitcoinde.

Examples:

account_de

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

  • uri (String) (defaults to: 'https://api.bitcoin.de/v4/account')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Hash)

    saldos no bitcoinde



32
33
34
35
36
37
38
39
# File 'lib/cns/apice.rb', line 32

def (uri = 'https://api.bitcoin.de/v4/account')
  JSON.parse(
    Curl.get(uri) { |obj| obj.headers = hde(uri) }.body,
    symbolize_names: true
  )[:data][:balances]
rescue StandardError
  {}
end

#account_fr(uri = 'https://paymium.com/api/v1/user') ⇒ Hash

Returns saldos no paymium.

Examples:

account_fr

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

  • uri (String) (defaults to: 'https://paymium.com/api/v1/user')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Hash)

    saldos no paymium



57
58
59
60
61
62
63
64
# File 'lib/cns/apice.rb', line 57

def (uri = 'https://paymium.com/api/v1/user')
  JSON.parse(
    Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body,
    symbolize_names: true
  )
rescue StandardError
  {}
end

#account_mt(uri = 'https://api.therocktrading.com/v1/balances') ⇒ Array<Hash>

Returns lista saldos no therock.

Examples:

account_mt

{
  balances: [
    { currency: 'BTC', balance: 0.0, trading_balance: 0.0 },
    { currency: 'ETH', balance: 0.0, trading_balance: 0.0 },
    { currency: 'EUR', balance: 0.0, trading_balance: 0.0 },
    { currency: 'DAI', balance: 0.0, trading_balance: 0.0 },
  ]
}

Parameters:

  • uri (String) (defaults to: 'https://api.therocktrading.com/v1/balances')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Array<Hash>)

    lista saldos no therock



77
78
79
80
81
82
83
84
85
86
# File 'lib/cns/apice.rb', line 77

def (uri = 'https://api.therocktrading.com/v1/balances')
  JSON.parse(
    Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body,
    symbolize_names: true
  )[:balances]
      .delete_if { |del| DC.include?(del[:currency]) }
      .sort { |oba, obb| oba[:currency] <=> obb[:currency] }
rescue StandardError
  []
end

#account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc) ⇒ Hash

Returns saldos no kraken.

Examples:

account_us

{
 error: [],
 result: {
   ZEUR: '0.0038',
   XXBT: '0.0000000000',
   XETH: '1.0000000000',
   XETC: '0.0000000000',
   EOS: '0.0000001700',
   BCH: '0.0000000000'
 }
}

Parameters:

  • urb (String) (defaults to: 'https://api.kraken.com/0/private')

    Uniform Resource Base do pedido HTTP

  • uri (String) (defaults to: 'Balance')

    Uniform Resource Identifier do pedido HTTP

  • non (Integer) (defaults to: nnc)

    continually-increasing unsigned integer

Returns:

  • (Hash)

    saldos no kraken



104
105
106
107
108
109
110
111
# File 'lib/cns/apice.rb', line 104

def (urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc)
  JSON.parse(
    Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body,
    symbolize_names: true
  )[:result]
rescue StandardError
  {}
end

#deposit_unif(has) ⇒ Hash

Returns deposit uniformizado bitcoinde.

Examples:

deposit_unif

[
  {
    txid: 177_245,
    time: '2014-01-31T22:01:30+01:00',
    tp: 'deposit',
    add: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
    qt: '0.13283',
    moe: 'btc',
    fee: '0'
  },
  {}
]

Returns:

  • (Hash)

    deposit uniformizado bitcoinde



207
208
209
210
211
212
213
214
# File 'lib/cns/apice.rb', line 207

def deposit_unif(has)
  {
    add: has[:address],
    time: Time.parse(has[:created_at]),
    qt: has[:amount],
    txid: Integer(has[:deposit_id])
  }.merge(tp: 'deposit', moe: 'btc', fee: '0')
end

#deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits') ⇒ Array<Hash>

Returns lista completa uniformizada depositos bitcoinde.

Examples:

deposits_de

{
  deposits: [
    {
      deposit_id: '177245',
      txid: '84f9e85bc5709cd471e3d58a7d0f42d2c4a7bbd888cabf844e200efbf0a7fda2',
      address: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
      amount: '0.13283',
      confirmations: 6,
      state: 2,
      created_at: '2014-01-31T22:01:30+01:00'
    },
    {}
  ],
  page: { current: 1, last: 1 },
  errors: [],
  credits: 23
}

Parameters:

  • pag (Integer) (defaults to: 0)

    pagina dos dados

  • ary (Array<Hash>) (defaults to: [])

    acumulador dos dados

  • uri (String) (defaults to: 'https://api.bitcoin.de/v4/btc/deposits')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Array<Hash>)

    lista completa uniformizada depositos bitcoinde



183
184
185
186
187
188
189
190
191
# File 'lib/cns/apice.rb', line 183

def deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits')
  par = "#{uri}?#{URI.encode_www_form(state: 2, page: pag += 1)}"
  res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
  ary += res[:deposits].map { |has| deposit_unif(has) }
  rep = res[:page]
  rep[:current] < rep[:last] ? deposits_de(pag, ary) : ary
rescue StandardError
  ary
end

#ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders') ⇒ Array<Hash>

Returns lista ledger paymium.

Examples:

ledger_fr

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

  • pag (Integer) (defaults to: 0)

    pagina dos dados

  • ary (Array<Hash>) (defaults to: [])

    acumulador dos dados

  • uri (String) (defaults to: 'https://paymium.com/api/v1/user/orders')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Array<Hash>)

    lista ledger paymium



300
301
302
303
304
305
306
307
308
# File 'lib/cns/apice.rb', line 300

def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders')
  res = JSON.parse(
    Curl.get(uri, offset: pag) { |obj| obj.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body,
    symbolize_names: true
  )
  res.empty? ? ary : ledger_fr(pag + res.size, ary + res)
rescue StandardError
  ary
end

#ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions') ⇒ Array<Hash>

Returns lista ledger therock.

Examples:

ledger_mt

{
  transactions: [
    {
      id: 305_445,
      date: '2014-03-06T10:59:13.000Z',
      type: 'withdraw',
      price: 97.47,
      currency: 'EUR',
      fund_id: nil,
      order_id: nil,
      trade_id: nil,
      note: 'BOV withdraw',
      transfer_detail: nil
    },
    {}
  ],
  meta: {
    total_count: nil,
    first: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
    previous: nil,
    current: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
    next: { page: 2, href: 'https://api.therocktrading.com/v1/transactions?page=2' },
    last: nil
  }
}

Parameters:

  • pag (Integer) (defaults to: 1)

    pagina dos dados

  • ary (Array<Hash>) (defaults to: [])

    acumulador dos dados

  • uri (String) (defaults to: 'https://api.therocktrading.com/v1/transactions')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Array<Hash>)

    lista ledger therock



338
339
340
341
342
343
344
345
346
# File 'lib/cns/apice.rb', line 338

def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions')
  res = JSON.parse(
    Curl.get(uri, page: pag) { |obj| obj.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body,
    symbolize_names: true
  )[:transactions]
  res.empty? ? ary : ledger_mt(pag + res.size, ary + res)
rescue StandardError
  ary
end

#ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') ⇒ Hash

Returns dados ledger kraken.

Examples:

ledger_us

{
  error: [],
  result: {
    ledger: {
      "LXXURB-ITI7S-CXVERS": {
        refid: 'ACCHF3A-RIBBMO-VYBESY',
        time: 1_543_278_716.2775,
        type: 'withdrawal',
        subtype: '',
        aclass: 'currency',
        asset: 'ZEUR',
        amount: '-15369.6200',
        fee: '0.0900',
        balance: '0.0062'
      },
      "OUTRO-LEDGER-ID": {}
    },
    count: 376
  }
}

Parameters:

  • ofs (Integer) (defaults to: 0)

    offset dos dados

  • has (Hash) (defaults to: {})

    acumulador dos dados

  • urb (String) (defaults to: 'https://api.kraken.com/0/private')

    Uniform Resource Base do pedido HTTP

  • uri (String)

    Uniform Resource Identifier do pedido HTTP

  • non (Integer)

    continually-increasing unsigned integer

Returns:

  • (Hash)

    dados ledger kraken



412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/cns/apice.rb', line 412

def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private')
  uri = 'Ledgers'
  non = nnc
  res = JSON.parse(
    Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
    symbolize_names: true
  )[:result]
  has.merge!(res[:ledger])
  sleep 2
  res[:ledger].count > 0 ? ledger_us(ofs + res[:ledger].count, has) : has
rescue StandardError
  has
end

#trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades') ⇒ Array<Hash>

Returns lista completa trades bitcoinde.

Examples:

trades_de

{
  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

  • ary (Array<Hash>) (defaults to: [])

    acumulador dos dados

  • uri (String) (defaults to: 'https://api.bitcoin.de/v4/trades')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Array<Hash>)

    lista completa trades bitcoinde



153
154
155
156
157
158
159
160
161
# File 'lib/cns/apice.rb', line 153

def trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades')
  par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}"
  res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
  ary += res[:trades]
  rep = res[:page]
  rep[:current] < rep[:last] ? trades_de(pag, ary) : ary
rescue StandardError
  ary
end

#trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') ⇒ Hash

Returns dados trades kraken.

Examples:

trades_us

{
  error: [],
  result: {
    trades: {
      "TVINF5-TIOUB-YFNGKE": {
        ordertxid: 'ORPSUW-YKP4F-UJZOC6',
        pair: 'XETHXXBT',
        time: 1_463_435_684.8387,
        type: 'buy',
        ordertype: 'market',
        price: '0.024989',
        cost: '1.193973',
        fee: '0.003104',
        vol: '47.77994129',
        margin: '0.000000',
        misc: ''
      },
      "OUTRO-TRADE-ID": {}
    },
    count: 157
  }
}

Parameters:

  • ofs (Integer) (defaults to: 0)

    offset dos dados

  • has (Hash) (defaults to: {})

    acumulador dos dados

  • urb (String) (defaults to: 'https://api.kraken.com/0/private')

    Uniform Resource Base do pedido HTTP

  • uri (String)

    Uniform Resource Identifier do pedido HTTP

  • non (Integer)

    continually-increasing unsigned integer

Returns:

  • (Hash)

    dados trades kraken



375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/cns/apice.rb', line 375

def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private')
  uri = 'TradesHistory'
  non = nnc
  res = JSON.parse(
    Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
    symbolize_names: true
  )[:result]
  has.merge!(res[:trades])
  sleep 2
  res[:trades].count > 0 ? trades_us(ofs + res[:trades].count, has) : has
rescue StandardError
  has
end

#withdrawal_unif(has) ⇒ Hash

Returns withdrawal uniformizada bitcoinde.

Examples:

withdrawal_unif

[
  {
    txid: 136_605,
    time: '2014-02-05T13:05:17+01:00',
    tp: 'withdrawal',
    add: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
    qt: '0.120087',
    fee: '0',
    moe: 'btc'
  },
  {}
]

Returns:

  • (Hash)

    withdrawal uniformizada bitcoinde



262
263
264
265
266
267
268
269
270
# File 'lib/cns/apice.rb', line 262

def withdrawal_unif(has)
  {
    add: has[:address],
    time: Time.parse(has[:transferred_at]),
    qt: has[:amount],
    fee: has[:network_fee],
    txid: Integer(has[:withdrawal_id])
  }.merge(tp: 'withdrawal', moe: 'btc')
end

#withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals') ⇒ Array<Hash>

Returns lista completa uniformizada withdrawals bitcoinde.

Examples:

withdrawals_de

{
  withdrawals: [
    {
      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
    },
    {}
  ],
  page: { current: 1, last: 2 },
  errors: [],
  credits: 23
}

Parameters:

  • pag (Integer) (defaults to: 0)

    pagina dos dados

  • ary (Array<Hash>) (defaults to: [])

    acumulador dos dados

  • uri (String) (defaults to: 'https://api.bitcoin.de/v4/btc/withdrawals')

    Uniform Resource Identifier do pedido HTTP

Returns:

  • (Array<Hash>)

    lista completa uniformizada withdrawals bitcoinde



238
239
240
241
242
243
244
245
246
# File 'lib/cns/apice.rb', line 238

def withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals')
  par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}"
  res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
  ary += res[:withdrawals].map { |has| withdrawal_unif(has) }
  rep = res[:page]
  rep[:current] < rep[:last] ? withdrawals_de(pag, ary) : ary
rescue StandardError
  ary
end