class Vexapion::Bitflyer

bitflyerのAPIラッパークラスです 各メソッドの戻り値は下記URLを参照してください @see lightning.bitflyer.jp/docs?lang=ja&_ga=1.264432847.170149243.1463313992

Public Instance Methods

board(pair) click to toggle source
Public API

板情報

@param [String] pair product_codeを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 29
def board(pair)
        public_get('board', product_code: pair.upcase)
end
Also aliased as: get_board
cancel_all_child_order(pair) click to toggle source

すべての注文をキャンセルする

@param [String] pair product_codeを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 311
def cancel_all_child_order(pair)
        post('cancelallchildorders', product_code: pair.upcase)
end
cancel_child_order(pair, order_id) click to toggle source

child_order_idを指定して、注文をキャンセルする

@param [String] pair product_codeを指定します。
@param [Integer] order_id child_order_idを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 255
def cancel_child_order(pair, order_id)
        params = {
                product_code:   pair.upcase,
                child_order_id: order_id
        }

        post('cancelchildorder', params)
end
cancel_child_order_specify_acceptance_id(pair, acceptance_id) click to toggle source

child_order_acceptance_idを指定して、注文をキャンセルする

@param [String] pair product_codeを指定します。
@param [Integer] child_order_acceptance_id child_order_acceptance_idを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 268
def cancel_child_order_specify_acceptance_id(pair, acceptance_id)
        params = {
                product_code:              pair.upcase,
                child_order_acceptance_id: acceptance_id
        }

        post('cancelchildorder', params)
end
executions(pair, count='', before='', after='') click to toggle source

約定履歴

@param [String] pair product_codeを指定します。
@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 48
def executions(pair, count='', before='', after='')
        params = {
          product_code: pair.upcase
        }
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''
        public_get('executions', params)
end
Also aliased as: get_public_executions
get_addresses() click to toggle source

預入用BTC/ETHアドレス取得

@return [Hash]
# File lib/vexapion/bitflyer.rb, line 94
def get_addresses
        get('getaddresses')
end
get_balance() click to toggle source

資産残高を取得

@return [Hash]
# File lib/vexapion/bitflyer.rb, line 82
def get_balance
        get('getbalance')
end
get_bank_accounts() click to toggle source

銀行口座一覧取得

@return [Hash]
# File lib/vexapion/bitflyer.rb, line 159
def get_bank_accounts
        get('getbankaccounts')
end
get_board(pair)
Alias for: board
get_chats(date) click to toggle source

チャット

@params [???] 日付を指定するようです。形式不明。省略すると5日前からのデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 63
def get_chats(date)
        public_get('getchats', from_date: date)
end
get_child_orders(pair, state='', count='', before='', after='') click to toggle source

注文の一覧を取得 stateが指定されない場合、ACTIVE, COMPLETED, CANCELED, RXPIRED, REJECTEDのすべてが返されます。

@param [String] pair product_codeを指定します。
@param [String] state ACTIVE, COMPLETED, CANCELED, RXPIRED, REJECTEDのいずれかを指定します。省略可。
@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 323
def get_child_orders(pair, state='', count='', before='', after='')
        params = {
                product_code: pair.upcase
        }
        params[:child_order_state]  = state  if state != ''
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''

        get('getchildorders', params)
end
get_child_orders_parent_order_id(pair, parent_order_id) click to toggle source

parent_order_idに関連した注文の一覧を取得

@param [String] pair product_codeを指定します。
@param [Integer] parent_order_id parent_order_idを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 339
def get_child_orders_parent_order_id(pair, parent_order_id)
        params = {
                product_code: pair.upcase,
                parent_order_id: parent_order_id
        }

        get('getchildorders', params)
end
get_coin_ins(count='', before='', after='') click to toggle source

BTC/ETH預入履歴

@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 103
def get_coin_ins(count='', before='', after='')
  params = Hash.new
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''
        get('getcoinins', params)
end
get_coin_outs(count='', before='', after='') click to toggle source

BTC/ETH送付履歴

@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 138
def get_coin_outs(count='', before='', after='')
  params = Hash.new
        #params[:message_id] = id if id     != ''
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''

        get('getcoinouts', params)
end
get_coin_outs_id(message_id) click to toggle source

BTC/ETH送付状況確認

@param [String]     message_id  sendcoinAPIの戻り値を指定
@return [hash]
# File lib/vexapion/bitflyer.rb, line 151
def get_coin_outs_id(message_id)
        params = { message_id: message_id }

        get('getcoinouts', params)
end
get_collateral() click to toggle source

証拠金の状態を取得

