Class: Kaesen::Coincheck
Overview
Coincheck Wrapper Class coincheck.jp/documents/exchange/api?locale=ja
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
abstract
Buy the amount of Bitcoin at the rate.
-
#depth ⇒ hash
abstract
Get order book.
-
#initialize ⇒ 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
#cancel, #cancel_all, unBigDecimal
Constructor Details
#initialize ⇒ Coincheck
Returns a new instance of Coincheck.
14 15 16 17 18 19 20 21 |
# 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.jp" @url_private = @url_public end |
Instance Method Details
#balance ⇒ hash
This method is abstract.
Get account balance.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kaesen/coincheck.rb', line 85 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
This method is abstract.
Buy the amount of Bitcoin at the rate. 指数注文 買い.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/kaesen/coincheck.rb', line 140 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 |
#depth ⇒ hash
This method is abstract.
Get order book.
62 63 64 65 66 67 68 69 |
# File 'lib/kaesen/coincheck.rb', line 62 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
This method is abstract.
Buy the amount of Bitcoin from the market. 成行注文 買い.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/kaesen/coincheck.rb', line 172 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
This method is abstract.
Sell the amount of Bitcoin to the market. 成行注文 売り.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/kaesen/coincheck.rb', line 237 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
This method is abstract.
Get open orders.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/kaesen/coincheck.rb', line 112 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
This method is abstract.
Sell the amount of Bitcoin at the rate. 指数注文 売り.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/kaesen/coincheck.rb', line 205 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kaesen/coincheck.rb', line 37 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 |