Class: Krkt::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/krkt/client.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'], options: {}) ⇒ Client

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



26
27
28
29
30
31
32
33
34
# File 'lib/krkt/client.rb', line 26

def initialize(pky: ENV['KRAKEN_API_KEY'], psc: ENV['KRAKEN_API_SECRET'], options: {})
  b = options.fetch(:base_uri, 'https://api.kraken.com')
  v = options.fetch(:version, 0)
  @aky = pky
  @asc = psc
  @puu = "#{b}/#{v}/public/"
  @pru = "#{b}/#{v}/private/"
  @pth = "/#{v}/private/"
end

Instance Attribute Details

#akyString (readonly)

Returns API key.

Returns:

  • (String)

    API key



13
14
15
# File 'lib/krkt/client.rb', line 13

def aky
  @aky
end

#ascString (readonly)

Returns API secret.

Returns:

  • (String)

    API secret



15
16
17
# File 'lib/krkt/client.rb', line 15

def asc
  @asc
end

#pruString (readonly)

Returns API private url.

Returns:

  • (String)

    API private url



19
20
21
# File 'lib/krkt/client.rb', line 19

def pru
  @pru
end

#pthString (readonly)

Returns API private path.

Returns:

  • (String)

    API private path



21
22
23
# File 'lib/krkt/client.rb', line 21

def pth
  @pth
end

#puuString (readonly)

Returns API public url.

Returns:

  • (String)

    API public url



17
18
19
# File 'lib/krkt/client.rb', line 17

def puu
  @puu
end

Instance Method Details

#balanceHash

Returns saldos no kraken.

Examples:

{
  'ZEUR' => '0.0000',
  'XXBT' => '0.0000000000',
  'XETH' => '1.1806988100',
  'XETC' => '0.0000000000',
  'EOS' => '0.0000001700',
  'BCH' => '0.0000000000'
}

Returns:

  • (Hash)

    saldos no kraken



95
96
97
# File 'lib/krkt/client.rb', line 95

def balance
  post_private('Balance')['result']
end

#ledgerHash

Returns resultados ultimas transacoes ledger no kraken.

Examples:

{
  'ledger' => {
    'LUK3QC-QW6TA-27B7NI' => {
      'refid' => 'A2BNCQS-CHCETZ-JYCER6',
      'time' => 1_584_349_306.9479,
      'type' => 'withdrawal',
      'subtype' => '',
      'aclass' => 'currency',
      'asset' => 'XETH',
      'amount' => '-29.2659039100',
      'fee' => '0.0050000000',
      'balance' => '1.1806988100'
    }
    ,
    ...
  },
  'count' => 373
}

Returns:

  • (Hash)

    resultados ultimas transacoes ledger no kraken



81
82
83
# File 'lib/krkt/client.rb', line 81

def ledger
  post_private('Ledgers')['result']
end

#server_timeHash

Returns data hora kraken.

Examples:

{
  'unixtime' => 1_598_956_727,
  'rfc1123' => 'Tue,  1 Sep 20 10:38:47 +0000'
}

Returns:

  • (Hash)

    data hora kraken



105
106
107
# File 'lib/krkt/client.rb', line 105

def server_time
  get_public('Time')['result']
end

#trades_historyHash

Returns resultados ultimas transacoes trades no kraken.

Examples:

{
  'trades' => {
    'TLADFV-QIUTN-QDNCBR' => {
      'ordertxid' => 'O2CRFG-5PCJA-EMX7VC',
      'pair' => 'XETHXXBT',
      'time' => 1_463_422_494.7069,
      'type' => 'buy',
      'ordertype' => 'market',
      'price' => '0.024400',
      'cost' => '1.358424',
      'fee' => '0.003532',
      'vol' => '55.67311475',
      'margin' => '0.000000',
      'misc' => ''
    },
    ...
  },
  'count' => 156
}

Returns:

  • (Hash)

    resultados ultimas transacoes trades no kraken



57
58
59
# File 'lib/krkt/client.rb', line 57

def trades_history
  post_private('TradesHistory')['result']
end