Class: ZaifWrapper::Client::ZaifLeverageApi
- Inherits:
-
ZaifParentApi
- Object
- ZaifParentApi
- ZaifWrapper::Client::ZaifLeverageApi
- 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
- #check(method_name, body) ⇒ Object
-
#initialize(api_key, api_secret) ⇒ ZaifLeverageApi
constructor
A new instance of ZaifLeverageApi.
- #method_missing(name, *args) ⇒ Object
Methods inherited from ZaifParentApi
#create_signature, #get_nonce, #get_request, #post_request
Constructor Details
#initialize(api_key, api_secret) ⇒ ZaifLeverageApi
Returns a new instance of ZaifLeverageApi.
130 131 132 133 |
# File 'lib/zaif_wrapper/client.rb', line 130 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
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/zaif_wrapper/client.rb', line 135 def method_missing(name, *args) if LEVERAGE_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, LEVERAGE_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
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/zaif_wrapper/client.rb', line 153 def check(method_name, body) case method_name when 'get_positions' then raise "Required parameters are missing" if body["type"].nil? || (body["type"] == 'futures' && body["group_id"].nil?) when 'position_history' then raise "Required parameters are missing" if body["type"].nil? || (body["type"] == 'futures' && body["group_id"].nil?) when 'active_positions' then raise "Required parameters are missing" if body["type"].nil? || (body["type"] == 'futures' && body["group_id"].nil?) when 'create_position' then raise "Required parameters are missing" if body["type"].nil? || (body["type"] == 'futures' && body["group_id"].nil?) || body["currency_pair"].nil? || body["action"].nil? || body["price"].nil? || body["amount"].nil? || body["leverage"].nil? when 'change_position' then raise "Required parameters are missing" if body["type"].nil? || (body["type"] == 'futures' && body["group_id"].nil?) || body["leverage_id"].nil? || body["price"].nil? when 'cancel_position' then raise "Required parameters are missing" if body["type"].nil? || (body["type"] == 'futures' && body["group_id"].nil?) || body["leverage_id"].nil? end end |