Class: Kaesen::Kraken

Inherits:
Market
  • Object
show all
Defined in:
lib/kaesen/kraken.rb

Overview

Kraken Wrapper Class www.kraken.com/help/api

Constant Summary collapse

@@nonce =
0

Instance Attribute Summary

Attributes inherited from Market

#name

Instance Method Summary collapse

Methods inherited from Market

#balance, #buy, #cancel, #cancel_all, #market_buy, #market_sell, #opens, #sell, unBigDecimal

Constructor Details

#initializeKraken

Returns a new instance of Kraken.



14
15
16
17
18
19
20
21
# File 'lib/kaesen/kraken.rb', line 14

def initialize()
  super()
  @name        = "Kraken"
  @api_key     = ENV["KRAKEN_KEY"]
  @api_secret  = ENV["KRAKEN_SECRET"]
  @url_public  = "https://api.kraken.com/0/public"
  @url_private = "https://api.kraken.com/0/private"
end

Instance Method Details

#depthhash

This method is abstract.

Get order book.

Returns:

  • (hash)

    array of market depth asks: [Array] 売りオーダー

    price : [BigDecimal]
    size : [BigDecimal]
    

    bids: [Array] 買いオーダー

    price : [BigDecimal]
    size : [BigDecimal]
    

    ltimestamp: [int] ローカルタイムスタンプ



62
63
64
65
66
67
68
69
70
# File 'lib/kaesen/kraken.rb', line 62

def depth
  h = get_ssl(@url_public + "/Depth?pair=XXBTZJPY")
  h = h["XXBTZJPY"]
  {
    "asks"       => h["asks"].map{|a,b,t| [BigDecimal.new(a.to_s), BigDecimal.new(b.to_s)]}, # to_s でないと誤差が生じる
    "bids"       => h["bids"].map{|a,b,t| [BigDecimal.new(a.to_s), BigDecimal.new(b.to_s)]}, # to_s でないと誤差が生じる
    "ltimestamp" => Time.now.to_i,
  }
end

#tickerhash

Get ticker information.

Returns:

  • (hash)

    ticker ask: [BigDecimal] 最良売気配値bid: [BigDecimal] 最良買気配値last: [BigDecimal] 最近値(?用語要チェック), last price high: [BigDecimal] 高値low: [BigDecimal] 安値volume: [BigDecimal] 取引量ltimestamp: [int] ローカルタイムスタンプvwap: [BigDecimal] 過去24時間の加重平均



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kaesen/kraken.rb', line 37

def ticker
  h = get_ssl(@url_public + "/Ticker?pair=XXBTZJPY") # cf. XBTJPY is alias of XXBTZJPY
  h = h["XXBTZJPY"]
  {
    "ask"        => BigDecimal.new(h["a"][0]),
    "bid"        => BigDecimal.new(h["b"][0]),
    "last"       => BigDecimal.new(h["c"][0]),
    "high"       => BigDecimal.new(h["h"][1]), # of the previous 24 hours
    "low"        => BigDecimal.new(h["l"][1]), # of the previous 24 hours
    "volume"     => BigDecimal.new(h["v"][1]), # of the previous 24 hours
    "ltimestamp" => Time.now.to_i,
    "vwap"       => BigDecimal.new(h["p"][1]), # of the previous 24 hours
  }
end