class Vexapion::Zaif

zaifのAPIラッパークラスです。 各メソッドの戻り値は下記URLを参照してください。 @see corp.zaif.jp/api-docs/

Public Instance Methods

active_orders(pair = '') click to toggle source

未約定の注文一覧を取得します

@param [String]    pair    取得したい通貨ペア。省略時はすべての通貨ペア

@return [Hash]

# File lib/vexapion/zaif.rb, line 93
def active_orders(pair = '')
        params = Hash.new
        params['currency_pair'] = pair if pair != ''

        post('active_orders', params)
end
cancel_order(id) click to toggle source

注文のキャンセルをします

@param  [Integer]  id      注文ID
 @return  [Hash]
# File lib/vexapion/zaif.rb, line 122
def cancel_order(id)
        post('cancel_order', 'order_id' => id)
end
deposit_history(currency, i_since = '', i_end = '', i_from = '', i_count = '', from_id = '', end_id = '', order = '') click to toggle source

入金履歴を取得します。 @param [String] currency 取得したい通貨 @param [Integer] i_since 開始タイムスタンプ(UNIX time) @param [Integer] i_end 終了タイムスタンプ(UNIX time) @param [Integer] i_from この順番のレコードから取得 @param [Integer] i_count 取得するレコード数 @param [Integer] from_id このトランザクションIDのレコードから取得 @param [Integer] end_id このトランザクションIDのレコードまで取得 @param [String] order ソート順('ASC'/'DESC') @return [Hash]

# File lib/vexapion/zaif.rb, line 182
def deposit_history(currency, i_since = '', i_end = '',
        i_from = '', i_count = '', from_id = '', end_id = '', order = '')

        params = Hash.new
        params['currency']  = currency
        params['since']     = i_since  if i_since  != ''
        params['end']       = i_end    if i_end    != ''
        params['from']      = i_from   if i_from   != ''
        params['count']     = i_count  if i_count  != ''
        params['from_id']   = from_id  if from_id  != ''
        params['end_id']    = end_id   if end_id   != ''
        params['order']     = order    if order    != ''

        post('deposit_history', params)
end
depth(pair) click to toggle source

板情報 @param [String] pair 取得したい通貨ペア @return [Hash]

# File lib/vexapion/zaif.rb, line 64
def depth(pair)
        get('depth', pair)
end
get_info() click to toggle source

現在の残高(余力および残高・トークン)、APIキーの権限、過去のトレード数 アクティブな注文数、サーバーのタイムスタンプを取得します @return [Hash]

# File lib/vexapion/zaif.rb, line 73
def get_info
        post('get_info')
end
get_info2() click to toggle source

現在の残高(余力および残高・トークン)、APIキーの権限、 アクティブな注文数、サーバーのタイムスタンプを取得します @return [Hash]

# File lib/vexapion/zaif.rb, line 80
def get_info2
        post('get_info2')
end
get_personal_info() click to toggle source

チャットに使用されるニックネームと画像のパスを返します。 @return [Hash]

# File lib/vexapion/zaif.rb, line 86
def get_personal_info
        post('get_personal_info')
end
last_price(pair) click to toggle source

終値 @param [String] pair 取得したい通貨ペア @return [Hash]

# File lib/vexapion/zaif.rb, line 43
def last_price(pair)
        get('last_price', pair)
end
ticker(pair) click to toggle source

ティッカー @param [String] pair 取得したい通貨ペア @return [Hash]

# File lib/vexapion/zaif.rb, line 50
def ticker(pair)
        get('ticker', pair)
end
trade(pair, action, price, amount, limit = '') click to toggle source

未約定の注文一覧を取得します

@param [String]    pair    トレードしたい通貨ペア
@param [String]    action  注文の種類 ask(売)/bid(買)
@param [Float]    price    注文価格(ただしBTC_JPYの時はInteger)
@param [Float]    amount  注文量
@param [Float]    limit    リミット注文価格(ただしBTC_JPYの時はInteger)

@return [Hash]

# File lib/vexapion/zaif.rb, line 107
def trade(pair, action, price, amount, limit = '')
        params = {
                currency_pair: pair,
                action:        action,
                price:         price,
                amount:        amount
        }
        params['limit'] = limit if limit != ''

        post('trade', params)
end
trade_history(pair = '', i_since = '', i_end = '', i_from = '', i_count = '', from_id = '', end_id = '', order = '') click to toggle source

