coingecko_ruby 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +31 -0
  3. data/.gitignore +11 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +66 -0
  6. data/Gemfile +16 -0
  7. data/Gemfile.lock +37 -0
  8. data/README.md +7 -5
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/coingecko_ruby.gemspec +5 -5
  12. data/fixtures/vcr_cassettes/test_that_it_gets_a_coins_complete_current_data.yml +74 -0
  13. data/fixtures/vcr_cassettes/test_that_it_gets_a_coins_tickers.yml +99 -0
  14. data/fixtures/vcr_cassettes/test_that_it_gets_a_derivative_exchange.yml +71 -0
  15. data/fixtures/vcr_cassettes/test_that_it_gets_a_specific_exchange_ticker_from_an_exchange.yml +145 -0
  16. data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_eth_exchange_rate.yml +120 -0
  17. data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_usd_exchange_rate.yml +122 -0
  18. data/fixtures/vcr_cassettes/test_that_it_gets_complete_data_for_an_exchange.yml +72 -0
  19. data/fixtures/vcr_cassettes/test_that_it_gets_daily_historical_prices_for_one_coin.yml +120 -0
  20. data/fixtures/vcr_cassettes/test_that_it_gets_derivative_exchanges.yml +79 -0
  21. data/fixtures/vcr_cassettes/test_that_it_gets_derivatives.yml +1732 -0
  22. data/fixtures/vcr_cassettes/test_that_it_gets_derivatives_exchanges_ids_and_names.yml +95 -0
  23. data/fixtures/vcr_cassettes/test_that_it_gets_event_countries.yml +76 -0
  24. data/fixtures/vcr_cassettes/test_that_it_gets_event_types.yml +71 -0
  25. data/fixtures/vcr_cassettes/test_that_it_gets_exchange_ids_supported_by_coingecko.yml +159 -0
  26. data/fixtures/vcr_cassettes/test_that_it_gets_exchange_tickers_from_an_exchange.yml +78 -0
  27. data/fixtures/vcr_cassettes/test_that_it_gets_finance_platforms.yml +95 -0
  28. data/fixtures/vcr_cassettes/test_that_it_gets_finance_products.yml +100 -0
  29. data/fixtures/vcr_cassettes/test_that_it_gets_global_crypto_data.yml +71 -0
  30. data/fixtures/vcr_cassettes/test_that_it_gets_global_defi_data.yml +71 -0
  31. data/fixtures/vcr_cassettes/test_that_it_gets_historical_price_for_one_coin_at_a_previous_date.yml +173 -0
  32. data/fixtures/vcr_cassettes/test_that_it_gets_hourly_historical_prices_for_one_coin.yml +120 -0
  33. data/fixtures/vcr_cassettes/test_that_it_gets_indexes.yml +127 -0
  34. data/fixtures/vcr_cassettes/test_that_it_gets_indexes_by_market_id_and_coin_id.yml +66 -0
  35. data/fixtures/vcr_cassettes/test_that_it_gets_indexes_by_market_id_and_index_id.yml +71 -0
  36. data/fixtures/vcr_cassettes/test_that_it_gets_indexes_ids.yml +630 -0
  37. data/fixtures/vcr_cassettes/test_that_it_gets_last_7_days_exchange_volume_from_an_exchange.yml +120 -0
  38. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin.yml +169 -0
  39. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin_in_myr.yml +120 -0
  40. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_multiple_coins_in_eth.yml +120 -0
  41. data/fixtures/vcr_cassettes/test_that_it_gets_minutely_historical_prices_for_one_coin.yml +188 -0
  42. data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_30_days_in_myr.yml +120 -0
  43. data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_7_days.yml +120 -0
  44. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_multiple_coins.yml +71 -0
  45. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_multiple_coins_in_different_currencies.yml +71 -0
  46. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin.yml +122 -0
  47. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin_in_a_different_currency.yml +120 -0
  48. data/fixtures/vcr_cassettes/test_that_it_gets_simple_price_for_one_coin.yml +73 -0
  49. data/fixtures/vcr_cassettes/test_that_it_gets_status_updates.yml +79 -0
  50. data/fixtures/vcr_cassettes/test_that_it_gets_status_updates_for_an_exchange.yml +76 -0
  51. data/fixtures/vcr_cassettes/test_that_it_gets_the_list_of_asset_platforms.yml +80 -0
  52. data/fixtures/vcr_cassettes/test_that_it_gets_the_list_of_categories.yml +114 -0
  53. data/fixtures/vcr_cassettes/test_that_it_gets_the_list_of_categories_with_market_data.yml +100 -0
  54. data/fixtures/vcr_cassettes/test_that_it_gets_the_list_of_supported_coins.yml +143 -0
  55. data/fixtures/vcr_cassettes/test_that_it_gets_the_list_of_supported_exchanges.yml +79 -0
  56. data/fixtures/vcr_cassettes/test_that_it_gets_the_list_supported_coins.yml +74 -0
  57. data/fixtures/vcr_cassettes/test_that_it_gets_trending_searches.yml +77 -0
  58. data/lib/coingecko_ruby.rb +1 -1
  59. data/lib/coingecko_ruby/client.rb +20 -0
  60. data/lib/coingecko_ruby/client/categories.rb +85 -0
  61. data/lib/coingecko_ruby/client/coins.rb +213 -10
  62. data/lib/coingecko_ruby/client/derivatives.rb +154 -0
  63. data/lib/coingecko_ruby/client/events.rb +84 -0
  64. data/lib/coingecko_ruby/client/exchanges.rb +193 -0
  65. data/lib/coingecko_ruby/client/finance.rb +100 -0
  66. data/lib/coingecko_ruby/client/indexes.rb +88 -0
  67. data/lib/coingecko_ruby/client/infos.rb +174 -0
  68. data/lib/coingecko_ruby/client/prices.rb +302 -10
  69. data/lib/coingecko_ruby/client/status.rb +7 -1
  70. data/lib/coingecko_ruby/connection.rb +4 -6
  71. data/lib/coingecko_ruby/version.rb +1 -1
  72. metadata +63 -2
