Module: CoinmarketcapFree

Defined in:
lib/coinmarketcap_free.rb,
lib/coinmarketcap_free/coin.rb,
lib/coinmarketcap_free/icon.rb,
lib/coinmarketcap_free/helper.rb,
lib/coinmarketcap_free/version.rb,
lib/coinmarketcap_free/coin_history.rb

Overview

Get data from Coinmarketcap API without requiring an API key.

Defined Under Namespace

Modules: Coin, CoinHistory, Helper, Icon

Constant Summary collapse

BASE_URI =
'https://api.coinmarketcap.com/data-api/'
VERSION_API =
'v3'
VERSION =
"#{MAJOR}.#{MINOR}.#{PATCH}"

Class Method Summary collapse

Class Method Details

.coin_history(id, range_time) ⇒ Hash

Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.

You can use one of the following intervals: 1D, 7D, 1M, 3M, 1Y, YTD, ALL

history = CoinmarketcapFree.coin_history(1, '1D')

Also you can use this method like this:

history = CoinmarketcapFree.coin_history(1, '1668981600~1671659999') do |data|
    JSON.parse(data)
end

‘data’ - Results of your query returned as an object map. ‘points’ - Price range history ‘status’ - Standardized status object for API calls.

Parameters:

  • id (Integer)

    Cryptocurrency identifier from coinmarketcap. For example, Bitcoin has the number 1

  • range_time (String)

    Range time. For example, ‘1D’, ‘7D’, ‘1M’, ‘3M’, ‘1Y’, ‘YTD’, ‘ALL’ or custom range ‘1668981600~1671659999’

Returns:

  • (Hash)


81
82
83
84
85
86
87
# File 'lib/coinmarketcap_free.rb', line 81

def coin_history(id, range_time)
  data = CoinHistory.custom_time(id, range_time)

  return yield data if block_given?

  JSON.parse(data)
end

.coin_icon(id_coin, size) ⇒ String

Generate URI image of a coin

 = CoinmarketcapFree.coin_icon(1, 64)

Result:

"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"

Parameters:

  • id_coin (Integer)

    Identify coin. For example, bitcoin has 1

  • size (Integer)

    Choose one size: 64, 128, 200

Returns:

  • (String)

    Return URI from coinmarketcap



99
100
101
# File 'lib/coinmarketcap_free.rb', line 99

def coin_icon(id_coin, size)
  Icon.generate_url(id_coin, size)
end

.coins(**params) ⇒ Hash

Get a list of cryptocurrencies

list = CoinmarketcapFree.coins(limit: 100, start: 1)

If you want to sort in ascending, just write parameter:

list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'asc')

or

list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'desc')

You can also adding sort by:

list = CoinmarketcapFree.coins(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
Convert cryptocurrency to

list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: ‘USD,BTC,ETH’)

Also you can use this method like this:

list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD,BTC,ETH') do |data|
    JSON.parse(data)
end

Parameters:

  • start (Integer)

    Optionally offset the start (1-based index) of the paginated list of items to return.

  • limit (Integer)

    Optionally specify the number of results to return. Use this parameter and the ‘start’ parameter to determine your own pagination size.

  • sort_by (String)

    What field to sort the list of cryptocurrencies by. (‘rank’, ‘name’, ‘symbol’, ‘date_added’, ‘market_cap’, ‘market_cap_strict’, ‘price’, ‘circulating_supply’, ‘total_supply’, ‘max_supply’, ‘num_market_pairs’, ‘volume_24h’, ‘percent_change_1h’, ‘percent_change_24h’, ‘percent_change_7d’, ‘market_cap_by_total_supply_strict’, ‘volume_7d’, ‘volume_30d“)

  • sort_type (String)

    The direction in which to order cryptocurrencies against the specified sort. (‘asc’, ‘desc’)

  • convert (String)

    Select cryptocurrencies to exchange (‘AUD’, ‘BRL’, ‘CAD’, ‘CHF’, ‘CLP’, ‘CNY’, ‘CZK’, ‘DKK’, ‘EUR’, ‘GBP’, ‘HKD’, ‘HUF’, ‘IDR’, ‘ILS’, ‘INR’, ‘JPY’, ‘KRW’, ‘MXN’, ‘MYR’, ‘NOK’, ‘NZD’, ‘PHP’, ‘PKR’, ‘PLN’, ‘RUB’, ‘SEK’, ‘SGD’, ‘THB’, ‘TRY’, ‘TWD’, ‘ZAR’). For example, many ‘USD,BTC,ETH’ to convert or only one ‘USD’

  • crypto_type (String)

    The type of cryptocurrency to include. (‘all’, ‘coins’, ‘tokens’)

  • tag_type (String)

    The tag of cryptocurrency to include. (‘all’, ‘defi’, ‘filesharing’)

  • audited (TrueClass, FalseClass)

    Show audited ‘true’ or not ‘false’

  • aux (String)

    Optionally specify a comma-separated list of supplemental data fields to return. Pass ‘ath, atl, high24h, low24h, num_market_pairs, cmc_rank, date_added, max_supply, circulating_supply, total_supply, volume_7d, volume_30d, self_reported_circulating_supply, self_reported_market_cap’ to include all auxiliary fields.

  • tags (String)

    If you want to see cryptocurrencies that can be mined, just type ‘mineable’.

  • volume24h_range (String)

    Optionally specify a threshold 24 hour USD volume to filter results by. For example, ‘0~100000000000000000’

  • percent_change24h_range (String)

    Optionally specify a threshold 24 hour percent change to filter results by. For example, ‘0~100’ or ‘-10~100’

  • circulating_supply_range (String)

    Optionally specify a threshold circulating supply to filter results by. For example, ‘0~100000000000000000’

  • price_range (String)

    Optionally specify a threshold USD price to filter results by. For example, ‘0~100000000000000000’

  • market_cap_range (String)

    Optionally specify a threshold market cap to filter results by. For example, ‘0~100000000000000000’

Returns:

  • (Hash)


54
55
56
57
58
59
60
# File 'lib/coinmarketcap_free.rb', line 54

def coins(**params)
  data = Coin.list(params)

  return yield data if block_given?

  JSON.parse(data)
end