class Vexapion::Coincheck

coincheckのAPIラッパークラスです。 各メソッドの戻り値は下記URLを参照してください。 @see coincheck.com/ja/documents/exchange/api

Public Instance Methods

accounts() click to toggle source

アカウント情報 @return [Hash]

# File lib/vexapion/coincheck.rb, line 297
def accounts
        get('accounts')
end
balance() click to toggle source

残高 @return [Hash]

# File lib/vexapion/coincheck.rb, line 256
def balance
        get('accounts/balance')
end
bank_accounts() click to toggle source

銀行口座一覧 @return [Hash]

# File lib/vexapion/coincheck.rb, line 306
def bank_accounts
        get('bank_accounts')
end
bank_withdraw(id, amount, currency = 'JPY', is_fast = false) click to toggle source

日本円出金申請 @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
bank_withdraw_history() click to toggle source

日本円出金履歴 @return [Hash]

# File lib/vexapion/coincheck.rb, line 338
def bank_withdraw_history
        get('withdraws')
end
borrow(currency, amount) click to toggle source

借入申請 @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
borrow_list() click to toggle source

借入中一覧 @return [Hash]

# File lib/vexapion/coincheck.rb, line 380
def borrow_list
        get('lending/borrows/matches')
end
cancel(id) click to toggle source

注文のキャンセル @param [Integer] id キャンセルしたい注文ID @return [Hash]

# File lib/vexapion/coincheck.rb, line 229
def cancel(id)
        delete("exchange/orders/#{id}")
end
cancel_bank_withdraw(id) click to toggle source

日本円出金申請のキャンセル @param [Integer] id 出金申請のID @return [Hash]

# File lib/vexapion/coincheck.rb, line 362
def cancel_bank_withdraw(id)
        delete("withdraws/#{id}")
end
close_position(pair, close_position, position_id, rate, amount) click to toggle source

レバレッジ決済売買

@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
close_position_market_order(pair, close_position, position_id, amount) click to toggle source

レバレッジ決済取引(成行)

@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
Also aliased as: close_position_without_limit
close_position_without_limit(pair, close_position, position_id, amount)
delete_bank_account(id) click to toggle source

銀行口座の削除 @param [Integer] id 銀行口座一覧のID @return [Hash]

# File lib/vexapion/coincheck.rb, line 332
def delete_bank_account(id)
        delete("bank_accounts/#{id}")
end
deposit_accelerate(id) click to toggle source

ビットコインの高速入金 @param [Integer] id 高速入金させたいビットコイン受取履歴のID @return [Hash]

# File lib/vexapion/coincheck.rb, line 291
def deposit_accelerate(id)
        post("deposit_money/#{id}/fast")
end
deposit_history(currency = 'BTC') click to toggle source

ビットコイン受取履歴 @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
from_leverage(currency, amount) click to toggle source

レバレッジアカウントから振替 @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
leverage_balance() click to toggle source

レバレッジアカウントの残高 @return [Hash]

# File lib/vexapion/coincheck.rb, line 262
def leverage_balance
        get('accounts/leverage_balance')
end
market_buy(pair, amount_jpy, stop_loss_rate = '') click to toggle source

成行注文 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
market_order_leverage(pair, order_type, amount, stop_loss_rate = '') click to toggle source

レバレッジ新規取引(成行)

@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
market_sell(pair, amount, stop_loss_rate = '') click to toggle source

成行注文 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
opens() click to toggle source

未約定の注文一覧 @return [Hash]

# File lib/vexapion/coincheck.rb, line 222
def opens
        get('exchange/orders/opens')
end
order(pair, order_type, rate, amount, stop_loss_rate = '') click to toggle source

@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
order_books() click to toggle source

板情報 @return [Hash]

# File lib/vexapion/coincheck.rb, line 46
def order_books
        public_get('order_books')
end
order_leverage(pair, order_type, rate, amount, stop_loss_rate = '') click to toggle source

レバレッジ新規取引

@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
position(status='') click to toggle source

ポジション一覧 @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
rate(pair, order_type, price='', amount='') click to toggle source

レート取得 @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
regist_bank_account(bank, branch, type, number_str, name) click to toggle source

銀行口座の登録 @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
repayment(id) click to toggle source

返済 @param [Integer] id 借入中一覧のID @return [Hash]

# File lib/vexapion/coincheck.rb, line 387
def repayment(id)
        post("lending/borrows/#{id}/repay")
end
sales_rate(pair, price='', amount='') click to toggle source

販売所レート取得 @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
send_history(currency = 'BTC') click to toggle source

ビットコイン送金履歴 @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
send_money(address, amount) click to toggle source

ビットコインの送金 @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
ticker() click to toggle source

ティッカー @return [Hash]

# File lib/vexapion/coincheck.rb, line 34
def ticker
        public_get('ticker')
end
to_leverage(currency, amount) click to toggle source

レバレッジアカウントへ振替 @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
trades() click to toggle source

取引履歴 @return [Array]

# File lib/vexapion/coincheck.rb, line 40
def trades
        public_get('trades')
end
transactions() click to toggle source

約定履歴 @return [Hash]

# File lib/vexapion/coincheck.rb, line 235
def transactions
        get('exchange/orders/transactions')
end

Private Instance Methods

delete(method) click to toggle source
# 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
error_check(res) click to toggle source
# 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
get(method, params = '') click to toggle source
# 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
header(nonce, signature) click to toggle source
# 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
post(method, params = '') click to toggle source
# 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
public_get(method) click to toggle source

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
signature(message) click to toggle source
# File lib/vexapion/coincheck.rb, line 469
def signature(message)
        algo = OpenSSL::Digest.new('sha256')
        OpenSSL::HMAC.hexdigest(algo, @secret, message)
end