class ZaifWrapper::Client::ZaifLeverageApi

Public Class Methods

new(api_key, api_secret) click to toggle source
# File lib/zaif_wrapper/client.rb, line 130
def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
end

Public Instance Methods

check(method_name, body) click to toggle source
# 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
method_missing(name, *args) click to toggle source
# 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