coingecko_ruby 0.3.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +27 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +10 -10
  7. data/fixtures/vcr_cassettes/test_that_it_gets_a_specific_exchange_ticker_from_an_exchange.yml +70 -0
  8. data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_eth_exchange_rate.yml +49 -0
  9. data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_usd_exchange_rate.yml +49 -0
  10. data/fixtures/vcr_cassettes/test_that_it_gets_daily_historical_prices_for_one_coin.yml +49 -0
  11. data/fixtures/vcr_cassettes/test_that_it_gets_historical_price_for_one_coin_at_a_previous_date.yml +49 -0
  12. data/fixtures/vcr_cassettes/test_that_it_gets_hourly_historical_prices_for_one_coin.yml +49 -0
  13. data/fixtures/vcr_cassettes/test_that_it_gets_indexes_by_market_id_and_coin_id.yml +66 -0
  14. data/fixtures/vcr_cassettes/test_that_it_gets_last_7_days_exchange_volume_from_an_exchange.yml +49 -0
  15. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin.yml +98 -0
  16. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin_in_myr.yml +49 -0
  17. data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_multiple_coins_in_eth.yml +49 -0
  18. data/fixtures/vcr_cassettes/test_that_it_gets_minutely_historical_prices_for_one_coin.yml +49 -0
  19. data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_30_days_in_myr.yml +47 -0
  20. data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_7_days.yml +47 -0
  21. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin.yml +49 -0
  22. data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin_in_a_different_currency.yml +49 -0
  23. data/lib/coingecko_ruby/client.rb +6 -0
  24. data/lib/coingecko_ruby/client/categories.rb +21 -6
  25. data/lib/coingecko_ruby/client/coins.rb +28 -15
  26. data/lib/coingecko_ruby/client/derivatives.rb +30 -9
  27. data/lib/coingecko_ruby/client/events.rb +21 -6
  28. data/lib/coingecko_ruby/client/exchanges.rb +45 -13
  29. data/lib/coingecko_ruby/client/finance.rb +14 -4
  30. data/lib/coingecko_ruby/client/indexes.rb +22 -7
  31. data/lib/coingecko_ruby/client/infos.rb +27 -8
  32. data/lib/coingecko_ruby/client/prices.rb +74 -30
  33. data/lib/coingecko_ruby/connection.rb +5 -9
  34. data/lib/coingecko_ruby/version.rb +1 -1
  35. metadata +4 -2
@@ -9,7 +9,7 @@ module CoingeckoRuby
9
9
  # @return [Array<Hash>] returns an array of hashes of detailed exchange data.
10
10
  #
11
11
  # @example Fetch complete exchange data with 1 result per page.
12
- # client.get_exchanges(options: { per_page: 1 })
12
+ # client.exchanges(per_page: 1)
13
13
  # @example Sample response object
14
14
  # [{
15
15
  # "id" => "binance",
@@ -25,8 +25,13 @@ module CoingeckoRuby
25
25
  # "trade_volume_24h_btc" => 982949.3975723931,
26
26
  # "trade_volume_24h_btc_normalized" => 982949.3975723931
27
27
  # }]
28
+ def exchanges(**options)
29
+ get 'exchanges', **options
30
+ end
31
+
32
+ # @deprecated Use {#exchanges} instead
28
33
  def get_exchanges(options: {})
29
- get 'exchanges', { options: options }
34
+ exchanges(**options)
30
35
  end
31
36
 
32
37
  # Fetches complete data for a specific exchange.
@@ -36,17 +41,22 @@ module CoingeckoRuby
36
41
  # @return [Hash] returns detailed data for the given exchange.
37
42
  #
38
43
  # @example Fetch complete exchange data for Binance.
39
- # client.get_exchange_data(id: 'binance')
40
- def get_exchange_data(id:)
44
+ # client.exchange('binance')
45
+ def exchange(id)
41
46
  get "exchanges/#{id}"
42
47
  end
43
48
 
49
+ # @deprecated Use {#exchange} instead
50
+ def get_exchange_data(id:)
51
+ exchange(id)
52
+ end
53
+
44
54
  # Fetches exchange ids for every exchange currently supported by the CoinGecko API.