@@ -0,0 +1,88 @@
1
+ module CoingeckoRuby
2
+ class Client
3
+ module Indexes
4
+ # Fetches the list of market indexes listed in CoinGecko.
5
+ #
6
+ # @option options [Integer] :per_page (100) sets the number of results to return per page.
7
+ # @option options [Integer] :page sets the page for results.
8
+ #
9
+ # @return [Array<Hash>] each index's id, name, market name, last done, and whether it's a multiasset composite index.
10
+ #
11
+ # @example Get all market indexes.
12
+ # client.indexes
13
+ # @example Sample response object
14
+ # [
15
+ # {"name"=>"CoinFLEX (Futures) DFN",
16
+ # "id"=>"DFN",
17
+ # "market"=>"CoinFLEX (Futures)",
18
+ # "last"=>nil,
19
+ # "is_multi_asset_composite"=>nil},
20
+ # {"name"=>"Bibox (Futures) LINK",
21
+ # "id"=>"LINK",
22
+ # "market"=>"Bibox (Futures)",
23
+ # "last"=>nil,
24
+ # "is_multi_asset_composite"=>nil},
25
+ # {"name"=>"CME Bitcoin Futures BTC",
26
+ # "id"=>"BTC",
27
+ # "market"=>"CME Bitcoin Futures",
28
+ # "last"=>nil,
29
+ # "is_multi_asset_composite"=>false}
30
+ # ]
31
+ def indexes(**options)
32
+ get 'indexes', options
33
+ end
34
+
35
+ # @deprecated Use {#indexes} instead
36
+ def get_indexes(options: {})
37
+ indexes(**options)
38
+ end
39
+
40
+ # Fetches the ids of market indexes listed in CoinGecko.
41
+ #
42
+ # @return [Array<Hash>] each index's id and name.
43
+ #
44
+ # @example Get all market index ids and names.
45
+ # client.index_ids
46
+ # @example Sample response object
47
+ # [
48
+ # {"id"=>"LINK", "name"=>"Bibox (Futures) LINK"},
49
+ # {"id"=>"BTC", "name"=>"CME Bitcoin Futures BTC"},
50
+ # {"id"=>"XRP", "name"=>"Bibox (Futures) XRP"},
51
+ # {"id"=>"ETH", "name"=>"Crypto.com (Futures) ETH"}
52
+ # ]
53
+ def index_ids
54
+ get 'indexes/list'
55
+ end
56
+
57
+ # @deprecated Use {#index_ids} instead
58
+ def get_indexes_ids
59
+ index_ids
60
+ end
61
+
62
+ # Fetches the list of indexes based on the market and index given.
63
+ #
64
+ # @param market_id [String] filter results by the market id.
65
+ # @param coin_id [String] filter indexes from the given market by the index id.
66
+ #
67
+ # @return [Array<Hash>] the index's name, market, last done, and whether it's a multiasset composite index.
68
+ #
69
+ # @example Get all BTC indexes in the CME Futures market.
70
+ # client.indexes_by_market_and_coin(market_id: 'cme_futures', coin_id: 'btc')
71
+ # @example Sample response object
72
+ # {
73
+ # "name"=>"CME Bitcoin Futures BTC",
74
+ # "market"=>"CME Bitcoin Futures",
75
+ # "last"=>nil,
76
+ # "is_multi_asset_composite"=>false
77
+ # }
78
+ def indexes_by_market_and_coin(market_id, coin_id, **options)
79
+ get "indexes/#{market_id}/#{coin_id}", options
80
+ end
81
+
82
+ # @deprecated Use {#indexes_by_market_and_coin} instead
83
+ def get_indexes_by_market_and_index(market_id:, index_id:, options: {})
84
+ indexes_by_market_and_index(market_id, index_id, **options)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,174 @@
1
+ module CoingeckoRuby
2
+ class Client
3
+ module Infos
4
+ # Fetches global crypto data from CoinGecko.
5
+ #
6
+ # @return [Hash] global crypto data (e.g. market cap, total volume, active ICOs, etc.)
7
+ #
8
+ # @example Get global crypto data.
9
+ # client.global_crypto_data
10
+ # @example Sample response object (truncated)
11
+ # {
12
+ # "data" => {
13
+ # "active_cryptocurrencies" => 7361,
14
+ # "upcoming_icos" => 0,
15
+ # "ongoing_icos" => 50,
16
+ # "ended_icos" => 3375,
17
+ # "markets" => 616,
18
+ # "total_market_cap" => {
19
+ # "btc" => 48541739.601360835,
20
+ # "eth" => 628896708.615425,
21
+ # "ltc" => 7052042789.61238,
22
+ # "bch" => 1934433566.5425043
23
+ # },
24
+ # "total_volume" => {
25
+ # "btc" => 6568919.505737251,
26
+ # "eth" => 85105558.43783577,
27
+ # "ltc" => 954318939.049309,
28
+ # "usd" => 286508058915.08606
29
+ # }
30
+ # "market_cap_percentage" => {
31
+ # "btc" => 38.55040456662042,
32
+ # "eth" => 18.387297257364622,
33
+ # },
34
+ # "market_cap_change_percentage_24h_usd" => -3.133283965790086,
35
+ # "updated_at" => 1621344957
36
+ # }
37
+ # }
38
+ def global_crypto_data
39
+ get 'global'
40
+ end
41
+
42
+ # @deprecated Use {#global_crypto_data} instead
43
+ def get_global_crypto_data
44
+ global_crypto_data
45
+ end
46
+
47
+ # Fetches global crypto data from CoinGecko.
48
+ #
49
+ # @return [Hash] global defi data.
50
+ #
51
+ # @example Get global defi data.
52
+ # client.global_defi_data
53
+ # @example Sample response object
54
+ # {
55
+ # "data" => {
56
+ # "defi_market_cap" => "125745676087.2760332093360054945",
57
+ # "eth_market_cap" => "394420680555.8088822113739591981",
58
+ # "defi_to_eth_ratio" =>
59
+ # "31.8811062112863892278072770612100063079659263284319798945238447",
60
+ # "trading_volume_24h" => "15011166214.23270941006219308344",
61
+ # "defi_dominance" =>
62
+ # "5.8997291574682455351428477202615510371051549446051010984545824",
63
+ # "top_coin_name" => "Uniswap",
64
+ # "top_coin_defi_dominance" => 14.449398175884316
65
+ # }
66
+ # }
67
+ def global_defi_data
68
+ get 'global/decentralized_finance_defi'
69
+ end
70
+
71
+ # @deprecated Use {#global_defi_data} instead
72
+ def get_global_defi_data
73
+ global_defi_data
74
+ end
75
+
76
+ # Fetches the top 7 coin searches from CoinGecko in the last 24 hours.
77
+ #
78
+ # @return [Hash] the ternding searches and its information.
79
+ #
80
+ # @example Get trending searches in the last 24 hours.
81
+ # client.trending_searches
82
+ # @example Sample response object (truncated)
83
+ # {
84
+ # "coins" => [{
85
+ # "item" => {
86
+ # "id" => "shiba-inu",
87
+ # "coin_id" => 11939,
88
+ # "name" => "Shiba Inu",
89
+ # "symbol" => "SHIB",
90
+ # "market_cap_rank" => 24,
91
+ # "thumb" =>
92
+ # "https://assets.coingecko.com/coins/images/11939/thumb/SHIBLOGO.png?1600752116",
93
+ # "small" =>
94
+ # "https://assets.coingecko.com/coins/images/11939/small/SHIBLOGO.png?1600752116",
95
+ # "large" =>
96
+ # "https://assets.coingecko.com/coins/images/11939/large/SHIBLOGO.png?1600752116",
97
+ # "slug" => "shiba-inu",
98
+ # "price_btc" => 3.637711629799728e-10,
99
+ # "score" => 0
100
+ # }
101
+ # },
102
+ # ],
103
+ # "exchanges" => []
104
+ # }
105
+ def trending_searches
106
+ get 'search/trending'
107
+ end
108
+
109
+ # @deprecated Use {#trending_searches} instead
110
+ def get_trending_searches
111
+ trending_searches
112
+ end
113
+
114
+ # Fetches coin and/or market status updates.
115
+ #
116
+ # @option options [String] :category filter results by the given category. Valid values: general, milestone, partnership, exchange_listing, software_release, fund_movement, new_listings, event
117
+ # @option options [String] :project_type filter results by the project type. Fetches both coin and market status updates if left blank. Valid values: coin, market
118
+ # @option options [Integer] :per_page sets the number of results to return per page.
119
+ # @option options [Integer] :page sets the page for results.
120
+ #
121
+ # @return [Hash] the list of status updates and its information.
122
+ #
123
+ # @example Get a single status update.
124
+ # client.status_updates(per_page: 1)
125
+ # @example Sample response object
126
+ # {
127
+ # "status_updates" => [{
128
+ # "description" =>
129
+ # "📢 Community Call & AMA Invitation 📢\r\n" +
130
+ # "\r\n" +
131
+ # "Thursday 20th May at 4pm CET (Registration below)\r\n" +
132
+ # "\r\n" +
133
+ # "During this event, we will be updating our community on the latest news and developments at Fuse, covering:\r\n" +
134
+ # "\r\n" +
135
+ # "- Fuse Dollar (fUSD)\r\n" +
136
+ # "- Fuse Cash\r\n" +
137
+ # "- Latest partnerships and integrations.\r\n" +
138
+ # "- Binance Smart Chain (BSC) bridge.\r\n" +
139
+ # "- DeFi on Fuse.\r\n" +
140
+ # "- Featured communities.\r\n" +
141
+ # "- What to expect for the rest of Q2 and beyond!\r\n" +
142
+ # "\r\n" +
143
+ # "Please register 👉 https://bit.ly/3furWZs",
144
+ # "category" => "general",
145
+ # "created_at" => "2021-05-18T08:29:06.537Z",
146
+ # "user" => "Robert Miller",
147
+ # "user_title" => "Marcom Director ",
148
+ # "pin" => false,
149
+ # "project" => {
150
+ # "type" => "Coin",
151
+ # "id" => "fuse-network-token",
152
+ # "name" => "Fuse",
153
+ # "symbol" => "fuse",
154
+ # "image" => {
155
+ # "thumb" =>
156
+ # "https://assets.coingecko.com/coins/images/10347/thumb/vUXKHEe.png?1601523640",
157
+ # "small" =>
158
+ # "https://assets.coingecko.com/coins/images/10347/small/vUXKHEe.png?1601523640",
159
+ # "large" =>
160
+ # "https://assets.coingecko.com/coins/images/10347/large/vUXKHEe.png?1601523640"
161
+ # }
162
+ # }
163
+ # }]
164
+ # }
165
+ def status_updates(**options)
166
+ get 'status_updates', options
167
+ end
168
+
169
+ def get_status_updates(options: {})
170
+ status_updates(**options)
171
+ end
172
+ end
173
+ end
174
+ end
@@ -1,26 +1,318 @@
1
1
  module CoingeckoRuby