@return [Hash]
# File lib/vexapion/bitflyer.rb, line 88
def get_collateral
        get('getcollateral')
end
get_deposits(count='', before='', after='') click to toggle source

デポジット入金履歴

@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 168
def get_deposits(count='', before='', after='')
  params = Hash.new
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''

        get('getdeposits', params)
end
get_executions(pair, count='', before='', after='') click to toggle source

約定の一覧を取得

@param [String] pair product_codeを指定します。
@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 387
def get_executions(pair, count='', before='', after='')
        #必須パラメータ
        params = {
                product_code: pair.upcase
        }
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''

        get('getexecutions', params)
end
get_executions_acceptance_id(pair, child_order_acceptance_id='') click to toggle source

child_order_acceptance_idに関連した約定の一覧を取得

@param [String] pair product_codeを指定します。
@param [Integer] child_order_acceptance_id child_order_acceptance_idを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 417
def get_executions_acceptance_id(pair, child_order_acceptance_id='')
        params = {
                product_code: pair.upcase,
                child_order_acceptance_id: child_order_acceptance_id  
        }

        get('getexecutions', params)
end
get_executions_child_order_id(pair, child_order_id) click to toggle source

child_order_idに関連した約定の一覧を取得

@param [String] pair product_codeを指定します。
@param [Integer] child_order_id child_order_idを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 403
def get_executions_child_order_id(pair, child_order_id)
        #必須パラメータ
        params = {
                product_code: pair.upcase,
                child_order_id: child_order_id
        }

        get('getexecutions', params)
end
get_health() click to toggle source

取引所の状態

@return [Hash]
# File lib/vexapion/bitflyer.rb, line 69
def get_health
        public_get('gethealth')
end
get_permissions() click to toggle source
Private API

APIキーの権限を取得

@return [Hash]
# File lib/vexapion/bitflyer.rb, line 76
def get_permissions
        get('getpermissions')
end
get_positions(pair) click to toggle source

建玉の一覧を取得 @param [String] pair product_codeを指定します。 “FX_BTC_JPY”を指定します。 @return [Hash]

# File lib/vexapion/bitflyer.rb, line 429
def get_positions(pair)
        params = {
                product_code: pair.upcase
        }

        get('getpositions', params)
end
get_public_executions(pair, count='', before='', after='')

get_executionsは個人の約定履歴の取得に使っているので混同しないこと

Alias for: executions
get_ticker(pair)
Alias for: ticker
get_withdrawals(count='', before='', after='') click to toggle source

デポジット解約履歴(出金)

@param [Integer] count 結果の個数を指定します。
@param [Integer] before このパラメータに指定した値より小さいidを持つデータを取得します。
@param [Integer] after このパラメータに指定した値より大きいidを持つデータを取得します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 199
def get_withdrawals(count='', before='', after='')
  params = Hash.new
        params[:count]  = count  if count  != ''
        params[:before] = before if before != ''
        params[:after]  = after  if after  != ''

        get('getwithdrawals', params)
end
send_child_order(pair, side, price, size, expire='', force='') click to toggle source

指値で新規注文を出す

@param [String] pair product_codeを指定します。
@param [String] side 買い注文の場合は"BUY"、売り注文の場合は"SELL"を指定します。
@param [Float] price 価格を指定します。 ただしJPYの場合はInteger
@param [Float] size  注文数量を指定します。
@param [Integer] expire 期限切れまでの時間を分で指定します。省略した場合の値は525600(365日間)です。
@param [String] force 執行数量条件を"GTC"、"IOC"、"FOK"のいずれかで指定します。省略した場合は"GTC"です。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 217
def send_child_order(pair, side, price, size, expire='', force='')
        params = {
                product_code:      pair.upcase,
                child_order_type:  'LIMIT',
                side:              side.upcase,
                price:             price,
                size:              size.to_f
        }
        params[:minute_to_expire]  = expire  if expire != ''
        params[:time_in_force]     = force   if force  != ''

        post('sendchildorder', params)
end
send_child_order_market(pair, side, size, expire='', force='') click to toggle source

成行で新規注文を出す

@param [String] pair product_codeを指定します。
@param [String] side 買い注文の場合は"BUY"、売り注文の場合は"SELL"を指定します。
@param [Float] size  注文数量を指定します。
@param [Integer] expire 期限切れまでの時間を分で指定します。省略した場合の値は525600(365日間)です。
@param [String] force 執行数量条件を"GTC"、"IOC"、"FOK"のいずれかで指定します。省略した場合は"GTC"です。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 238
def send_child_order_market(pair, side, size, expire='', force='')
        params = {
                product_code:      pair.upcase,
                child_order_type:  'MARKET',
                side:              side.upcase,
                size:              size.to_f
        }
        params[:minute_to_expire]  = expire  if expire != ''
        params[:time_in_force]     = force   if force  != ''

        post('sendchildorder', params)