45
55
  #
46
56
  # @return [Array<Hash>] returns an array of hashes of the exchange id and name.
47
57
  #
48
58
  # @example Fetch all exchange ids.
49
- # client.get_exchanges_ids
59
+ # client.exchange_ids
50
60
  # @example Sample response object
51
61
  # [{
52
62
  # "id" => "aave",
@@ -58,13 +68,19 @@ module CoingeckoRuby
58
68
  # "id" => "aax_futures",
59
69
  # "name" => "AAX Futures"
60
70
  # }]
61
- def get_exchanges_ids
71
+ def exchange_ids
62
72
  get 'exchanges/list'
63
73
  end
64
74
 
75
+ # @deprecated Use {#exchange_ids} instead
76
+ def get_exchanges_ids
77
+ exchange_ids
78
+ end
79
+
65
80
  # Fetches coin tickers from a specific exchange.
66
81
  #
67
82
  # @param id [String] the exchange id to fetch.
83
+ #
68
84
  # @option options [String] :coin_ids comma-separated list of tickers to fetch from the given exchange id (e.g. 'bitcoin, eth, litecoin').
69
85
  # @option options [String] :include_exchange_logo includes the exchange's logo.
70
86
  # @option options [Integer] :page sets the page for results.
@@ -74,7 +90,7 @@ module CoingeckoRuby
74
90
  # @return [Hash] the exchange name and tickers as provided or all tickers if coin_ids is not provided.
75
91
  #
76
92
  # @example Get Bitcoin tickers from Binance.
77
- # client.get_exchange_tickers(id: 'binance', options: { coin_ids: 'bitcoin' })
93
+ # client.exchange_tickers('binance', coin_ids: 'bitcoin')
78
94
  # @example Sample response object
79
95
  # {
80
96
  # "name" => "Binance", "tickers" => [{
@@ -104,20 +120,26 @@ module CoingeckoRuby
104
120
  # "target_coin_id" => "tether"
105
121
  # }]
106
122
  # }
123
+ def exchange_tickers(id, **options)
124
+ get "exchanges/#{id}/tickers", **options
125
+ end
126
+
127
+ # @deprecated Use {#exchange_tickers} instead
107
128
  def get_exchange_tickers(id:, options: {})
108
- get "exchanges/#{id}/tickers", { options: options }
129
+ exchange_tickers(id, **options)
109
130
  end
110
131
 
111
132
  # Fetches news,announcments, and updates from a specific exchange.
112
133
  #
113
134
  # @param id [String] the exchange id to fetch.
135
+ #
114
136
  # @option options [Integer] :per_page (100) sets the number of results to return per page.
115
137
  # @option options [Integer] :page sets the page for results.
116
138
  #
117
139
  # @return [Hash] the status update data for the given exchange.
118
140
  #
119
141
  # @example Get the last 3 status updates from Binance.
120
- # client.get_exchange_status_updates(id: 'binance', options: { per_page: 1 })
142
+ # client.exchange_status('binance', per_page: 1)
121
143
  # @example Sample response object
122
144
  # {
123
145
  # "status_updates" => [{
@@ -134,27 +156,37 @@ module CoingeckoRuby
134
156
  # }
135
157
  # }]
136
158
  # }
159
+ def exchange_status(id, **options)
160
+ get "exchanges/#{id}/status_updates", **options
161
+ end
162
+
163
+ # @deprecated Use {#exchange_status} instead
137
164
  def get_exchange_status_updates(id:, options: {})
138
- get "exchanges/#{id}/status_updates", { options: options }
165
+ exchange_status(id, **options)
139
166
  end
140
167
 
141
168
  # Fetches trade volume data from a specific exchange.
142
169
  #
143
170
  # @param id [String] the exchange id to fetch.
144
- # @param days [Integer] number of days ago to fetch trade volume data.
171
+ # @param days [Integer] number of days ago to fetch trade volume data. Defaults to 7 days.
145
172
  #