2
2
  class Client
3
3
  module Prices
4
- def get_prices(ids:, vs_currencies: 'usd')
5
- get('simple/price', { query: { ids: ids, vs_currencies: vs_currencies } })
4
+ # Fetches the current price for a coin in the given coin or currency.
5
+ # @param ids [String, Array] the coin id or array of ids to fetch.
6
+ # @param currency [String, Array] the currency or array of currencies to display the coin's price. Defaults to 'USD'
7
+ # @option options [Boolean] :include_market_cap include market cap data.
8
+ # @option options [Boolean] :include_24hr_vol include 24 hour volume data.
9
+ # @option options [Boolean] :include_24hr_change include 24 hour price change data.
10
+ # @option options [Boolean] :include_last_updated_at include last updated at value for the given coin.
11
+ #
12
+ # @return [Hash] returns the given coin id and its current price.
13
+ #
14
+ # @example Fetch the current price in USD for Bitcoin.
15
+ # client.price('bitcoin', currency: 'usd')
16
+ # @example Sample response object
17
+ # {
18
+ # "bitcoin" => {
19
+ # "usd" => 47931 # current price in given currency
20
+ # }
21
+ # }
22
+ # @example Fetch the current price, market cap, 24 hour volume, 24 hour price change and last updated at for Bitcoin.
23
+ # client.price('bitcoin', 'usd', include_market_cap: true, include_24hr_vol: true, include_24hr_change: true, include_last_updated_at: true)
24
+ # @example Sample response object
25
+ # {
26
+ # "bitcoin" => {
27
+ # "usd" => 48217, # current price in given currency
28
+ # "usd_market_cap" => 905542853013.7438, # market cap in given currency
29
+ # "usd_24h_vol" => 66724791943.1098, # 24 hour volume in given currency
30
+ # "usd_24h_change" => -2.813036070702345, # 24 hour price change percentage
31
+ # "last_updated_at" => 1621142197 # last updated at UNIX timestamp for the given coin
32
+ # }
33
+ # }
34
+ def price(ids, currency: 'usd', **options)
35
+ ids = ids.join(',') if ids.is_a? Array
36
+ currency = currency.join(',') if currency.is_a? Array
37
+ get 'simple/price', { ids: ids, vs_currencies: currency, **options }
6
38
  end
