Module: Kucoin::Api::Endpoints

Included in:
REST
Defined in:
lib/kucoin/api/endpoints.rb,
lib/kucoin/api/endpoints/base.rb,
lib/kucoin/api/endpoints/user.rb,
lib/kucoin/api/endpoints/other.rb,
lib/kucoin/api/endpoints/trade.rb,
lib/kucoin/api/endpoints/markets.rb,
lib/kucoin/api/endpoints/websocket.rb,
lib/kucoin/api/endpoints/trade/fills.rb,
lib/kucoin/api/endpoints/trade/orders.rb,
lib/kucoin/api/endpoints/user/accounts.rb,
lib/kucoin/api/endpoints/user/deposits.rb,
lib/kucoin/api/endpoints/markets/symbols.rb,
lib/kucoin/api/endpoints/markets/tickers.rb,
lib/kucoin/api/endpoints/user/withdrawals.rb,
lib/kucoin/api/endpoints/markets/histories.rb,
lib/kucoin/api/endpoints/markets/currencies.rb,
lib/kucoin/api/endpoints/markets/order_book.rb

Defined Under Namespace

Classes: Base, Markets, Other, Trade, User, Websocket

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.endpoint_method(client_klass, name, result, parent_var = nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/kucoin/api/endpoints.rb', line 86

def self.endpoint_method client_klass, name, result, parent_var = nil
  child_endpoint_klass = Endpoints.get_klass(name, (parent_var && parent_var.class))

  if parent_var
    parent_var.define_singleton_method name do
      endpoint_var = "@#{name}"
      var = instance_variable_get(endpoint_var) || instance_variable_set(endpoint_var, child_endpoint_klass.new(parent_var.client))
      client_klass.generate_endpoint_methods result: result, parent_var: var
      var
    end
  else
    client_klass.class_exec do
      define_method name do
        endpoint_var = "@#{name}"
        var = instance_variable_get(endpoint_var) || instance_variable_set(endpoint_var, child_endpoint_klass.new(self))
        client_klass.generate_endpoint_methods result: result, parent_var: var
        var
      end
    end
  end
end

.get_klass(name, parent = nil) ⇒ Object



82
83
84
# File 'lib/kucoin/api/endpoints.rb', line 82

def self.get_klass name, parent=nil
  Object.const_get("#{parent || 'Kucoin::Api::Endpoints'}::#{name.to_s.split('_').map(&:capitalize).join}")
end

Instance Method Details

#generate_endpoint_methods(result: ENDPOINTS, parent_var: nil) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/kucoin/api/endpoints.rb', line 108

def generate_endpoint_methods result: ENDPOINTS, parent_var: nil
  result.each do |endpoint_name, _result|
    if _result.is_a?(Hash)
      Kucoin::Api::Endpoints.endpoint_method(self, endpoint_name, _result, parent_var)
    end
  end
end