146
173
  # @return [Array<Array<Float, String>>] the exchange's trade volume data in 10-minute intervals, hourly intervals, or daily intervals depending on the number of days given
147
174
  #
148
175
  # @example Get Binance's trade volume from a day ago.
149
- # client.get_exchange_volume(id: 'binance', days: 1)
176
+ # client.exchange_volume('binance', days: 1)
150
177
  # @example Sample response object (truncated)
151
178
  # [
152
179
  # [1620550200000.0, "1005476.2667217359131632087795432176371669876601688256288859094077173967202827700534809705802"], # [UNIX timestamp for exchange trade volume data, trade volume]
153
180
  # [1620553800000.0, "1018442.2775982988468591292487708941265043962519659923872972786095536137127193126138169804088"],
154
181
  # [1620557400000.0, "1042158.4333253484568599192332614201045319574863305612009609211497295171074087677404153278624"]
155
182
  # ]
183
+ def exchange_volume(id, days: 7, **options)
184
+ get "exchanges/#{id}/volume_chart", days: days, **options
185
+ end
186
+
187
+ # @deprecated Use {#exchange_volume} instead
156
188
  def get_exchange_volume(id:, days:)
157
- get "exchanges/#{id}/volume_chart", { days: days }
189
+ exchange_volume(id, days: days)
158
190
  end
159
191
  end
160
192
  end
@@ -9,7 +9,7 @@ module CoingeckoRuby
9
9
  # @return [Array<Hash>] each finance platform's name, category, url, facts (description), and centralized status.
10
10
  #
11
11
  # @example Get all finance platforms.
12
- # client.get_finance_platforms
12
+ # client.finance_platforms
13
13
  # @example Sample response object (truncated)
14
14
  # [
15
15
  # {
@@ -34,8 +34,13 @@ module CoingeckoRuby
34
34
  # "website_url"=>"https://cobo.com/"
35
35
  # }
36
36
  # ]
37
+ def finance_platforms(**options)
38
+ get 'finance_platforms', **options
39
+ end
40
+
41
+ # @deprecated Use {#finance_platforms} instead
37
42
  def get_finance_platforms(options: {})
38
- get 'finance_platforms', { options: options }
43
+ finance_platforms(**options)
39
44
  end
40
45
 
41
46
  # Fetches the list of finance products (e.g. Binance Savings, Nexo, Fulcrum) listed in CoinGecko.
@@ -48,7 +53,7 @@ module CoingeckoRuby
48
53
  # @return [Array<Hash>] each finance product's platform, identifier, supply and borrow rate percentage, and the product duration data.
49
54
  #
50
55
  # @example Get all finance products.
51
- # client.get_finance_products
56
+ # client.finance_products
52
57
  # @example Sample response object (truncated)
53
58
  # [
54
59
  # {"platform"=>"Binance Savings",
@@ -82,8 +87,13 @@ module CoingeckoRuby
82
87
  # "value_at"=>0,
83
88
  # "redeem_at"=>0}
84
89
  # ]
90
+ def finance_products(**options)
91
+ get 'finance_products', **options
92
+ end
93
+
94
+ # @deprecated Use {#finance_products} instead
85
95
  def get_finance_products(options: {})
86
- get 'finance_products', { options: options }
96
+ finance_products(**options)
87
97
  end
88
98
  end
89
99
  end
@@ -9,7 +9,7 @@ module CoingeckoRuby
9
9
  # @return [Array<Hash>] each index's id, name, market name, last done, and whether it's a multiasset composite index.
10
10
  #
11
11
  # @example Get all market indexes.
12
- # client.get_indexes
12
+ # client.indexes
13
13
  # @example Sample response object
14
14
  # [
15
15
  # {"name"=>"CoinFLEX (Futures) DFN",
@@ -28,8 +28,13 @@ module CoingeckoRuby
28
28
  # "last"=>nil,
29
29
  # "is_multi_asset_composite"=>false}
30
30
  # ]
31
+ def indexes(**options)
32
+ get 'indexes', **options
33
+ end
34
+
35
+ # @deprecated Use {#indexes} instead
31
36
  def get_indexes(options: {})
