Class: Kaesen::Coincheck
Overview
Coincheck Wrapper Class coincheck.com/documents/exchange/api?locale=ja
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| ... } ⇒ Coincheck
constructor
A new instance of Coincheck.
-
#market_buy(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
abstract
Sell the amount of Bitcoin at the rate.
-
#ticker ⇒ hash
Get ticker information.
Methods inherited from Market
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Coincheck
Returns a new instance of Coincheck.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kaesen/coincheck.rb', line 14 def initialize( = {}) super() @name = "Coincheck" @api_key = ENV["COINCHECK_KEY"] @api_secret = ENV["COINCHECK_SECRET"] @url_public = "https://coincheck.com" @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
Get account balance.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/kaesen/coincheck.rb', line 90 def balance have_key? address = @url_private + "/api/accounts/balance" h = get_ssl_with_sign(address) { "jpy" => { "amount" => BigDecimal.new(h["jpy"].to_s) + BigDecimal.new(h["jpy_reserved"].to_s), "available" => BigDecimal.new(h["jpy"].to_s), }, "btc" => { "amount" => BigDecimal.new(h["btc"].to_s) + BigDecimal.new(h["btc_reserved"].to_s), "available" => BigDecimal.new(h["btc"].to_s), }, "ltimestamp" => Time.now.to_i, } end |
#buy(rate, amount = BigDecimal.new(0)) ⇒ hash
Buy the amount of Bitcoin at the rate. 指数注文 買い.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kaesen/coincheck.rb', line 145 def buy(rate, amount=BigDecimal.new(0)) have_key? address = @url_private + "/api/exchange/orders" body = { "rate" => rate.to_i, "amount" => amount.to_f.round(4), "order_type" => "buy", "pair" => "btc_jpy", } h = post_ssl_with_sign(address,body) { "success" => h["success"].to_s, "id" => h["id"].to_s, "rate" => BigDecimal.new(h["rate"].to_s), "amount" => BigDecimal.new(h["size"].to_s), "order_type" => h["order_type"], "ltimestamp" => Time.now.to_i, "timestamp" => DateTime.parse(h["created_at"]).to_time.to_i, } end |
#cancel(id) ⇒ hash
Cancel an open order
267 268 269 270 271 272 273 274 275 |
# File 'lib/kaesen/coincheck.rb', line 267 def cancel(id) have_key? address = @url_privat + "/api/exchange/orders/" + id body = { } h = delete_ssl_with_sign(address, body) { "success" => h["success"], } end |
#cancel_all ⇒ array
Cancel all open orders
281 282 283 284 285 286 |
# File 'lib/kaesen/coincheck.rb', line 281 def cancel_all have_key? opens.collect{|h| cancel(h["id"]) } end |
#depth ⇒ hash
Get order book.
67 68 69 70 71 72 73 74 |
# File 'lib/kaesen/coincheck.rb', line 67 def depth h = get_ssl(@url_public + "/api/order_books") { "asks" => h["asks"].map{|a,b| [BigDecimal.new(a.to_s), BigDecimal.new(b.to_s)]}, "bids" => h["bids"].map{|a,b| [BigDecimal.new(a.to_s), BigDecimal.new(b.to_s)]}, "ltimestamp" => Time.now.to_i, } end |
#market_buy(market_buy_amount = BigDecimal.new("0.0")) ⇒ hash
Buy the amount of Bitcoin from the market. 成行注文 買い.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/kaesen/coincheck.rb', line 177 def market_buy(market_buy_amount=BigDecimal.new("0.0")) have_key? address = @url_private + "/api/exchange/orders" body = { "market_buy_amount" => market_buy_amount.to_f.round(4), "order_type" => "market_buy", "pair" => "btc_jpy", } h = post_ssl_with_sign(address,body) { "success" => h["success"].to_s, "id" => h["id"].to_s, "rate" => BigDecimal.new(h["rate"].to_s), "amount" => BigDecimal.new(h["size"].to_s), "order_type" => h["order_type"], "ltimestamp" => Time.now.to_i, "timestamp" => DateTime.parse(h["created_at"]).to_time.to_i, } end |
#market_sell(amount = BigDecimal.new("0.0")) ⇒ hash
Sell the amount of Bitcoin to the market. 成行注文 売り.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/kaesen/coincheck.rb', line 242 def market_sell(amount=BigDecimal.new("0.0")) have_key? address = @url_private + "/api/exchange/orders" body = { "amount" => amount.to_f.round(4), "order_type" => "market_sell", "pair" => "btc_jpy", } h = post_ssl_with_sign(address,body) { "success" => h["success"].to_s, "id" => h["id"].to_s, "rate" => BigDecimal.new(h["rate"].to_s), "amount" => BigDecimal.new(h["size"].to_s), "order_type" => h["order_type"], "ltimestamp" => Time.now.to_i, "timestamp" => DateTime.parse(h["created_at"]).to_time.to_i, } end |
#opens ⇒ Array
Get open orders.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/kaesen/coincheck.rb', line 117 def opens have_key? address = @url_private + "/api/exchange/orders/opens" h = get_ssl_with_sign(address) h["orders"].map{|x| { "success" => "true", "id" => x["id"].to_s, "rate" => BigDecimal.new(x["rate"].to_s), "amount" => BigDecimal.new(x["pending_amount"].to_s), "order_type" => x["order_type"], } } end |
#sell(rate, amount = BigDecimal.new(0)) ⇒ hash
Sell the amount of Bitcoin at the rate. 指数注文 売り.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/kaesen/coincheck.rb', line 210 def sell(rate, amount=BigDecimal.new(0)) have_key? address = @url_private + "/api/exchange/orders" body = { "rate" => rate.to_i, "amount" => amount.to_f.round(4), "order_type" => "sell", "pair" => "btc_jpy", } h = post_ssl_with_sign(address,body) { "success" => h["success"].to_s, "id" => h["id"].to_s, "rate" => BigDecimal.new(h["rate"].to_s), "amount" => BigDecimal.new(h["size"].to_s), "order_type" => h["order_type"], "ltimestamp" => Time.now.to_i, "timestamp" => DateTime.parse(h["created_at"]).to_time.to_i, } end |
#ticker ⇒ hash
Get ticker information.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kaesen/coincheck.rb', line 42 def ticker h = get_ssl(@url_public + "/api/ticker") @ticker = { "ask" => BigDecimal.new(h["ask"].to_s), "bid" => BigDecimal.new(h["bid"].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["volume"].to_s), "ltimestamp" => Time.now.to_i, "timestamp" => h["timestamp"].to_i, } end |