class BitFlyer::Api::PrivateReader

Constants

CURRENCY_CODE

Public Class Methods

new(key, secret) click to toggle source
# File lib/bit_flyer/api/private_reader.rb, line 10
def initialize(key, secret)
  @key = key
  @secret = secret
end

Public Instance Methods

balancehistory(count = 100, before = nil, after = nil) click to toggle source

残高履歴

# File lib/bit_flyer/api/private_reader.rb, line 47
def balancehistory(count = 100, before = nil, after = nil)
  timestamp = Time.now.to_i.to_s
  uri = URI.parse(BASE_URL)
  uri.path = "/v1/me/getbalancehistory"
  query_string = {}
  query_string[:currency_code] = CURRENCY_CODE
  query_string[:count] = count if count.present?
  query_string[:before] = before unless before.nil?
  query_string[:after] = after unless after.nil?
  uri.query = query_string.to_param
  request_uri = uri.request_uri

  text = timestamp + 'GET' + request_uri
  sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), @secret, text)

  response = connect.get do |req|
    req.url request_uri
    req.headers = {
      "ACCESS-KEY" => @key,
      "ACCESS-TIMESTAMP" => timestamp,
      "ACCESS-SIGN" => sign
    }
  end
  response.body
end
executions(product_code = '', count = nil, before = nil, after = nil) click to toggle source

約定の一覧を取得 パラメータ product_code: マーケットの一覧で取得できる product_code または alias のいずれかを指定してください。 count, before, after: ページ形式 を参照してください。

# File lib/bit_flyer/api/private_reader.rb, line 20
def executions(product_code = '', count = nil, before = nil, after = nil)
  timestamp = Time.now.to_i.to_s
  uri = URI.parse(BASE_URL)
  uri.path = "/v1/me/getexecutions"
  query_string = {}
  query_string[:product_code] = product_code if product_code.present?
  query_string[:count] = count if count.present?
  query_string[:before] = before unless before.nil?
  query_string[:after] = after unless after.nil?
  uri.query = query_string.to_param
  uri_path = query_string.count >= 1 ? uri.request_uri : uri.path

  text = timestamp + 'GET' + uri_path
  sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), @secret, text)

  response = connect.get do |req|
    req.url uri_path
    req.headers = {
      "ACCESS-KEY" => @key,
      "ACCESS-TIMESTAMP" => timestamp,
      "ACCESS-SIGN" => sign
    }
  end
  response.body
end