32
- get 'indexes', { options: options }
37
+ indexes(**options)
33
38
  end
34
39
 
35
40
  # Fetches the ids of market indexes listed in CoinGecko.
@@ -37,7 +42,7 @@ module CoingeckoRuby
37
42
  # @return [Array<Hash>] each index's id and name.
38
43
  #
39
44
  # @example Get all market index ids and names.
40
- # client.get_indexes_ids
45
+ # client.index_ids
41
46
  # @example Sample response object
42
47
  # [
43
48
  # {"id"=>"LINK", "name"=>"Bibox (Futures) LINK"},
@@ -45,19 +50,24 @@ module CoingeckoRuby
45
50
  # {"id"=>"XRP", "name"=>"Bibox (Futures) XRP"},
46
51
  # {"id"=>"ETH", "name"=>"Crypto.com (Futures) ETH"}
47
52
  # ]
48
- def get_indexes_ids
53
+ def index_ids
49
54
  get 'indexes/list'
50
55
  end
51
56
 
57
+ # @deprecated Use {#index_ids} instead
58
+ def get_indexes_ids
59
+ index_ids
60
+ end
61
+
52
62
  # Fetches the list of indexes based on the market and index given.
53
63
  #
54
64
  # @param market_id [String] filter results by the market id.
55
- # @param index_id [String] filter indexes from the given market by the index id.
65
+ # @param coin_id [String] filter indexes from the given market by the index id.
56
66
  #
57
67
  # @return [Array<Hash>] the index's name, market, last done, and whether it's a multiasset composite index.
58
68
  #
59
69
  # @example Get all BTC indexes in the CME Futures market.
60
- # client.get_indexes_by_market_and_index(market_id: 'cme_futures', index_id: 'btc')
70
+ # client.indexes_by_market_and_coin(market_id: 'cme_futures', coin_id: 'btc')
61
71
  # @example Sample response object
62
72
  # {
63
73
  # "name"=>"CME Bitcoin Futures BTC",
@@ -65,8 +75,13 @@ module CoingeckoRuby
65
75
  # "last"=>nil,
66
76
  # "is_multi_asset_composite"=>false
67
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
68
83
  def get_indexes_by_market_and_index(market_id:, index_id:, options: {})
69
- get "indexes/#{market_id}/#{index_id}", { options: options }
84
+ indexes_by_market_and_index(market_id, index_id, **options)
70
85
  end
71
86
  end
72
87
  end
@@ -6,7 +6,7 @@ module CoingeckoRuby
6
6
  # @return [Hash] global crypto data (e.g. market cap, total volume, active ICOs, etc.)
7
7
  #
8
8
  # @example Get global crypto data.
9
- # client.get_global_crypto_data
9
+ # client.global_crypto_data
10
10
  # @example Sample response object (truncated)
11
11
  # {
12
12
  # "data" => {
@@ -35,16 +35,21 @@ module CoingeckoRuby
35
35
  # "updated_at" => 1621344957
36
36
  # }
37
37
  # }
38
- def get_global_crypto_data
38
+ def global_crypto_data
39
39
  get 'global'
40
40
  end
41
41
 
42
+ # @deprecated Use {#global_crypto_data} instead
43
+ def get_global_crypto_data
44
+ global_crypto_data
45
+ end
46
+
42
47
  # Fetches global crypto data from CoinGecko.
43
48
  #
44
49
  # @return [Hash] global defi data.
45
50
  #
46
51
  # @example Get global defi data.
47
- # client.get_global_defi_data
52
+ # client.global_defi_data
48
53
  # @example Sample response object
49
54
  # {
50
55
  # "data" => {
@@ -59,16 +64,21 @@ module CoingeckoRuby
59
64
  # "top_coin_defi_dominance" => 14.449398175884316
60
65
  # }
61
66
  # }
62
- def get_global_defi_data
67
+ def global_defi_data
63
68
  get 'global/decentralized_finance_defi'
64
69
  end
65
70
 
71
+ # @deprecated Use {#global_defi_data} instead
72
+ def get_global_defi_data
73
+ global_defi_data
74
+ end
75
+
66
76
  # Fetches the top 7 coin searches from CoinGecko in the last 24 hours.
