Class: ZaifWrapper::Client::ZaifPrivateApi

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

Constant Summary

Constants inherited from ZaifParentApi

ZaifWrapper::Client::ZaifParentApi::FUTURE_METHODS, ZaifWrapper::Client::ZaifParentApi::FUTURE_REQUEST_URL_BASE, ZaifWrapper::Client::ZaifParentApi::LEVERAGE_METHODS, ZaifWrapper::Client::ZaifParentApi::LEVERAGE_REQUEST_URL_BASE, ZaifWrapper::Client::ZaifParentApi::PRIVATE_METHODS, ZaifWrapper::Client::ZaifParentApi::PRIVATE_REQUEST_URL_BASE, ZaifWrapper::Client::ZaifParentApi::PUBLIC_METHODS, ZaifWrapper::Client::ZaifParentApi::PUBLIC_REQUEST_URL_BASE

Instance Method Summary collapse

Methods inherited from ZaifParentApi

#create_signature, #get_nonce, #get_request, #post_request

Constructor Details

#initialize(api_key, api_secret) ⇒ ZaifPrivateApi

Returns a new instance of ZaifPrivateApi.



66
67
68
69
# File 'lib/zaif_wrapper/client.rb', line 66

def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/zaif_wrapper/client.rb', line 71

def method_missing(name, *args)
  if PRIVATE_METHODS.include?(name.to_s)
    klass = class << self; self end
    klass.class_eval do
      define_method(name) do |body = {}|
        check(name, body)
        body.store("method", name.to_s)
        post_request(body, PRIVATE_REQUEST_URL_BASE)
      end
    end
    if args.length == 1
      __send__(name, args[0])
    else
      __send__(name)
    end
  end
end

Instance Method Details

#check(method_name, body) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/zaif_wrapper/client.rb', line 89

def check(method_name, body)
  case method_name
    when 'trade' then
      raise "Required parameters are missing" if body["currency_pair"].nil? || body["action"].nil? || body["price"].nil? || body["amount"].nil?
    when 'cancel_order' then
      raise "Required parameters are missing" if body["order_id"].nil?
    when 'withdraw' then
      raise "Required parameters are missing" if body["currency"].nil? || body["address"].nil? || body["amount"].nil?
    when 'deposit_history' then
      raise "Required parameters are missing" if body["currency"].nil?
    when 'withdraw_history' then
      raise "Required parameters are missing" if body["currency"].nil?
  end
end