Class: ZaifWrapper::Client::ZaifParentApi

Inherits:
Object
  • Object
show all
Defined in:
lib/zaif_wrapper/client.rb

Constant Summary collapse

PUBLIC_REQUEST_URL_BASE =
'https://api.zaif.jp/api/1/'.freeze
PRIVATE_REQUEST_URL_BASE =
'https://api.zaif.jp/tapi'.freeze
FUTURE_REQUEST_URL_BASE =
'https://api.zaif.jp/fapi/1/'.freeze
LEVERAGE_REQUEST_URL_BASE =
'https://api.zaif.jp/tlapi'.freeze
PUBLIC_METHODS =
{
    :currencies     => 'currency_code',
    :currency_pairs => 'currency_pair',
    :last_price     => 'currency_pair',
    :ticker         => 'currency_pair',
    :trades         => 'currency_pair',
    :depth          => 'currency_pair'
}.freeze
PRIVATE_METHODS =
['get_info', 'get_info2', 'get_personal_info', 'get_id_info', 'trade_history', 'active_orders', 'trade', 'cancel_order', 'withdraw', 'deposit_history', 'withdraw_history'].freeze
FUTURE_METHODS =
['groups', 'last_price', 'ticker', 'trades', 'depth'].freeze
LEVERAGE_METHODS =
['get_positions', 'position_history', 'active_positions', 'create_position', 'change_position', 'cancel_position'].freeze

Instance Method Summary collapse

Instance Method Details

#create_signature(body) ⇒ Object



51
52
53
# File 'lib/zaif_wrapper/client.rb', line 51

def create_signature(body)
  OpenSSL::HMAC::hexdigest(OpenSSL::Digest.new('sha512'), @api_secret, body.to_s)
end

#get_nonceObject



47
48
49
# File 'lib/zaif_wrapper/client.rb', line 47

def get_nonce
  Time.now.to_f.to_i
end

#get_request(host, path) ⇒ Object



26
27
28
29
# File 'lib/zaif_wrapper/client.rb', line 26

def get_request(host, path)
  response = RestClient.get "#{host}#{path}"
  JSON.parse(response.body)
end

#post_request(body, host) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zaif_wrapper/client.rb', line 31

def post_request(body, host)
  body.store('nonce', get_nonce)
  signature_text = ""
  body.each_with_index { |param, i|
    signature_text = signature_text + '&' if i != 0
    signature_text = "#{signature_text}#{param[0]}=#{param[1]}"
  }
  response = RestClient.post host, body, {
      content_type: :json,
      accept: :json,
      key: @api_key,
      sign: create_signature(signature_text)
  }
  JSON.parse(response.body)
end