Class: CoingeckoClient::Client
- Inherits:
-
Object
- Object
- CoingeckoClient::Client
- Defined in:
- lib/coingecko_client.rb
Overview
This is a simple client to connect to Coingecko
Class Method Summary collapse
-
.btc_to_currency ⇒ Object
Get BTC-to-currency (BTC rate against FIAT, Gold, other coins etc).
- .coin_history(coin, currency, days) ⇒ Object
- .coins_list ⇒ Object
- .coins_market(currency: 'usd', ids_list: ['bitcoin'], order: 'market_cap_desc', per_page: 100, page: 1, sparkline: false, price_change_percentage: '') ⇒ Object
-
.coins_trending ⇒ Object
Returns Top 7 trending coins.
-
.global ⇒ Object
Get global data of coins (Total market cap, active coins, market cap percentage).
-
.global_defi ⇒ Object
Get global data for decentralized finance aka defi.
-
.list_coins ⇒ Object
coins API calls ################.
- .list_exchanges(per_page = 0, page = 1) ⇒ Object
- .ping ⇒ Object
-
.price(coin, currency) ⇒ Object
simple API calls #############.
-
.status_updates(category: 'general', project_type: '', per_page: 100, page: 1) ⇒ Object
Get status updates from coin maintainers and exchanges.
- .supported_vs_currencies ⇒ Object
- .token_price(platform_id = 'ethereum', address, currency) ⇒ Object
Class Method Details
.btc_to_currency ⇒ Object
Get BTC-to-currency (BTC rate against FIAT, Gold, other coins etc)
79 80 81 |
# File 'lib/coingecko_client.rb', line 79 def self.btc_to_currency api_call("exchange_rates") end |
.coin_history(coin, currency, days) ⇒ Object
60 61 62 |
# 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 ⇒ Object
40 41 42 |
# 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: '') ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
Returns Top 7 trending coins
74 75 76 |
# File 'lib/coingecko_client.rb', line 74 def self.coins_trending api_call("search/trending") end |
.global ⇒ Object
Get global data of coins (Total market cap, active coins, market cap percentage)
84 85 86 |
# File 'lib/coingecko_client.rb', line 84 def self.global api_call("global") end |
.global_defi ⇒ Object
Get global data for decentralized finance aka defi
89 90 91 |
# File 'lib/coingecko_client.rb', line 89 def self.global_defi api_call("global/decentralized_finance_defi") end |
.list_coins ⇒ Object
coins API calls ################
36 37 38 |
# File 'lib/coingecko_client.rb', line 36 def self.list_coins api_call('coins/list') end |
.list_exchanges(per_page = 0, page = 1) ⇒ Object
64 65 66 67 68 69 70 71 |
# 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 ⇒ Object
11 12 13 14 |
# File 'lib/coingecko_client.rb', line 11 def self.ping # Check API server status api_call('ping') end |
.price(coin, currency) ⇒ Object
simple API calls #############
17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
Get status updates from coin maintainers and exchanges
94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
31 32 33 |
# 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) ⇒ Object
27 28 29 |
# 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 |