Class: Kaesen::Bitflyer
Overview
bitFlyer Wrapper Class lightning.bitflyer.jp/docs?lang=ja API制限. Private API は 1 分間に約 200 回を上限とします。. IP アドレスごとに 1 分間に約 500 回を上限とします。
Direct Known Subclasses
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
abstract
Buy 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| ... } ⇒ Bitflyer
constructor
A new instance of Bitflyer.
-
#market_buy(amount = BigDecimal.new("0.0")) ⇒ hash
abstract
Buy the amount of Bitcoin from the market.
-
#market_sell(amount = BigDecimal.new("0.0")) ⇒ hash
abstract
Sell the amount of Bitcoin to the market.
-
#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
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Bitflyer
Returns a new instance of Bitflyer.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kaesen/bitflyer.rb', line 18 def initialize( = {}) super() @name = "bitFlyer" @api_key = ENV["BITFLYER_KEY"] @api_secret = ENV["BITFLYER_SECRET"] @url_public = "https://api.bitflyer.jp/v1" @url_private = @url_public @product_code = "BTC_JPY" .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Method Details
#balance ⇒ hash
Get account balance.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/kaesen/bitflyer.rb', line 94 def balance have_key? h = get_ssl_with_sign(@url_private + "/me/getbalance") { "jpy" => { "amount" => BigDecimal.new(h[0]["amount"].to_s), "available" => BigDecimal.new(h[0]["available"].to_s), }, "btc" => { "amount" => BigDecimal.new(h[1]["amount"].to_s), "available" => BigDecimal.new(h[1]["available"].to_s), }, "ltimestamp" => Time.now.to_i, } end |
#buy(rate, amount = BigDecimal.new(0)) ⇒ hash
Buy the amount of Bitcoin at the rate. 指数注文 買い.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/kaesen/bitflyer.rb', line 155 def buy(rate, amount=BigDecimal.new(0)) have_key? address = @url_private + "/me/sendchildorder" body = { "product_code" => @product_code, "child_order_type" => "LIMIT", "side" => "BUY", "price" => rate.to_i, "size" => amount.to_f.round(4), "minute_to_expire" => 525600, "time_in_force" => "GTC", } h = post_ssl_with_sign(address, body) { "success" => "true", "id" => h["child_order_acceptance_id"].to_s, "rate" => BigDecimal.new(rate.to_s), "amount" => BigDecimal.new(amount.to_s), "order_type" => "buy", "ltimestamp" => Time.now.to_i, } end |
#cancel(id) ⇒ hash
Cancel an open order
284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/kaesen/bitflyer.rb', line 284 def cancel(id) have_key? address = @url_private + "/me/cancelchildorder" body = { "product_code" => @product_code, "child_order_acceptance_id" => id } h = post_ssl_with_sign(address, body) { "success" => h } end |
#cancel_all ⇒ array
Cancel all open orders
301 302 303 304 305 306 |
# File 'lib/kaesen/bitflyer.rb', line 301 def cancel_all have_key? opens.collect{|h| cancel(h["id"]) } end |
#depth ⇒ hash
Get order book.
71 72 73 74 75 76 77 78 |
# File 'lib/kaesen/bitflyer.rb', line 71 def depth h = get_ssl(@url_public + "/getboard?product_code=#{@product_code}") { "asks" => h["asks"].map{|x| [BigDecimal.new(x["price"].to_s), BigDecimal.new(x["size"].to_s)]}, "bids" => h["bids"].map{|x| [BigDecimal.new(x["price"].to_s), BigDecimal.new(x["size"].to_s)]}, "ltimestamp" => Time.now.to_i, } end |
#market_buy(amount = BigDecimal.new("0.0")) ⇒ hash
Buy the amount of Bitcoin from the market. 成行注文 買い.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/kaesen/bitflyer.rb', line 189 def market_buy(amount=BigDecimal.new("0.0")) have_key? address = @url_private + "/me/sendchildorder" body = { "product_code" => @product_code, "child_order_type" => "MARKET", "side" => "BUY", "size" => amount.to_f.round(4), "minute_to_expire" => 525600, "time_in_force" => "GTC", } h = post_ssl_with_sign(address, body) { "success" => "true", "id" => h["child_order_acceptance_id"].to_s, # "rate" is not supplied. "amount" => BigDecimal.new(amount.to_s), "order_type" => "buy", "ltimestamp" => Time.now.to_i, } end |
#market_sell(amount = BigDecimal.new("0.0")) ⇒ hash
Sell the amount of Bitcoin to the market. 成行注文 売り.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/kaesen/bitflyer.rb', line 257 def market_sell(amount=BigDecimal.new("0.0")) have_key? address = @url_private + "/me/sendchildorder" body = { "product_code" => @product_code, "child_order_type" => "MARKET", "side" => "SELL", "size" => amount.to_f.round(4), "minute_to_expire" => 525600, "time_in_force" => "GTC", } h = post_ssl_with_sign(address, body) { "success" => "true", "id" => h["child_order_acceptance_id"].to_s, # "rate" is not supplied. "amount" => BigDecimal.new(amount.to_s), "order_type" => "sell", "ltimestamp" => Time.now.to_i, } end |
#opens ⇒ Array
Get open orders.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/kaesen/bitflyer.rb', line 121 def opens have_key? address = @url_private + "/me/getchildorders" query = { "child_order_state" => "ACTIVE", } address += "?" + query.to_a.map{|x|"#{x[0]}=#{x[1]}" }.join("&") body = { "product_code" => @product_code, } a = get_ssl_with_sign(address, body) a.map{|x| { "success" => "true", "id" => x["child_order_acceptance_id"], "rate" => BigDecimal.new(x["average_price"].to_s), "amount" => BigDecimal.new(x["size"].to_s), "order_type" => x["side"].downcase, } } end |
#sell(rate, amount = BigDecimal.new(0)) ⇒ hash
Sell the amount of Bitcoin at the rate. 指数注文 売り. Abstract Method.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/kaesen/bitflyer.rb', line 223 def sell(rate, amount=BigDecimal.new(0)) have_key? address = @url_private + "/me/sendchildorder" body = { "product_code" => @product_code, "child_order_type" => "LIMIT", "side" => "SELL", "price" => rate.to_i, "size" => amount.to_f.round(4), "minute_to_expire" => 525600, "time_in_force" => "GTC", } h = post_ssl_with_sign(address, body) { "success" => "true", "id" => h["child_order_acceptance_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.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kaesen/bitflyer.rb', line 47 def ticker h = get_ssl(@url_public + "/getticker?product_code=#{@product_code}") { "ask" => BigDecimal.new(h["best_ask"].to_s), "bid" => BigDecimal.new(h["best_bid"].to_s), "last" => BigDecimal.new(h["ltp"].to_s), # "high" is not supplied. # "low" is not supplied. "volume" => BigDecimal.new(h["volume"].to_s), "ltimestamp" => Time.now.to_i, "timestamp" => DateTime.parse(h["timestamp"]).to_time.to_i, } end |