Class: Cns::Apice

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

Overview

classe para acesso dados centralized exchanges

Constant Summary collapse

API =
{de: 'https://api.bitcoin.de/v4', us: 'https://api.kraken.com/0/private'}.freeze

Instance Method Summary collapse

Constructor Details

#initializeApice

Returns a new instance of Apice.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cns/apice.rb', line 14

def initialize
  @curl =
    Curl::Easy.new.tap do |c|
      c.timeout = 30
      c.connect_timeout = 10
      c.follow_location = true
      c.ssl_verify_peer = true
    end
  @deky = ENV.fetch('BITCOINDE_API_KEY', nil)
  @desc = ENV.fetch('BITCOINDE_API_SECRET', nil)
  @usky = ENV.fetch('KRAKEN_API_KEY', nil)
  @ussc = ENV.fetch('KRAKEN_API_SECRET', nil)
end

Instance Method Details

#account_deHash

Get account balances from Bitcoin.de

Returns:

  • (Hash)

    saldos no bitcoinde



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

def 
  uri = "#{API[:de]}/account"
  rcrl(@curl, uri, headers: hde(uri))
  pjsn(@curl).dig(:data, :balances) || {}
rescue Curl::Err::CurlError
  {}
end

#account_usHash

Get account balances from Kraken

Returns:

  • (Hash)

    saldos kraken



64
65
66
67
68
69
70
71
# File 'lib/cns/apice.rb', line 64

def 
  uri = 'Balance'
  ops = {nonce: nnc}
  rcrl(@curl, "#{API[:us]}/#{uri}", method: 'POST', post_data: ops, headers: hus(uri, ops))
  pjsn(@curl).fetch(:result, {})
rescue Curl::Err::CurlError
  {}
end

#deposits_deArray<Hash>

Get deposits from Bitcoin.de, uniformly formatted

Returns:

  • (Array<Hash>)

    depositos uniformizados bitcoinde



48
49
50
51
52
# File 'lib/cns/apice.rb', line 48

def deposits_de
  pag_de_req("#{API[:de]}/btc/deposits", {state: 2}, :deposits) { |i| i.map { |h| deposit_unif(h) } }
rescue Curl::Err::CurlError
  []
end

#ledger_usHash

Get ledger from Kraken

Returns:

  • (Hash)

    ledger kraken



83
84
85
86
87
# File 'lib/cns/apice.rb', line 83

def ledger_us
  pag_us_req('Ledgers', :ledger)
rescue Curl::Err::CurlError
  []
end

#trades_deArray<Hash>

Get trades from Bitcoin.de

Returns:

  • (Array<Hash>)

    trades bitcoinde



40
41
42
43
44
# File 'lib/cns/apice.rb', line 40

def trades_de
  pag_de_req("#{API[:de]}/trades", {state: 1}, :trades)
rescue Curl::Err::CurlError
  []
end

#trades_usHash

Get trades from Kraken

Returns:

  • (Hash)

    trades kraken



75
76
77
78
79
# File 'lib/cns/apice.rb', line 75

def trades_us
  pag_us_req('TradesHistory', :trades)
rescue Curl::Err::CurlError
  []
end

#withdrawals_deArray<Hash>

Get withdrawals from Bitcoin.de, uniformly formatted

Returns:

  • (Array<Hash>)

    withdrawals uniformizadas bitcoinde



56
57
58
59
60
# File 'lib/cns/apice.rb', line 56

def withdrawals_de
  pag_de_req("#{API[:de]}/btc/withdrawals", {state: 1}, :withdrawals) { |i| i.map { |h| withdrawal_unif(h) } }
rescue Curl::Err::CurlError
  []
end