7
39
 
40
+ # @see Alias for {#price}
41
+ def prices(ids, currency: 'usd', **options)
42
+ price(ids, currency: currency, **options)
43
+ end
44
+
45
+ # @deprecated Use {#price} or {#prices} instead
46
+ def get_price(id:, currency: 'usd', options: {})
47
+ price(id, currency, **options)
48
+ end
49
+
50
+ # Fetches historical price data for a coin at a given date.
51
+ # @param id [String] the coin id to fetch.
52
+ # @param date [String] the date to fetch the historical price, date given must be in the form of 'DD-MM-YYYY' (e.g: '14-05-2021'). Defaults to today's date.
53
+ #
54
+ # @return [Hash] returns the coin's historical price data on the given date.
55
+ #
56
+ # @example Fetch Bitcoin's price on 30th December, 2017.
57
+ # client.historical_price('bitcoin', date: '30-12-2017')
58
+ # @example Sample response object (truncated)
59
+ # {
60
+ # "id": "bitcoin",
61
+ # "symbol": "btc",
62
+ # "name": "Bitcoin",
63
+ # "localization": {
64
+ # "en": "Bitcoin",
65
+ # "ja": "ビットコイン",
66
+ # "id": "Bitcoin"
67
+ # },
68
+ # "image": {
69
+ # "thumb": "https://assets.coingecko.com/coins/images/1/thumb/bitcoin.png?1547033579",
70
+ # "small": "https://assets.coingecko.com/coins/images/1/small/bitcoin.png?1547033579"
71
+ # },
72
+ # "market_data": {
73
+ # "current_price": {
74
+ # "btc": 1,
75
+ # "eth": 18.483094024188404,
76
+ # "eur": 11345.8976447824,
77
+ # "gbp": 10079.0677868681,
78
+ # "usd": 13620.3618741461,
79
+ # },
80
+ # "market_cap": {
81
+ # "btc": 16772375,
82
+ # "eth": 310005384.13394696,
83
+ # "eur": 190297650009.907,
84
+ # "gbp": 169049904571.772,
85
+ # "usd": 228445816988.881,
86
+ # },
87
+ # "total_volume": {
88
+ # "btc": 264345.493482963,
89
+ # "eth": 4885922.610916088,
90
+ # "eur": 2999236911.91719,
91
+ # "gbp": 2664356147.96788,
92
+ # "usd": 3600481281.03768,
93
+ # }
94
+ # },
95
+ # "community_data": {
96
+ # "facebook_likes": null,
97
+ # "twitter_followers": 603664,
98
+ # "reddit_average_posts_48h": 2.042,
99
+ # "reddit_average_comments_48h": 445.896,
100
+ # "reddit_subscribers": 612412,
101
+ # "reddit_accounts_active_48h": "14074.0"
102
+ # },
103
+ # "developer_data": {
104
+ # "forks": 13660,
105
+ # "stars": 23665,
106
+ # "subscribers": 2513,
107
+ # "total_issues": 3591,
108
+ # "closed_issues": 3022,
109
+ # "pull_requests_merged": 5038,
110
+ # "pull_request_contributors": 450,
111
+ # "code_additions_deletions_4_weeks": {
112
+ # "additions": null,
113
+ # "deletions": null
114
+ # },
115
+ # "commit_count_4_weeks": 147
116
+ # },
117
+ # "public_interest_stats": {
118
+ # "alexa_rank": 2912,
119
+ # "bing_matches": null
120
+ # }
121
+ # }
122
+ def historical_price(id, date:, **options)
123
+ date = Time.now.strftime('%d-%m-%Y') if date.nil?
124
+
125
+ get "coins/#{id}/history", { date: date, **options }
126
+ end
127
+
128
+ # @deprecated Use {#historical_price} instead
8
129
  def get_historical_price_on_date(id:, date:)