トレードヒストリーを取得します。 @param [String] pair 取得したい通貨ペア @param [Integer] i_since 開始タイムスタンプ(UNIX time) @param [Integer] i_end 終了タイムスタンプ(UNIX time) @param [Integer] i_from この順番のレコードから取得 @param [Integer] i_count 取得するレコード数 @param [Integer] from_id このトランザクションIDのレコードから取得 @param [Integer] end_id このトランザクションIDのレコードまで取得 @param [String] order ソート順('ASC'/'DESC') @return [Hash]

# File lib/vexapion/zaif.rb, line 136
def trade_history(pair = '', i_since = '', i_end = '',
        i_from = '', i_count = '', from_id = '', end_id = '', order = '')

        params = Hash.new
        params['currency_pair']  = pair     if pair     != ''
        params['since']          = i_since  if i_since  != ''
        params['end']            = i_end    if i_end    != ''
        params['from']           = i_from   if i_from   != ''
        params['count']          = i_count  if i_count  != ''
        params['from_id']        = from_id  if from_id  != ''
        params['end_id']         = end_id   if end_id   != ''
        params['order']          = order    if order    != ''

        post('trade_history', params)
end
trades(pair) click to toggle source

取引履歴 @param [String] pair 取得したい通貨ペア @return [Array]

# File lib/vexapion/zaif.rb, line 57
def trades(pair)
        get('trades', pair)
end
withdraw(currency, amount, address, fee = nil, message = nil) click to toggle source

払出のリクエストをします。

@param [String]   currency  払出したい通貨
@param [Float]    amount    送金量
@param [String]   address    送信先アドレス
@param [Float]    fee        採掘者への手数料(XEM以外)

@param [String] message 送信メッセージ(XEMのみ) @return [Hash]

# File lib/vexapion/zaif.rb, line 160
def withdraw(currency, amount, address, fee = nil, message = nil)
        params = {
                currency:  currency.downcase,
                amount:    amount,
                address:   address
        }
        params['message'] = message if message  != nil
        params['opt_fee'] = fee     if fee      != nil

        post('withdraw', params)
end
withdraw_history(currency, i_since = '', i_end = '', i_from = '', i_count = '', from_id = '', end_id = '', order = '') click to toggle source

出金履歴を取得します。

@param [String]    currency  取得したい通貨

@param [Integer] i_since 開始タイムスタンプ(UNIX time) @param [Integer] i_end 終了タイムスタンプ(UNIX time) @param [Integer] i_from この順番のレコードから取得 @param [Integer] i_count 取得するレコード数 @param [Integer] from_id このトランザクションIDのレコードから取得 @param [Integer] end_id このトランザクションIDのレコードまで取得 @param [String] order ソート順('ASC'/'DESC') @return [Hash]

# File lib/vexapion/zaif.rb, line 208
def withdraw_history(currency, i_since = '', i_end = '',
        i_from = '', i_count = '', from_id = '', end_id = '', order = '')

        params = Hash.new
        params['currency']  = currency
        params['since']     = i_since  if i_since  != ''
        params['end']       = i_end    if i_end    != ''
        params['from']      = i_from   if i_from   != ''
        params['count']     = i_count  if i_count  != ''
        params['from_id']   = from_id  if from_id  != ''
        params['end_id']    = end_id   if end_id   != ''
        params['order']     = order    if order    != ''

        post('withdraw_history', params)
end

Private Instance Methods

error_check(res) click to toggle source
# File lib/vexapion/zaif.rb, line 257
def error_check(res)
        if !res.nil? && res['success'] == 0 && res.has_key?('error')
                fail Warning.new('0', res['error'])
        end
end
get(method, pair) click to toggle source

Create request header & body

# File lib/vexapion/zaif.rb, line 229
def get(method, pair)
        url = "#{@public_url}#{method.downcase}/#{pair.downcase}"
        uri = URI.parse url
        request = Net::HTTP::Get.new(uri.request_uri)

        do_command(uri, request)
end
post(method, params = {}) click to toggle source
# File lib/vexapion/zaif.rb, line 237
def post(method, params = {})
        uri = URI.parse @private_url
        params['method'] = method
        params['nonce'] = get_nonce

        request = Net::HTTP::Post.new(uri)
        request.set_form_data(params)  #クエリをURLエンコード (p1=v1&p2=v2...)
        request['Key']  = @key
        request['Sign'] = signature(request)

        res = do_command(uri, request)
        error_check(res)
        res
end
signature(req) click to toggle source
# File lib/vexapion/zaif.rb, line 252
def signature(req)
        algo = OpenSSL::Digest.new('sha512')
        OpenSSL::HMAC.hexdigest(algo, @secret, req.body)
end