class CoingeckoClient::Client
This is a simple client to connect to Coingecko
Public Class Methods
btc_to_currency()
click to toggle source
Get BTC-to-currency (BTC rate against FIAT, Gold, other coins etc)
# File lib/coingecko_client.rb, line 79 def self.btc_to_currency api_call("exchange_rates") end
coin_history(coin,currency,days)
click to toggle source
# File lib/coingecko_client.rb, line 60 def self.coin_history(coin,currency,days) api_call("coins/#{coin.downcase}/market_chart?vs_currency=#{currency.downcase}&days=#{days}") end
coins_list()
click to toggle source
# File lib/coingecko_client.rb, line 40 def self.coins_list list_coins end
coins_market(currency: 'usd', ids_list: ['bitcoin'], order: 'market_cap_desc', per_page: 100, page: 1, sparkline: false, price_change_percentage: '')
click to toggle source
# File lib/coingecko_client.rb, line 44 def self.coins_market(currency: 'usd', ids_list: ['bitcoin'], order: 'market_cap_desc', per_page: 100, page: 1, sparkline: false, price_change_percentage: '') ids = ids_list.join('%2C') request = "coins/markets?vs_currency=#{currency}&ids=#{ids}" request += "&order=#{order}&per_page=#{per_page}&page=#{page}&sparkline=#{sparkline}" request += "&price_change_percentage=#{price_change_percentage}" unless price_change_percentage.empty? api_call(request) end
coins_trending()
click to toggle source
Returns Top 7 trending coins
# File lib/coingecko_client.rb, line 74 def self.coins_trending api_call("search/trending") end
global()
click to toggle source
Get global data of coins (Total market cap, active coins, market cap percentage)
# File lib/coingecko_client.rb, line 84 def self.global api_call("global") end
global_defi()
click to toggle source
Get global data for decentralized finance aka defi
# File lib/coingecko_client.rb, line 89 def self.global_defi api_call("global/decentralized_finance_defi") end
list_coins()
click to toggle source
coins API calls ################
# File lib/coingecko_client.rb, line 36 def self.list_coins api_call('coins/list') end
list_exchanges(per_page=0, page=1)
click to toggle source
# File lib/coingecko_client.rb, line 64 def self.list_exchanges(per_page=0, page=1) if per_page == 0 api_call("exchanges?page=#{page}") else api_call("exchanges?per_page=#{per_page}&page=#{page}") end end
ping()
click to toggle source
# File lib/coingecko_client.rb, line 11 def self.ping # Check API server status api_call('ping') end
price(coin, currency)
click to toggle source
simple API calls #############
# File lib/coingecko_client.rb, line 17 def self.price(coin, currency) # Get the current price of any cryptocurrencies in any other supported currencies that you need. coin = coin.downcase currency = currency.downcase result = api_call("simple/price?ids=#{coin}&vs_currencies=#{currency}") return nil if result.nil? or !result.any? result[coin][currency] end
status_updates(category: 'general', project_type: '', per_page: 100, page: 1)
click to toggle source
Get status updates from coin maintainers and exchanges
# File lib/coingecko_client.rb, line 94 def self.status_updates(category: 'general', project_type: '', per_page: 100, page: 1) # If project_type empty returns statuses from both coins/markets request = "status_updates/?category=#{category}" request += "&project_type=#{project_type}&per_page=#{per_page}&page=#{page}" api_call(request) end
supported_vs_currencies()
click to toggle source
# File lib/coingecko_client.rb, line 31 def self.supported_vs_currencies api_call('simple/supported_vs_currencies') end
token_price(platform_id='ethereum',address,currency)
click to toggle source
# File lib/coingecko_client.rb, line 27 def self.token_price(platform_id='ethereum',address,currency) api_call("simple/token_price/#{platform_id}?contract_addresses=#{address}&vs_currencies=#{currency}") end
Private Class Methods
api_call(api_request)
click to toggle source
# File lib/coingecko_client.rb, line 104 def self.api_call(api_request) endpoint_head = 'https://api.coingecko.com/api/v3/' url = endpoint_head + api_request response = Excon.get(url) return nil if response.status != 200 JSON.parse(response.body) end