Class: Kaesen::Bitbank

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

Overview

Bitbank Wrapper Class docs.bitbank.cc/

Constant Summary collapse

@@nonce =
0

Instance Attribute Summary

Attributes inherited from Market

#api_key, #api_secret, #name, #url_private, #url_public

Instance Method Summary collapse

Methods inherited from Market

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

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Bitbank

Returns a new instance of Bitbank.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(options = {})
  super()
  @name        = "Bitbank"
  @api_key     = ENV["BITBANK_KEY"]
  @api_secret  = ENV["BITBANK_SECRET"]
  @url_public  = "https://public.bitbank.cc"
  @url_private = "https://api.bitbank.cc/v1"

  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
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] ローカルタイムスタンプ



67
68
69
70
71
72
73
74
75
# File 'lib/kaesen/bitbank.rb', line 67

def depth
  h = get_ssl(@url_public + "/btc_jpy/depth")
  h = h["data"]
  {
    "asks"       => h["asks"].map{|a,b| [BigDecimal.new(a.to_s), BigDecimal.new(b.to_s)]}, # to_s でないと誤差が生じる
    "bids"       => h["bids"].map{|a,b| [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] 取引量timestamp: [int] タイムスタンプltimestamp: [int] ローカルタイムスタンプ



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/kaesen/bitbank.rb', line 42

def ticker
  h = get_ssl(@url_public + "/btc_jpy/ticker")
  h = h["data"]
  {
    "ask"        => BigDecimal.new(h["sell"][0]),
    "bid"        => BigDecimal.new(h["buy"][0]),
    "last"       => BigDecimal.new(h["last"][0]),
    "high"       => BigDecimal.new(h["high"][1]), # of the previous 24 hours
    "low"        => BigDecimal.new(h["low"][1]), # of the previous 24 hours
    "volume"     => BigDecimal.new(h["vol"][1]), # of the previous 24 hours
    "ltimestamp" => Time.now.to_i,
    "timestamp"  => h["timestamp"],
  }
end