Class: Kaesen::Btcbox
Overview
BtcBox Wrapper Class www.btcbox.co.jp/help/api.html
Constant Summary collapse
- @@nonce =
0
Instance Attribute Summary
Attributes inherited from Market
Instance Method Summary collapse
-
#balance ⇒ hash
abstract
Get account balance.
-
#buy(rate, amount = BigDecimal.new(0)) ⇒ hash
Bought the amount of Bitcoin at the rate.
-
#depth ⇒ hash
abstract
Get order book.
-
#initialize ⇒ Btcbox
constructor
A new instance of Btcbox.
-
#opens ⇒ Array
abstract
Get open orders.
-
#sell(rate, amount = BigDecimal.new(0)) ⇒ hash
Sell the amount of Bitcoin at the rate.
-
#ticker ⇒ hash
Get ticker information.
Methods inherited from Market
#cancel, #cancel_all, #market_buy, #market_sell, unBigDecimal
Constructor Details
#initialize ⇒ Btcbox
Returns a new instance of Btcbox.
14 15 16 17 18 19 20 21 |
# File 'lib/kaesen/btcbox.rb', line 14 def initialize() super() @name = "BtcBox" @api_key = ENV["BTCBOX_KEY"] @api_secret = ENV["BTCBOX_SECRET"] @url_public = "https://www.btcbox.co.jp/api/v1" @url_private = @url_public end |
Instance Method Details
#balance ⇒ hash
This method is abstract.
Get account balance.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/kaesen/btcbox.rb', line 82 def balance have_key? h = post_ssl_with_sign(@url_private + "/balance/") { "jpy" => { "amount" => BigDecimal.new(h["jpy_balance"].to_s) + BigDecimal.new(h["jpy_lock"].to_s), "available" => BigDecimal.new(h["jpy_balance"].to_s), }, "btc" => { "amount" => BigDecimal.new(h["btc_balance"].to_s) + BigDecimal.new(h["btc_lock"].to_s), "available" => BigDecimal.new(h["btc_balance"].to_s), }, "ltimestamp" => Time.now.to_i, } end |
#buy(rate, amount = BigDecimal.new(0)) ⇒ hash
Bought the amount of Bitcoin at the rate. 指数注文 買い. Abstract Method.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/kaesen/btcbox.rb', line 138 def buy(rate, amount=BigDecimal.new(0)) have_key? address = @url_private + "/trade_add/" params = { "amount" => amount.to_f.round(4), "price" => rate.to_i, "type" => "buy", } h = post_ssl_with_sign(address, params) { "success" => h["result"].to_s, "id" => h["id"].to_s, "rate" => BigDecimal.new(rate.to_s), "amount" => BigDecimal.new(amount.to_s), "order_type" => "sell", "ltimestamp" => Time.now.to_i, } end |
#depth ⇒ hash
This method is abstract.
Get order book.
59 60 61 62 63 64 65 66 |
# File 'lib/kaesen/btcbox.rb', line 59 def depth h = get_ssl(@url_public + "/depth") { "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 |
#opens ⇒ Array
This method is abstract.
Get open orders.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/kaesen/btcbox.rb', line 108 def opens have_key? address = @url_private + "/trade_list/" params = { "type" => "open", } h = post_ssl_with_sign(address, params) h.map{|x| { "success" => "true", "id" => x["id"], "rate" => BigDecimal.new(x["price"].to_s), "amount" => BigDecimal.new(x["amount_outstanding"].to_s), "order_type" => x["type"], } } end |
#sell(rate, amount = BigDecimal.new(0)) ⇒ hash
Sell the amount of Bitcoin at the rate. 指数注文 売り. Abstract Method.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/kaesen/btcbox.rb', line 169 def sell(rate, amount=BigDecimal.new(0)) have_key? address = @url_private + "/trade_add/" params = { "amount" => amount.to_f.round(4), "price" => rate.to_i, "type" => "sell", } h = post_ssl_with_sign(address, params) { "success" => h["result"].to_s, "id" => h["id"].to_s, "rate" => BigDecimal.new(rate.to_s), "amount" => BigDecimal.new(amount.to_s), "order_type" => "sell", "ltimestamp" => Time.now.to_i, } end |
#ticker ⇒ hash
Get ticker information.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kaesen/btcbox.rb', line 36 def ticker h = get_ssl(@url_public + "/ticker") { "ask" => BigDecimal.new(h["sell"].to_s), "bid" => BigDecimal.new(h["buy"].to_s), "last" => BigDecimal.new(h["last"].to_s), "high" => BigDecimal.new(h["high"].to_s), "low" => BigDecimal.new(h["low"].to_s), "volume" => BigDecimal.new(h["vol"].to_s), "ltimestamp" => Time.now.to_i, } end |