Class: Cex::Apius

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

Overview

classe para processar dados no kraken

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pky: ENV['KRAKEN_API_KEY'], psc: ENV['KRAKEN_API_SECRET'], ops: { www: 'https://api.kraken.com', ver: 0 }) ⇒ Apius

Returns API kraken base.

Parameters:

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

    API key

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

    API secret

  • ops (Hash) (defaults to: { www: 'https://api.kraken.com', ver: 0 })

    parametrizacao base da API



25
26
27
28
29
30
31
32
33
34
# File 'lib/cex/apius.rb', line 25

def initialize(
  pky: ENV['KRAKEN_API_KEY'],
  psc: ENV['KRAKEN_API_SECRET'],
  ops: { www: 'https://api.kraken.com', ver: 0 }
)
  @aky = pky
  @asc = psc
  @urb = "#{ops[:www]}/#{ops[:ver]}"
  @pth = "/#{ops[:ver]}/private/"
end

Instance Attribute Details

#akyString (readonly)

Returns API key.

Returns:

  • (String)

    API key



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

def aky
  @aky
end

#ascString (readonly)

Returns API secret.

Returns:

  • (String)

    API secret



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

def asc
  @asc
end

#pthString (readonly)

Returns API private path.

Returns:

  • (String)

    API private path



19
20
21
# File 'lib/cex/apius.rb', line 19

def pth
  @pth
end

#urbString (readonly)

Returns API url base.

Returns:

  • (String)

    API url base



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

def urb
  @urb
end

Instance Method Details

#accountHash

Returns saldos no kraken.

Examples:

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

Returns:

  • (Hash)

    saldos no kraken



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

def 
  api_post('Balance')[:result]
end

#ledger(ofs = 0, has = {}) ⇒ Hash

Returns dados ledger no kraken.

Examples:

{
  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 a obter

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

    acumulador dos dados a obter

Returns:

  • (Hash)

    dados ledger no kraken



111
112
113
114
115
116
117
118
# File 'lib/cex/apius.rb', line 111

def ledger(ofs = 0, has = {})
  r = api_post('Ledgers', ofs: ofs)[:result]
  has.merge!(r[:ledger])
  ofs += 50
  ofs < r[:count] ? ledger(ofs, has) : has
rescue StandardError
  has
end

#trades(ofs = 0, has = {}) ⇒ Hash

Returns dados trades no kraken.

Examples:

{
  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 a obter

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

    acumulador dos dados a obter

Returns:

  • (Hash)

    dados trades no kraken



79
80
81
82
83
84
85
86
# File 'lib/cex/apius.rb', line 79

def trades(ofs = 0, has = {})
  r = api_post('TradesHistory', ofs: ofs)[:result]
  has.merge!(r[:trades])
  ofs += 50
  ofs < r[:count] ? trades(ofs, has) : has
rescue StandardError
  has
end