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
#api_key, #api_secret, #name, #url_private, #url_public
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.
-
#cancel(id) ⇒ hash
abstract
Cancel an open order.
-
#cancel_all ⇒ array
abstract
Cancel all open orders.
-
#depth ⇒ hash
abstract
Get order book.
-
#initialize(options = {}) {|_self| ... } ⇒ 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
#market_buy, #market_sell, unBigDecimal
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Btcbox
Returns a new instance of Btcbox.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Method Details
#balance ⇒ hash
This method is abstract.
Get account balance.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kaesen/btcbox.rb', line 87 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.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/kaesen/btcbox.rb', line 143 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 |
#cancel(id) ⇒ hash
This method is abstract.
Cancel an open order
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/kaesen/btcbox.rb', line 198 def cancel(id) have_key? address = @url_private + "/trade_cancel/" params = { "id" => id, } h = post_ssl_with_sign(address, params) { "success" => h["result"], } end |
#cancel_all ⇒ array
This method is abstract.
Cancel all open orders
214 215 216 217 218 219 |
# File 'lib/kaesen/btcbox.rb', line 214 def cancel_all have_key? opens.collect{|h| cancel(h["id"]) } end |
#depth ⇒ hash
This method is abstract.
Get order book.
64 65 66 67 68 69 70 71 |
# File 'lib/kaesen/btcbox.rb', line 64 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.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kaesen/btcbox.rb', line 113 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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/kaesen/btcbox.rb', line 174 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.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/kaesen/btcbox.rb', line 41 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 |