9
- get("coins/#{id}/history", { query: { date: date } })
130
+ historical_price(id, date: date)
131
+ end
132
+
133
+ # Fetches a coin's historical price data in 5 - 10 minutes ranges.
134
+ # @note Minutely historical data is only available within the last 24 hours.
135
+ # @param id [String] the coin id to fetch.
136
+ # @param currency [String] the currency used to display minutely historical price. Defaults to 'USD'
137
+ #
138
+ # @return [Hash] returns the coin's minutely historical price data within the last 24 hours.
139
+ #
140
+ # @example Fetch Bitcoin's minutely historical price within the last 24 hours.
141
+ # client.minutely_historical_price('bitcoin')
142
+ # @example Sample response object (truncated)
143
+ # {
144
+ # "prices" => [
145
+ # [1621057474114, 49364.605172521166], # [UNIX timestamp for minutely price data, coin price in given currency]
146
+ # [1621057731319, 49482.24672699064],
147
+ # [1621058047104, 49759.16253913667],
148
+ # ],
149
+ # "market_caps" => [
150
+ # [1621057474114, 923529491095.7441],
151
+ # [1621057731319, 923529491095.7441],
152
+ # [1621058047104, 925839705121.9677],
153
+ # ],
154
+ # "total_volumes" => [
155
+ # [1621057474114, 55351845301.87241],
156
+ # [1621057731319, 55565821585.076706],
157
+ # [1621058047104, 57046967935.326035],
158
+ # ]
159
+ # }
160
+ def minutely_historical_price(id, currency: 'usd', **options)
161
+ get "coins/#{id}/market_chart", { vs_currency: currency, days: 1, **options }
10
162
  end
