class CoinMarketPro::Endpoint::Tools

@see pro.coinmarketcap.com/api/v1#tag/exchange

Constants

ENDPOINT

Public Instance Methods

price_conversion(**args) click to toggle source

Convert an amount of one currency into up to 32 other cryptocurrency or fiat currencies

at the same time using latest exchange rates.
Optionally pass a historical timestamp to convert values based on historic averages.

@param [Hash] args @option args [Number] :amount @option args [Array<Integer>] :id @option args [Array<String>] :symbol @option args [String] :time @option args [String] :convert @return [CoinMarketPro::Result]

@see pro.coinmarketcap.com/api/v1#operation/getV1ToolsPriceconversion

# File lib/coin_market_pro/endpoint/tools.rb, line 22
def price_conversion(**args)
  valid_params?(args)
  params = convert_params(args)
  client.get("#{ENDPOINT}/price-conversion", options: params.compact).tap do |resp|
    resp.body = [resp.body]
  end
end

Protected Instance Methods

valid_params?(args) click to toggle source

@param args [Hash] @return [Boolean] @raise [ArgumentError]

# File lib/coin_market_pro/endpoint/tools.rb, line 35
def valid_params?(args)
  raise ArgumentError.new('amount is required.') if args[:amount].blank?
  raise ArgumentError.new('At least one "id" or "slug" is required.') if args[:id].blank? && args[:slug].blank?

  true
end