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
-
.coin_history(id, range_time) ⇒ Hash
Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
-
.coin_icon(id_coin, size) ⇒ String
Generate URI image of a coin.
-
.coins(**params) ⇒ Hash
Get a list of cryptocurrencies.
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.
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
logo = CoinmarketcapFree.coin_icon(1, 64)
Result:
"https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
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
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 |