11
163
 
12
- def get_minutely_historical_prices(id:, vs_currency: 'usd')
13
- get("coins/#{id}/market_chart", { query: { vs_currency: vs_currency, days: 1 } })
164
+ # @deprecated Use {#minutely_historical_price} instead
165
+ def get_minutely_historical_prices(id:, currency: 'usd')
166
+ minutely_historical_price(id, currency: currency)
167
+ end
168
+
169
+ # Fetches a coin's historical price data in 1 hour ranges.
170
+ # @note Hourly historical data is only available within the last 90 days.
171
+ # @param id [String] the coin id to fetch.
172
+ # @param currency [String] the currency used to display hourly historical price. Defaults to 'USD'
173
+ # @param days [Integer] the number of days to fetch hourly historical prices (min: 1 day, max: 90 days). Defaults to 7 days
174
+ #
175
+ # @return [Hash] returns the coin's hourly historical price data within the number of days given.
176
+ #
177
+ # @example Fetch Bitcoin's hourly historical price in USD within the last 7 days.
178
+ # client.hourly_historical_price('bitcoin', days: 7)
179
+ # @example Sample response object (truncated)
180
+ # {
181
+ # "prices" => [
182
+ # [1620540153122, 58533.64354969528], # [UNIX timestamp for minutely price data, coin price in given currency]
183
+ # [1620543723872, 58384.26782776662],
184
+ # [1620547381049, 58022.030773147424],
185
+ # ], "market_caps" => [
186
+ # [1620540153122, 1094831531450.288],
187
+ # [1620543723872, 1092040480555.5005],
188
+ # [1620547381049, 1085268316789.8125],
189
+ # ], "total_volumes" => [
190
+ # [1620540153122, 71975097904.11748],
191
+ # [1620543723872, 72192190625.33702],
192
+ # [1620547381049, 72064327648.28767],
193
+ # ]
194
+ # }
195
+ def hourly_historical_price(id, currency: 'usd', days: 7, **options)
196
+ return daily_historical_price(id, currrency: currency, days: days) if days > 90
197
+
198
+ get "coins/#{id}/market_chart", { vs_currency: currency, days: days, **options }
14
199
  end