67
77
  #
68
78
  # @return [Hash] the ternding searches and its information.
69
79
  #
70
80
  # @example Get trending searches in the last 24 hours.
71
- # client.get_trending_searches
81
+ # client.trending_searches
72
82
  # @example Sample response object (truncated)
73
83
  # {
74
84
  # "coins" => [{
@@ -92,10 +102,15 @@ module CoingeckoRuby
92
102
  # ],
93
103
  # "exchanges" => []
94
104
  # }
95
- def get_trending_searches
105
+ def trending_searches
96
106
  get 'search/trending'
97
107
  end
98
108
 
109
+ # @deprecated Use {#trending_searches} instead
110
+ def get_trending_searches
111
+ trending_searches
112
+ end
113
+
99
114
  # Fetches coin and/or market status updates.
100
115
  #
101
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
@@ -106,7 +121,7 @@ module CoingeckoRuby
106
121
  # @return [Hash] the list of status updates and its information.
107
122
  #
108
123
  # @example Get a single status update.
109
- # client.get_status_updates(options: { per_page: 1 })
124
+ # client.status_updates(per_page: 1)
110
125
  # @example Sample response object
111
126
  # {
112
127
  # "status_updates" => [{
@@ -147,8 +162,12 @@ module CoingeckoRuby
147
162
  # }
148
163
  # }]
149
164
  # }
165
+ def status_updates(**options)
166
+ get 'status_updates', **options
167
+ end
168
+
150
169
  def get_status_updates(options: {})
151
- get 'status_updates', { options: options }
170
+ status_updates(**options)
152
171
  end
153
172
  end
154
173
  end
@@ -2,8 +2,8 @@ module CoingeckoRuby
2
2
  class Client
3
3
  module Prices
4
4
  # Fetches the current price for a coin in the given coin or currency.
5
- # @param id [String] the coin id to fetch.
6
- # @param currency [String] the currency to display the coin's price.
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
7
  # @option options [Boolean] :include_market_cap include market cap data.
8
8
  # @option options [Boolean] :include_24hr_vol include 24 hour volume data.
9
9
  # @option options [Boolean] :include_24hr_change include 24 hour price change data.
@@ -12,7 +12,7 @@ module CoingeckoRuby
12
12
  # @return [Hash] returns the given coin id and its current price.
13
13
  #
14
14
  # @example Fetch the current price in USD for Bitcoin.
15
- # client.get_price(id: 'bitcoin', currency: 'usd')
15
+ # client.price('bitcoin', currency: 'usd')
16
16
  # @example Sample response object
17
17
  # {
18
18
  # "bitcoin" => {
@@ -20,7 +20,7 @@ module CoingeckoRuby
20
20
  # }
21
21
  # }
22
22
  # @example Fetch the current price, market cap, 24 hour volume, 24 hour price change and last updated at for Bitcoin.
23
- # client.get_price(id: 'bitcoin', currency: 'usd', options: { include_market_cap: true, include_24hr_vol: true, include_24hr_change: true, include_last_updated_at: true })
23
+ # client.price('bitcoin', 'usd', include_market_cap: true, include_24hr_vol: true, include_24hr_change: true, include_last_updated_at: true)
24
24
  # @example Sample response object
25
25
  # {
26
26
  # "bitcoin" => {
@@ -31,18 +31,30 @@ module CoingeckoRuby
31
31
  # "last_updated_at" => 1621142197 # last updated at UNIX timestamp for the given coin
32
32
  # }
33
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
38
+ end
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
34
46
  def get_price(id:, currency: 'usd', options: {})
35
- get 'simple/price', { ids: id, vs_currencies: currency, options: options }
47
+ price(id, currency, **options)
36
48
  end
37
49
 
38
50
  # Fetches historical price data for a coin at a given date.
39
51
  # @param id [String] the coin id to fetch.
40
- # @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').
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.
41
53
  #
42
54
  # @return [Hash] returns the coin's historical price data on the given date.
43
55
  #
44
56
  # @example Fetch Bitcoin's price on 30th December, 2017.