end
sendcoin(currency, amount, address, fee='', code='') click to toggle source

BTC/ETH外部送付

@param [String] currency 送付する通貨名を指定します。~BTC" または "ETH"を指定します。
@param [Float] amount 送付する数量を数値で指定します。
@param [String] address 送付先アドレスを指定します。
@param [Float] fee 追加の手数料を指定します。上限は0.0005です。
@param [String] code 二段階認証の確認コードです。コイン外部送付時の二段階認証を設定している場合のみ必要。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 118
def sendcoin(currency, amount, address, fee='', code='')
        params = {
                currency_code: currency.upcase,
                amount:  amount.to_f,
                address: address,
        }
        if fee != ''
                fee = 0.0005 < fee.to_f ? 0.0005 : fee.to_f
                params[:additional_fee]  = fee
        end
        params[:code] = code.to_i  if code != ''

        post('sendcoin', params)
end
ticker(pair) click to toggle source

Ticker

@param [String] pair product_codeを指定します。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 37
def ticker(pair)
        public_get('ticker', product_code: pair.upcase)
end
Also aliased as: get_ticker
withdraw(currency, id, amount, code='') click to toggle source

デポジット解約(出金)

@param [String] currency 送付する通貨名を指定します。現在は"JPY"のみ対応しています。
@param [Integer] id 出金先口座のidを指定します。
@param [Integer] amount 解約する数量を指定します。
@param [String] code 二段階認証の確認コードです。出金時の二段階認証を設定している場合のみ必要。
@return [Hash]
# File lib/vexapion/bitflyer.rb, line 183
def withdraw(currency, id, amount, code='')
        params = {
                currency_code:    currency.upcase,
                bank_account_id:  id,
                amount:           amount
        }
        params[:code] = code if code != ''

        post('withdraw', params)
end

Private Instance Methods

error_check(res) click to toggle source
# File lib/vexapion/bitflyer.rb, line 500
def error_check(res)
        if !res.nil? && res['success'] == 0 && res.has_key?('error')
                fail Warning.new(0, res['error'])
        end
end
get(command, query={}) click to toggle source
# File lib/vexapion/bitflyer.rb, line 451
def get(command, query={})
        method = 'GET'
        uri = URI.parse "#{@private_url}#{command}"
        uri.query = URI.encode_www_form(query) if query != {}
        timestamp = get_nonce.to_s
        text = "#{timestamp}#{method}#{uri.request_uri}"
        sign = signature(text)
        header = {
                'ACCESS-KEY'        =>  @key,
                'ACCESS-TIMESTAMP'  =>  timestamp,
                'ACCESS-SIGN'        =>  sign
        }

        request = Net::HTTP::Get.new(uri.request_uri, header)

        do_command(uri, request)
end
headers(sign, timestamp) click to toggle source
# File lib/vexapion/bitflyer.rb, line 491
def headers(sign, timestamp)
        {
                'ACCESS-KEY'        => @key,
                'ACCESS-TIMESTAMP'  => timestamp,
                'ACCESS-SIGN'       => sign,
                'Content-Type'      => 'application/json'
        }
end
post(command, params={}) click to toggle source
# File lib/vexapion/bitflyer.rb, line 469
def post(command, params={})
        method = 'POST'
        uri = URI.parse "#{@private_url}#{command}"
        timestamp = get_nonce.to_s
        body = params.to_json #add

        text = "#{timestamp}#{method}#{uri.request_uri}#{body}"
        sign = signature(text)
        header = headers(sign, timestamp)
        request = Net::HTTP::Post.new(uri.request_uri, header)
        request.body = body

        res = do_command(uri, request)
        #error_check(res)
        res
end
public_get(command, query={}) click to toggle source

Create request header & body

# File lib/vexapion/bitflyer.rb, line 442
def public_get(command, query={})
        uri = URI.parse "#{@public_url}#{command}"
        uri.query = URI.encode_www_form(query)
        request = Net::HTTP::Get.new(uri.request_uri)
        request.set_form_data(query) #クエリをURLエンコード(p1=v1&p2=v2...)

        do_command(uri, request)
end
signature(data) click to toggle source
# File lib/vexapion/bitflyer.rb, line 486
def signature(data)
        algo = OpenSSL::Digest.new('sha256')
        OpenSSL::HMAC.hexdigest(algo, @secret, data)
end