15
200
 
16
- def get_hourly_historical_prices(id:, days:)
17
- return get_daily_historical_prices(id: id, days: days) if days > 90
201
+ # @deprecated Use {#hourly_historical_price} instead
202
+ def get_hourly_historical_prices(id:, days:, currency: 'usd')
203
+ hourly_historical_price(id, currency: currency, days: days)
204
+ end
205
+
206
+ # Fetches a coin's historical price data in daily ranges.
207
+ # @param id [String] the coin id to fetch.
208
+ # @param days [Integer] the number of days to fetch daily historical prices. Defaults to 7 days.
209
+ # @param currency [String] the currency used to display daily historical price. Defaults to USD.
210
+ #
211
+ # @return [Hash] returns the coin's daily historical price data within the number of days given.
212
+ #
213
+ # @example Fetch Bitcoin's daily historical price within the last 14 days.
214
+ # client.daily_historical_prices('bitcoin', days: 14)
215
+ # @example Sample response object (truncated)
216
+ # {
217
+ # "prices" => [
218
+ # [1620000000000, 56600.74528738432], # [UNIX timestamp for minutely price data, coin price in given currency]
219
+ # [1620086400000, 57200.30029871162],
220
+ # [1620172800000, 53464.37021950372],
221
+ # ], "market_caps" => [
222
+ # [1620000000000, 1057850321948.5465],
223
+ # [1620086400000, 1069571255195.5189],
224
+ # [1620172800000, 999775008412.3738],
225
+ # ], "total_volumes" => [
226
+ # [1620000000000, 39072664393.929405],
227
+ # [1620086400000, 54132470274.07509],
228
+ # [1620172800000, 71296763919.13268],
229
+ # ]
230
+ # }
231
+ def daily_historical_price(id, currency: 'usd', days: 7, **options)
232
+ get "coins/#{id}/market_chart", { vs_currency: currency, days: days, interval: 'daily', **options }
233
+ end
234
+
235
+ # @deprecated Use {#daily_historical_price} instead
236
+ def get_daily_historical_prices(id:, days:, currency: 'usd')
237
+ daily_historical_price(id, currency: currency, days: days)
238
+ end
239
+
240
+ # Fetches a coin's open, high, low, and close (OHLC) data within the number of days given.
241
+ # @param id [String] the coin id to fetch.
242
+ # @param days [Integer, String] the number of days to fetch daily historical prices. Valid values: 1/7/14/30/90/180/365/'max'. Defaults to 7 days.
243
+ # @param currency [String] the currency to display OHLC data. Defaults to 'USD'.
244
+ #
245
+ # @return [Array<Array<String, Float>>] returns the coin's OHLC data within the number of days given.
246
+ # If the number of days given is between 1-2 days, the OHLC data is returned in 30-minute intervals.
247
+ # If the number of days given is between 3-30 days, the OHLC data is returned in 4-hour intervals.
248
+ # If the number of days given is more than 30 days, the OHLC data is returned in 4-day intervals.
249
+ #
250
+ # @example Fetch Bitcoin's OHLC data within the last 7 days.
251
+ # client.ohlc('bitcoin', days: 7)
252
+ # @example Sample response object (truncated)
253
+ # [
254
+ # [1620547200000, 58384.27, 58384.27, 58384.27, 58384.27], # [UNIX timestamp for OHLC data, open, high, low, close]
255
+ # [1620561600000, 58022.03, 58214.96, 57943.18, 58048.35],
256
+ # [1620576000000, 57956.7, 57956.7, 56636.68, 57302.22],
257
+ # ]
258
+ def ohlc(id, currency: 'usd', days: 7, **options)
259
+ get "coins/#{id}/ohlc", { vs_currency: currency, days: days, **options }
260
+ end
261
+
262
+ # @deprecated Use {#ohlc} instead
263
+ def get_ohlc(id:, days:, currency: 'usd')
264
+ ohlc(id, currency: currency, days: days)
265
+ end
266
+
267
+ # Fetches the list of currencies currently supported by CoinGecko's API.
268
+ #
269
+ # @return [Array<String>] returns the list of currencies currently supported by CoinGecko's API.
270
+ #
271
+ # @example Fetch supported currencies.
272
+ # client.supported_currencies
273
+ # @example Sample response object (truncated)
274
+ # [
275
+ # "btc",
276
+ # "eth",
277
+ # "yfi",
278
+ # "usd",
279
+ # "aud",
280
+ # "eur",
281
+ # "gbp",
282
+ # ]
283
+ def supported_currencies
284
+ get 'simple/supported_vs_currencies'
285
+ end
18
286
 