45
- # client.get_historical_price_on_date(id: 'bitcoin', date: '30-12-2017')
57
+ # client.historical_price('bitcoin', date: '30-12-2017')
46
58
  # @example Sample response object (truncated)
47
59
  # {
48
60
  # "id": "bitcoin",
@@ -107,19 +119,26 @@ module CoingeckoRuby
107
119
  # "bing_matches": null
108
120
  # }
109
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
110
129
  def get_historical_price_on_date(id:, date:)
111
- get "coins/#{id}/history", { date: date }
130
+ historical_price(id, date: date)
112
131
  end
113
132
 
114
133
  # Fetches a coin's historical price data in 5 - 10 minutes ranges.
115
134
  # @note Minutely historical data is only available within the last 24 hours.
116
135
  # @param id [String] the coin id to fetch.
117
- # @param currency [String] the currency used to display minutely historical price.
136
+ # @param currency [String] the currency used to display minutely historical price. Defaults to 'USD'
118
137
  #
119
138
  # @return [Hash] returns the coin's minutely historical price data within the last 24 hours.
120
139
  #
121
140
  # @example Fetch Bitcoin's minutely historical price within the last 24 hours.
122
- # client.get_minutely_historical_prices(id: 'bitcoin')
141
+ # client.minutely_historical_price('bitcoin')
123
142
  # @example Sample response object (truncated)
124
143
  # {
125
144
  # "prices" => [
@@ -138,20 +157,25 @@ module CoingeckoRuby
138
157
  # [1621058047104, 57046967935.326035],
139
158
  # ]
140
159
  # }
160
+ def minutely_historical_price(id, currency: 'usd', **options)
161
+ get "coins/#{id}/market_chart", vs_currency: currency, days: 1, **options
162
+ end
163
+
164
+ # @deprecated Use {#minutely_historical_price} instead
141
165
  def get_minutely_historical_prices(id:, currency: 'usd')
142
- get "coins/#{id}/market_chart", { id: id, vs_currency: currency, days: 1 }
166
+ minutely_historical_price(id, currency: currency)
143
167
  end
144
168
 
145
169
  # Fetches a coin's historical price data in 1 hour ranges.
146
170
  # @note Hourly historical data is only available within the last 90 days.
147
171
  # @param id [String] the coin id to fetch.
148
- # @param days [Integer] the number of days to fetch hourly historical prices (min: 1 day, max: 90 days)
149
- # @param currency [String] the currency used to display hourly historical price.
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
150
174
  #
151
175
  # @return [Hash] returns the coin's hourly historical price data within the number of days given.
152
176
  #
153
- # @example Fetch Bitcoin's hourly historical price within the last 7 days.
154
- # client.get_hourly_historical_prices(id: 'bitcoin', days: 7)
177
+ # @example Fetch Bitcoin's hourly historical price in USD within the last 7 days.
178
+ # client.hourly_historical_price('bitcoin', days: 7)
155
179
  # @example Sample response object (truncated)
156
180
  # {
157
181
  # "prices" => [
@@ -168,21 +192,26 @@ module CoingeckoRuby
168
192
  # [1620547381049, 72064327648.28767],
169
193
  # ]
170
194
  # }
171
- def get_hourly_historical_prices(id:, days:, currency: 'usd')
172
- return get_daily_historical_prices(id: id, days: days) if days > 90
195
+ def hourly_historical_price(id, currency: 'usd', days: 7, **options)
196
+ return daily_historical_price(id, currrency: currency, days: days) if days > 90
173
197
 
174
- get "coins/#{id}/market_chart", { vs_currency: currency, days: days }
198
+ get "coins/#{id}/market_chart", vs_currency: currency, days: days, **options
199
+ end
200
+
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)
175
204
  end
176
205
 
177
206
  # Fetches a coin's historical price data in daily ranges.
178
207
  # @param id [String] the coin id to fetch.
179
- # @param days [Integer] the number of days to fetch daily historical prices.
180
- # @param currency [String] the currency used to display daily historical price.
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.
181
210
  #
