class Vexapion::Coincheck
coincheckのAPIラッパークラスです。 各メソッドの戻り値は下記URLを参照してください。 @see coincheck.com/ja/documents/exchange/api
Public Instance Methods
アカウント情報 @return [Hash]
# File lib/vexapion/coincheck.rb, line 297 def accounts get('accounts') end
残高 @return [Hash]
# File lib/vexapion/coincheck.rb, line 256 def balance get('accounts/balance') end
銀行口座一覧 @return [Hash]
# File lib/vexapion/coincheck.rb, line 306 def bank_accounts get('bank_accounts') end
日本円出金申請 @param [Integer] id 銀行口座一覧のID @param [Integer] amount 金額 @param [String] currency 通貨名 現在はJPYのみ。省略時デフォルト'JPY' @param [Boolean] is_fast 高速出金オプション 省略時デフォルトはfalse @return [Hash]
# File lib/vexapion/coincheck.rb, line 348 def bank_withdraw(id, amount, currency = 'JPY', is_fast = false) params = { 'bank_account_id' => id, 'amount' => amount, 'currency' => currency, 'is_fast' => is_fast } post('withdraws', params) end
日本円出金履歴 @return [Hash]
# File lib/vexapion/coincheck.rb, line 338 def bank_withdraw_history get('withdraws') end
借入申請 @param [String] currency 借りたい通貨 @param [Float] amount 借りたい量 @return [Hash]
# File lib/vexapion/coincheck.rb, line 372 def borrow(currency, amount) params = { 'amount' => amount, 'currency' => currency } post('lending/borrows', params) end
借入中一覧 @return [Hash]
# File lib/vexapion/coincheck.rb, line 380 def borrow_list get('lending/borrows/matches') end
注文のキャンセル @param [Integer] id キャンセルしたい注文ID @return [Hash]
# File lib/vexapion/coincheck.rb, line 229 def cancel(id) delete("exchange/orders/#{id}") end
日本円出金申請のキャンセル @param [Integer] id 出金申請のID @return [Hash]
# File lib/vexapion/coincheck.rb, line 362 def cancel_bank_withdraw(id) delete("withdraws/#{id}") end
レバレッジ決済売買
@param [String] pair 現在は'btc_jpy'のみ @param [String] close_position 'long' or 'short' @param [Integer] position_id ポジションID @param [Integer] rate 注文のレート 例28000 @param [Float] amount 注文での量 例0.1 @return [Hash]
# File lib/vexapion/coincheck.rb, line 189 def close_position(pair, close_position, position_id, rate, amount) params = { 'pair' => pair.downcase, 'order_type' => "close_#{close_position.downcase}", 'position_id' => position_id.to_i, 'rate' => rate.to_f, 'amount' => amount.to_f } post('exchange/orders', params) end
レバレッジ決済取引(成行)
@param [String] pair 現在は'btc_jpy'のみ @param [String] close_position 'long' or 'short' @param [Integer] position_id ポジションID @param [Float] amount 注文での量 例0.1 @return [Hash]
# File lib/vexapion/coincheck.rb, line 207 def close_position_market_order(pair, close_position, position_id, amount) params = { 'pair' => pair.downcase, 'order_type' => "close_#{close_position.downcase}", 'position_id' => position_id.to_i, 'amount' => amount.to_f } post('exchange/orders', params) end
銀行口座の削除 @param [Integer] id 銀行口座一覧のID @return [Hash]
# File lib/vexapion/coincheck.rb, line 332 def delete_bank_account(id) delete("bank_accounts/#{id}") end
ビットコインの高速入金 @param [Integer] id 高速入金させたいビットコイン受取履歴のID @return [Hash]
# File lib/vexapion/coincheck.rb, line 291 def deposit_accelerate(id) post("deposit_money/#{id}/fast") end
ビットコイン受取履歴 @param [String] currency 現在はBTCのみ対応。省略時のデフォルトはBTC @return [Hash]
# File lib/vexapion/coincheck.rb, line 284 def deposit_history(currency = 'BTC') get('deposit_money', 'currency' => currency) end
レバレッジアカウントから振替 @param [String] currency 通貨 現在はJPYのみ @param [Float] amount 移動する数量 @return [Hash]
# File lib/vexapion/coincheck.rb, line 407 def from_leverage(currency, amount) params = { 'currency' => currency, 'amount' => amount } post('exchange/transfers/from_leverage', params) end
レバレッジアカウントの残高 @return [Hash]
# File lib/vexapion/coincheck.rb, line 262 def leverage_balance get('accounts/leverage_balance') end
成行注文 buyの時はamountにJPYの数量を指定する(amount_jpy円分買うという指定方法)
@param [String] pair 現在は'btc_jpy'のみ @param [Float] amount_jpy 注文での量 例5000 @param [Integer] stop_loss_rate 省略可 逆指値レート @return [Hash]
# File lib/vexapion/coincheck.rb, line 117 def market_buy(pair, amount_jpy, stop_loss_rate = '') params = { 'pair' => pair.downcase, 'order_type' => "market_buy", 'market_buy_amount' => amount_jpy } params['stop_loss_rate'] = stop_loss_rate if stop_loss_rate != '' post('exchange/orders', params) end
レバレッジ新規取引(成行)
@param [String] pair 現在は'btc_jpy'のみ @param [String] order_type 'sell' or 'buy' @param [Float] amount 注文での量 例0.1 @param [Integer] stop_loss_rate 省略可 逆指値レート @return [Hash]
# File lib/vexapion/coincheck.rb, line 171 def market_order_leverage(pair, order_type, amount, stop_loss_rate = '') params = { 'pair' => pair.downcase, 'amount' => amount.to_f, 'order_type' => "leverage_#{order_type.downcase}" } params['stop_loss_rate'] = stop_loss_rate if stop_loss_rate != '' post('exchange/orders', params) end
成行注文 sellの時はamountにBTCの数量を指定する
@param [String] pair 現在は'btc_jpy'のみ @param [Float] amount 注文での量 例0.1 @param [Integer] stop_loss_rate 省略可 逆指値レート @return [Hash]
# File lib/vexapion/coincheck.rb, line 134 def market_sell(pair, amount, stop_loss_rate = '') params = { 'pair' => pair.downcase, 'order_type' => "market_sell", 'amount' => amount } params['stop_loss_rate'] = stop_loss_rate if stop_loss_rate != '' post('exchange/orders', params) end
未約定の注文一覧 @return [Hash]
# File lib/vexapion/coincheck.rb, line 222 def opens get('exchange/orders/opens') end
@param [String] pair 現在は'btc_jpy'のみ @param [String] order_type 'sell' or 'buy' @param [Integer] rate 注文での金額 例28000 @param [Float] amount 注文での量 例0.1 @param [Integer] stop_loss_rate 省略可 逆指値レート @return [Hash]
# File lib/vexapion/coincheck.rb, line 99 def order(pair, order_type, rate, amount, stop_loss_rate = '') params = { 'rate' => rate, 'amount' => amount, 'pair' => pair.downcase, 'order_type' => order_type.downcase } params['stop_loss_rate'] = stop_loss_rate if stop_loss_rate != '' post('exchange/orders', params) end
板情報 @return [Hash]
# File lib/vexapion/coincheck.rb, line 46 def order_books public_get('order_books') end
レバレッジ新規取引
@param [String] pair 現在は'btc_jpy'のみ @param [String] order_type 'sell' or 'buy' @param [Integer] rate 注文のレート 例28000 @param [Float] amount 注文での量 例0.1 @param [Integer] stop_loss_rate 省略可 逆指値レート @return [Hash]
# File lib/vexapion/coincheck.rb, line 153 def order_leverage(pair, order_type, rate, amount, stop_loss_rate = '') params = { 'pair' => pair.downcase, 'rate' => rate.to_f, 'amount' => amount.to_f, 'order_type' => "leverage_#{order_type.downcase}" } params['stop_loss_rate'] = stop_loss_rate if stop_loss_rate != '' post('exchange/orders', params) end
ポジション一覧 @param [String] status 省略可 'open'/'closed'を指定出来ます @return [Hash]
# File lib/vexapion/coincheck.rb, line 248 def position(status='') params = Hash.new params['status'] = status if status != '' get('exchange/leverage/positions', params) end
レート取得 @param [String] pair 必須 現在は'btc_jpy'のみ @param [String] order_type 必須 'sell' or 'buy' @param [Integer] price 省略可 注文での金額 例28000 @param [Float] amount 省略可 注文での量 例0.1 @return [Hash]
# File lib/vexapion/coincheck.rb, line 56 def rate(pair, order_type, price='', amount='') params = { 'pair' => pair.downcase, 'order_type' => order_type, } params['price'] = price if price != '' params['amount'] = amount if amount != '' public_get('exchange/orders/rate') end
銀行口座の登録 @param [String] bank 銀行名 @param [String] branch 支店名 @param [String] type 口座の種類 (普通口座 futsu / 当座預金口座 toza) @param [String] number_str 口座番号 例:'0123456' @param [String] name 口座名義 @return [Hash]
# File lib/vexapion/coincheck.rb, line 317 def regist_bank_account(bank, branch, type, number_str, name) params = { 'bank_name' => bank, 'branch_name' => branch, 'bank_account_type' => type, 'number' => number_str, 'name' => name } post('bank_accounts', params) end
返済 @param [Integer] id 借入中一覧のID @return [Hash]
# File lib/vexapion/coincheck.rb, line 387 def repayment(id) post("lending/borrows/#{id}/repay") end
販売所レート取得 @param [String] pair ('btc_jpy', 'eth_jpy', 'zec_btc' …etc) @return [Hash]
# File lib/vexapion/coincheck.rb, line 70 def sales_rate(pair, price='', amount='') params = { 'pair' => pair.downcase, } public_get('exchange/orders/rate', params) end
ビットコイン送金履歴 @param [String] currency 現在はBTCのみ対応。省略時のデフォルトはBTC @return [Hash]
# File lib/vexapion/coincheck.rb, line 277 def send_history(currency = 'BTC') get('send_money', 'currency' => currency) end
ビットコインの送金 @param [String] address 送り先のビットコインアドレス @param [Float] amount 送りたいビットコインの量 @return [Hash]
# File lib/vexapion/coincheck.rb, line 270 def send_money(address, amount) post('send_money', 'address' => address, 'amount' => amount) end
ティッカー @return [Hash]
# File lib/vexapion/coincheck.rb, line 34 def ticker public_get('ticker') end
レバレッジアカウントへ振替 @param [String] currency 通貨 現在はJPYのみ @param [Float] amount 移動する数量 @return [Hash]
# File lib/vexapion/coincheck.rb, line 397 def to_leverage(currency, amount) params = { 'currency' => currency, 'amount' => amount } post('exchange/transfers/to_leverage', params) end
取引履歴 @return [Array]
# File lib/vexapion/coincheck.rb, line 40 def trades public_get('trades') end
約定履歴 @return [Hash]
# File lib/vexapion/coincheck.rb, line 235 def transactions get('exchange/orders/transactions') end
Private Instance Methods
# File lib/vexapion/coincheck.rb, line 456 def delete(method) nonce = get_nonce.to_s uri = URI.parse "#{@private_url}#{method}" message = nonce + uri.to_s sig = signature(message) headers = header(nonce, sig) request = Net::HTTP::Delete.new(uri.request_uri, headers) res = do_command(uri, request) error_check(res) #TODO check require res end
# File lib/vexapion/coincheck.rb, line 483 def error_check(res) if !res.nil? && res['success'] == 0 && res.has_key?('error') fail Warning.new(0, res['error']) end end
# File lib/vexapion/coincheck.rb, line 424 def get(method, params = '') nonce = get_nonce.to_s uri = URI.parse "#{@private_url}#{method}" params = params.to_json if params != '' #URI.encode_www_form(params) message = "#{nonce}#{uri.to_s}#{params}" sig = signature(message) headers = header(nonce, sig) request = Net::HTTP::Get.new(uri.request_uri, headers) request.body = params res = do_command(uri, request) error_check(res) #TODO check require res end
# File lib/vexapion/coincheck.rb, line 474 def header(nonce, signature) { 'Content-Type' => "application/json", 'ACCESS-KEY' => @key, 'ACCESS-NONCE' => nonce, 'ACCESS-SIGNATURE' => signature } end
# File lib/vexapion/coincheck.rb, line 440 def post(method, params = '') nonce = get_nonce.to_s uri = URI.parse "#{@private_url}#{method}" params = params.to_json #URI.encode_www_form(params) message = "#{nonce}#{uri.to_s}#{params}" sig = signature(message) headers = header(nonce, sig) request = Net::HTTP::Post.new(uri.request_uri, headers) request.body = params if params != '' res = do_command(uri, request) error_check(res) #check ok res end
Create request header & body
# File lib/vexapion/coincheck.rb, line 417 def public_get(method) uri = URI.parse "#{@public_url}#{method}" request = Net::HTTP::Get.new(uri.request_uri) do_command(uri, request) end
# File lib/vexapion/coincheck.rb, line 469 def signature(message) algo = OpenSSL::Digest.new('sha256') OpenSSL::HMAC.hexdigest(algo, @secret, message) end