19
- get("coins/#{id}/market_chart", { query: { vs_currency: vs_currency, days: days } })
287
+ # Fetches the exchange rate for a coin or currency in the given coin or currency.
288
+ # @param from [String] the coin id or currency to be converted.
289
+ # @param to [String] the coin id or currency to convert against. Defaults to 'USD'.
290
+ #
291
+ # @return [Hash] returns the coin's exchange rate against the given coin or currency.
292
+ #
293
+ # @example Fetch the exchange rate for BTC-USD.
294
+ # client.exchange_rate(from: 'bitcoin', to: 'usd')
295
+ # @example Sample response object
296
+ # {
297
+ # "bitcoin" => {
298
+ # "usd" => 47931 # current price in given currency
299
+ # }
300
+ # }
301
+ # @example Fetch the exchange rate for BTC-ETH.
302
+ # client.get_exchange_rate(from: 'bitcoin', to: 'eth')
303
+ # @example Sample response object
304
+ # {
305
+ # "bitcoin" => {
306
+ # "eth" => 12.71434 # current price in given currency
307
+ # }
308
+ # }
309
+ def exchange_rate(from:, to: 'usd')
310
+ price(from, currency: to)
20
311
  end
21
312
 
22
- def get_daily_historical_prices(id:, days:)
23
- get("coins/#{id}/market_chart", { query: { vs_currency: vs_currency, days: days, interval: 'daily' } })
313
+ # @deprecated Use {#exchange_rate} instead
314
+ def get_exchange_rate(from:, to: 'usd')
315
+ exchange_rate(from: from, to: to)
24
316
  end
25
317
  end
26
318
  end