class FtxExchangeApi::BaseApi

Attributes

config[R]

Public Class Methods

new(config: nil) click to toggle source
# File lib/ftx_exchange_api/base_api.rb, line 11
def initialize(config: nil)
  @config = Config.new(config)
  @config.reverse_merge!(FtxExchangeApi.default_config)
end

Protected Instance Methods

send_request(method, path, headers, query) click to toggle source
# File lib/ftx_exchange_api/base_api.rb, line 18
def send_request(method, path, headers, query)
  uuid = SecureRandom.uuid
  print_log(:info, "[API] #{uuid} #{method.upcase} '#{path}' query = #{query}")

  body_or_query = method == :get ? :query : :body

  begin
    response = self.class.send(
      method,
      path,
      headers: headers,
      timeout: @config.timeout,
      body_or_query => query,
    ).parsed_response

    print_log(:info, "[API] #{uuid} response #{response}")
    return response
  rescue => error
    print_log(:error, "[API] #{uuid} raise exception #{error.message}")
    raise error
  end
end

Private Instance Methods

print_log(method, message) click to toggle source