182
211
  # @return [Hash] returns the coin's daily historical price data within the number of days given.
183
212
  #
184
213
  # @example Fetch Bitcoin's daily historical price within the last 14 days.
185
- # client.get_daily_historical_prices(id: 'bitcoin', days: 14)
214
+ # client.daily_historical_prices('bitcoin', days: 14)
186
215
  # @example Sample response object (truncated)
187
216
  # {
188
217
  # "prices" => [
@@ -199,30 +228,40 @@ module CoingeckoRuby
199
228
  # [1620172800000, 71296763919.13268],
200
229
  # ]
201
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
202
236
  def get_daily_historical_prices(id:, days:, currency: 'usd')
203
- get "coins/#{id}/market_chart", { vs_currency: currency, days: days, interval: 'daily' }
237
+ daily_historical_price(id, currency: currency, days: days)
204
238
  end
205
239
 
206
240
  # Fetches a coin's open, high, low, and close (OHLC) data within the number of days given.
207
241
  # @param id [String] the coin id to fetch.
208
- # @param days [Integer, String] the number of days to fetch daily historical prices. Valid values: 1/7/14/30/90/180/365/'max'
209
- # @param currency [String] the currency to display OHLC data.
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'.
210
244
  #
211
245
  # @return [Array<Array<String, Float>>] returns the coin's OHLC data within the number of days given.
212
246
  # If the number of days given is between 1-2 days, the OHLC data is returned in 30-minute intervals.
213
247
  # If the number of days given is between 3-30 days, the OHLC data is returned in 4-hour intervals.
214
248
  # If the number of days given is more than 30 days, the OHLC data is returned in 4-day intervals.
215
249
  #
216
- # @example Fetch Bitcoin's OHLC data in USD within the last 7 days.
217
- # client.get_ohlc(id: 'bitcoin', days: 7, currency: 'usd')
250
+ # @example Fetch Bitcoin's OHLC data within the last 7 days.
251
+ # client.ohlc('bitcoin', days: 7)
218
252
  # @example Sample response object (truncated)
219
253
  # [
220
254
  # [1620547200000, 58384.27, 58384.27, 58384.27, 58384.27], # [UNIX timestamp for OHLC data, open, high, low, close]
221
255
  # [1620561600000, 58022.03, 58214.96, 57943.18, 58048.35],
222
256
  # [1620576000000, 57956.7, 57956.7, 56636.68, 57302.22],
223
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
224
263
  def get_ohlc(id:, days:, currency: 'usd')
225
- get "coins/#{id}/ohlc", { vs_currency: currency, days: days }
264
+ ohlc(id, currency: currency, days: days)
226
265
  end
227
266
 
228
267
  # Fetches the list of currencies currently supported by CoinGecko's API.
@@ -247,12 +286,12 @@ module CoingeckoRuby
247
286
 
248
287
  # Fetches the exchange rate for a coin or currency in the given coin or currency.
249
288
  # @param from [String] the coin id or currency to be converted.
250
- # @param to [String] the coin id or currency to convert against.
289
+ # @param to [String] the coin id or currency to convert against. Defaults to 'USD'.
251
290
  #
252
291
  # @return [Hash] returns the coin's exchange rate against the given coin or currency.
253
292
  #
254
293
  # @example Fetch the exchange rate for BTC-USD.
255
- # client.get_exchange_rate(from: 'bitcoin', to: 'usd')
294
+ # client.exchange_rate(from: 'bitcoin', to: 'usd')
256
295
  # @example Sample response object
257
296
  # {
258
297
  # "bitcoin" => {
@@ -267,8 +306,13 @@ module CoingeckoRuby
267
306
  # "eth" => 12.71434 # current price in given currency
268
307
  # }
269
308
  # }
309
+ def exchange_rate(from:, to: 'usd')
310
+ price(from, currency: to)
311
+ end
312
+
313
+ # @deprecated Use {#exchange_rate} instead
270
314
  def get_exchange_rate(from:, to: 'usd')
271
- get_price(id: from, currency: to)
315
+ exchange_rate(from: from, to: to)
272
316
  end
273
317
  end
274
318
  end