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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +27 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -10
- data/fixtures/vcr_cassettes/test_that_it_gets_a_specific_exchange_ticker_from_an_exchange.yml +70 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_eth_exchange_rate.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_btc_to_usd_exchange_rate.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_daily_historical_prices_for_one_coin.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_historical_price_for_one_coin_at_a_previous_date.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_hourly_historical_prices_for_one_coin.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_indexes_by_market_id_and_coin_id.yml +66 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_last_7_days_exchange_volume_from_an_exchange.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin.yml +98 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_a_coin_in_myr.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_market_data_for_multiple_coins_in_eth.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_minutely_historical_prices_for_one_coin.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_30_days_in_myr.yml +47 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_ohlc_data_for_one_coin_in_the_last_7_days.yml +47 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin.yml +49 -0
- data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin_in_a_different_currency.yml +49 -0
- data/lib/coingecko_ruby/client.rb +6 -0
- data/lib/coingecko_ruby/client/categories.rb +21 -6
- data/lib/coingecko_ruby/client/coins.rb +28 -15
- data/lib/coingecko_ruby/client/derivatives.rb +30 -9
- data/lib/coingecko_ruby/client/events.rb +21 -6
- data/lib/coingecko_ruby/client/exchanges.rb +45 -13
- data/lib/coingecko_ruby/client/finance.rb +14 -4
- data/lib/coingecko_ruby/client/indexes.rb +22 -7
- data/lib/coingecko_ruby/client/infos.rb +27 -8
- data/lib/coingecko_ruby/client/prices.rb +74 -30
- data/lib/coingecko_ruby/connection.rb +5 -9
- data/lib/coingecko_ruby/version.rb +1 -1
- metadata +4 -2
@@ -70,4 +70,53 @@ http_interactions:
|
|
70
70
|
encoding: ASCII-8BIT
|
71
71
|
string: '{"bitcoin":{"usd":49253}}'
|
72
72
|
recorded_at: Sat, 15 May 2021 14:10:16 GMT
|
73
|
+
- request:
|
74
|
+
method: get
|
75
|
+
uri: https://api.coingecko.com/api/v3/simple/price
|
76
|
+
body:
|
77
|
+
encoding: US-ASCII
|
78
|
+
string: ''
|
79
|
+
headers:
|
80
|
+
Accept-Encoding:
|
81
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
82
|
+
Accept:
|
83
|
+
- "*/*"
|
84
|
+
User-Agent:
|
85
|
+
- Ruby
|
86
|
+
response:
|
87
|
+
status:
|
88
|
+
code: 422
|
89
|
+
message: Unprocessable Entity
|
90
|
+
headers:
|
91
|
+
Date:
|
92
|
+
- Mon, 19 Jul 2021 03:15:54 GMT
|
93
|
+
Content-Type:
|
94
|
+
- application/json; charset=utf-8
|
95
|
+
Transfer-Encoding:
|
96
|
+
- chunked
|
97
|
+
Connection:
|
98
|
+
- keep-alive
|
99
|
+
Vary:
|
100
|
+
- Accept-Encoding, Origin
|
101
|
+
Cache-Control:
|
102
|
+
- no-cache
|
103
|
+
X-Request-Id:
|
104
|
+
- 1fd0e6d0-8a67-4c70-9d7f-4b3b810e8667
|
105
|
+
X-Runtime:
|
106
|
+
- '0.002829'
|
107
|
+
Cf-Cache-Status:
|
108
|
+
- MISS
|
109
|
+
Expect-Ct:
|
110
|
+
- max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
|
111
|
+
Server:
|
112
|
+
- cloudflare
|
113
|
+
Cf-Ray:
|
114
|
+
- 6710c9b49ddc2374-HKG
|
115
|
+
Alt-Svc:
|
116
|
+
- h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443";
|
117
|
+
ma=86400
|
118
|
+
body:
|
119
|
+
encoding: ASCII-8BIT
|
120
|
+
string: '{"error":"Missing parameter ids"}'
|
121
|
+
recorded_at: Mon, 19 Jul 2021 03:15:54 GMT
|
73
122
|
recorded_with: VCR 6.0.0
|
data/fixtures/vcr_cassettes/test_that_it_gets_price_for_one_coin_in_a_different_currency.yml
CHANGED
@@ -68,4 +68,53 @@ http_interactions:
|
|
68
68
|
encoding: ASCII-8BIT
|
69
69
|
string: '{"bitcoin":{"myr":203620}}'
|
70
70
|
recorded_at: Sat, 15 May 2021 14:10:15 GMT
|
71
|
+
- request:
|
72
|
+
method: get
|
73
|
+
uri: https://api.coingecko.com/api/v3/simple/price
|
74
|
+
body:
|
75
|
+
encoding: US-ASCII
|
76
|
+
string: ''
|
77
|
+
headers:
|
78
|
+
Accept-Encoding:
|
79
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
80
|
+
Accept:
|
81
|
+
- "*/*"
|
82
|
+
User-Agent:
|
83
|
+
- Ruby
|
84
|
+
response:
|
85
|
+
status:
|
86
|
+
code: 422
|
87
|
+
message: Unprocessable Entity
|
88
|
+
headers:
|
89
|
+
Date:
|
90
|
+
- Mon, 19 Jul 2021 03:15:55 GMT
|
91
|
+
Content-Type:
|
92
|
+
- application/json; charset=utf-8
|
93
|
+
Transfer-Encoding:
|
94
|
+
- chunked
|
95
|
+
Connection:
|
96
|
+
- keep-alive
|
97
|
+
Vary:
|
98
|
+
- Accept-Encoding, Origin
|
99
|
+
Cache-Control:
|
100
|
+
- no-cache
|
101
|
+
X-Request-Id:
|
102
|
+
- 623b2a81-35ef-4085-a08c-73554740918d
|
103
|
+
X-Runtime:
|
104
|
+
- '0.002243'
|
105
|
+
Cf-Cache-Status:
|
106
|
+
- MISS
|
107
|
+
Expect-Ct:
|
108
|
+
- max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
|
109
|
+
Server:
|
110
|
+
- cloudflare
|
111
|
+
Cf-Ray:
|
112
|
+
- 6710c9bdf91d3d0c-HKG
|
113
|
+
Alt-Svc:
|
114
|
+
- h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443";
|
115
|
+
ma=86400
|
116
|
+
body:
|
117
|
+
encoding: ASCII-8BIT
|
118
|
+
string: '{"error":"Missing parameter ids"}'
|
119
|
+
recorded_at: Mon, 19 Jul 2021 03:15:55 GMT
|
71
120
|
recorded_with: VCR 6.0.0
|
@@ -6,7 +6,7 @@ module CoingeckoRuby
|
|
6
6
|
# @return [Array<Hash>] each category's id and name
|
7
7
|
#
|
8
8
|
# @example Get all coin categories.
|
9
|
-
# client.
|
9
|
+
# client.categories
|
10
10
|
# @example Sample response object
|
11
11
|
# [{
|
12
12
|
# "category_id" => "recently_added",
|
@@ -15,16 +15,21 @@ module CoingeckoRuby
|
|
15
15
|
# "category_id" => "aave-tokens",
|
16
16
|
# "name" => "Aave Tokens"
|
17
17
|
# }]
|
18
|
-
def
|
18
|
+
def categories
|
19
19
|
get 'coins/categories/list'
|
20
20
|
end
|
21
21
|
|
22
|
+
# @deprecated Use {#categories} instead
|
23
|
+
def get_categories
|
24
|
+
categories
|
25
|
+
end
|
26
|
+
|
22
27
|
# Fetches the list of coin categories with its respective market data.
|
23
28
|
#
|
24
29
|
# @return [Array<Hash>] each category's id, name, and market data
|
25
30
|
#
|
26
31
|
# @example Get all coin categories with market data.
|
27
|
-
# client.
|
32
|
+
# client.categories_with_market_data
|
28
33
|
# @example Sample response object
|
29
34
|
# [
|
30
35
|
# {
|
@@ -44,16 +49,21 @@ module CoingeckoRuby
|
|
44
49
|
# "updated_at" => "2021-05-16T08:20:20.877Z"
|
45
50
|
# }
|
46
51
|
# ]
|
47
|
-
def
|
52
|
+
def categories_with_market_data
|
48
53
|
get 'coins/categories'
|
49
54
|
end
|
50
55
|
|
56
|
+
# @deprecated Use {#categories_with_market_data} instead
|
57
|
+
def get_categories_with_market_data
|
58
|
+
categories_with_market_data
|
59
|
+
end
|
60
|
+
|
51
61
|
# Fetches the list of asset platforms (e.g. Ethereum, OpenLedger, Counterpart) listed in CoinGecko.
|
52
62
|
#
|
53
63
|
# @return [Array<Hash>] each asset platform's id, name, short name, and chain identifier
|
54
64
|
#
|
55
65
|
# @example Get all asset platforms.
|
56
|
-
# client.
|
66
|
+
# client.asset_platforms
|
57
67
|
# @example Sample response object
|
58
68
|
# [
|
59
69
|
# {"id"=>"factom", "chain_identifier"=>nil, "name"=>"Factom", "shortname"=>""},
|
@@ -62,9 +72,14 @@ module CoingeckoRuby
|
|
62
72
|
# "name"=>"OpenLedger",
|
63
73
|
# "shortname"=>""}
|
64
74
|
# ]
|
65
|
-
def
|
75
|
+
def asset_platforms
|
66
76
|
get 'asset_platforms'
|
67
77
|
end
|
78
|
+
|
79
|
+
# @deprecated Use {#asset_platforms} instead
|
80
|
+
def get_asset_platforms
|
81
|
+
asset_platforms
|
82
|
+
end
|
68
83
|
end
|
69
84
|
end
|
70
85
|
end
|
@@ -3,7 +3,7 @@ module CoingeckoRuby
|
|
3
3
|
module Coins
|
4
4
|
# Fetches the id, name, and symbol of every coin supported by CoinGecko's API.
|
5
5
|
#
|
6
|
-
# @
|
6
|
+
# @option options include_platform [Boolean] displays the coin's platform contract address (e.g. 0x... for ETH-based tokens)
|
7
7
|
#
|
8
8
|
# @return [Array<Hash>] returns an array of hashes for every supported coin's id, name, symbol, and platform contract address (optional).
|
9
9
|
#
|
@@ -21,8 +21,8 @@ module CoingeckoRuby
|
|
21
21
|
# "name" => "0.5X Long Algorand Token"
|
22
22
|
# }, {
|
23
23
|
# ]
|
24
|
-
def coins_list(
|
25
|
-
get 'coins/list',
|
24
|
+
def coins_list(**options)
|
25
|
+
get 'coins/list', **options
|
26
26
|
end
|
27
27
|
|
28
28
|
# Fetches detailed current data for a coin.
|
@@ -36,16 +36,21 @@ module CoingeckoRuby
|
|
36
36
|
# @return [Hash] returns comprehensive current data for the given coin.
|
37
37
|
#
|
38
38
|
# @example Fetch Bitcoin's current data.
|
39
|
-
# client.
|
39
|
+
# client.coin('bitcoin')
|
40
|
+
def coin(id, **options)
|
41
|
+
get "coins/#{id}", **options
|
42
|
+
end
|
43
|
+
|
44
|
+
# @deprecated Use {#coin} instead
|
40
45
|
def get_coin_data(id:, options: {})
|
41
|
-
|
46
|
+
coin(id, **options)
|
42
47
|
end
|
43
48
|
|
44
49
|
# Fetches the list of tickers (e.g: BTC-USD) for a coin
|
45
50
|
#
|
46
51
|
# @param id [String] the coin id to fetch.
|
47
|
-
# @option options [String] :
|
48
|
-
# @option options [
|
52
|
+
# @option options [String] :exchange_ids filter ticker results from the given exchange ids (e.g. 'binance, bitfinex').
|
53
|
+
# @option options [Boolean] :include_exchange_logo flag to show the exchange's logo.
|
49
54
|
# @option options [Integer] :page sets the page for results.
|
50
55
|
# @option options [String] :order ('trust_score_desc') sets the sort order for results. Valid values: trust_score_desc', 'trust_score_asc', 'volume_desc.
|
51
56
|
# @option options [Boolean] :depth (false) displays orderbook depth (2%).
|
@@ -53,7 +58,7 @@ module CoingeckoRuby
|
|
53
58
|
# @return [Hash] returns the list of tickers for the given coin.
|
54
59
|
#
|
55
60
|
# @example Fetch Bitcoin's tickers.
|
56
|
-
# client.
|
61
|
+
# client.tickers('bitcoin')
|
57
62
|
# @example Sample response object (truncated)
|
58
63
|
# {
|
59
64
|
# "name" => "Bitcoin",
|
@@ -87,7 +92,7 @@ module CoingeckoRuby
|
|
87
92
|
# }],
|
88
93
|
# }
|
89
94
|
# @example Fetch Bitcoin's tickers from Binance with 2% orderbook depth data.
|
90
|
-
# client.
|
95
|
+
# client.tickers('bitcoin', exchange_id: 'binance', depth: true)
|
91
96
|
# @example Sample response object (truncated)
|
92
97
|
# {
|
93
98
|
# "name" => "Bitcoin",
|
@@ -122,14 +127,19 @@ module CoingeckoRuby
|
|
122
127
|
# "target_coin_id" => "tether"
|
123
128
|
# }],
|
124
129
|
# }
|
130
|
+
def tickers(id, **options)
|
131
|
+
get "coins/#{id}/tickers", **options
|
132
|
+
end
|
133
|
+
|
134
|
+
# @deprecated Use {#tickers} instead
|
125
135
|
def get_tickers(id:, options: {})
|
126
|
-
|
136
|
+
tickers(id, **options)
|
127
137
|
end
|
128
138
|
|
129
139
|
# Fetches market data for a coin or a list of coins.
|
130
140
|
#
|
131
141
|
# @param ids [String] the coin id or ids to fetch.
|
132
|
-
# @
|
142
|
+
# @option options [String] :vs_currency the currency to display market price data.
|
133
143
|
# @option options [String] :category filter results by the given coin category.
|
134
144
|
# @option options [String] :order ('market_cap_desc') sets the sort order for results. Valid values: market_cap_desc, gecko_desc, gecko_asc, market_cap_asc, market_cap_desc, volume_asc, volume_desc, id_asc, id_desc.
|
135
145
|
# @option options [Integer] :per_page (100) sets the number of results to return per page.
|
@@ -140,7 +150,7 @@ module CoingeckoRuby
|
|
140
150
|
# @return [Array<Hash>] returns market data for the given coin or coins.
|
141
151
|
#
|
142
152
|
# @example Fetch market data for Bitcoin and Ethereum in USD.
|
143
|
-
# client.
|
153
|
+
# client.markets('bitcoin, ethereum', vs_currency: 'gbp')
|
144
154
|
# @example Sample response object
|
145
155
|
# [{
|
146
156
|
# "id" => "bitcoin",
|
@@ -205,10 +215,13 @@ module CoingeckoRuby
|
|
205
215
|
# "last_updated" => "2021-05-16T07:06:00.946Z"
|
206
216
|
# }
|
207
217
|
# ]
|
208
|
-
|
209
|
-
|
218
|
+
def markets(ids, **options)
|
219
|
+
get 'coins/markets', ids: ids, **options
|
220
|
+
end
|
221
|
+
|
222
|
+
# @deprecated Use {#markets} instead
|
210
223
|
def get_markets(ids:, currency: 'usd', options: {})
|
211
|
-
|
224
|
+
markets(ids, vs_currency: currency, **options)
|
212
225
|
end
|
213
226
|
end
|
214
227
|
end
|
@@ -8,7 +8,7 @@ module CoingeckoRuby
|
|
8
8
|
# @return [Array<Hash>] each derivative product's information.
|
9
9
|
#
|
10
10
|
# @example Get all unexpired derivatives.
|
11
|
-
# client.
|
11
|
+
# client.derivatives(include_tickers: 'unexpired')
|
12
12
|
# @example Sample response object (truncated)
|
13
13
|
# [
|
14
14
|
# {
|
@@ -44,8 +44,13 @@ module CoingeckoRuby
|
|
44
44
|
# "expired_at" => nil
|
45
45
|
# },
|
46
46
|
# ]
|
47
|
+
def derivatives(**options)
|
48
|
+
get 'derivatives', **options
|
49
|
+
end
|
50
|
+
|
51
|
+
# @deprecated Use {#derivatives} instead
|
47
52
|
def get_derivatives(options: {})
|
48
|
-
|
53
|
+
derivatives(**options)
|
49
54
|
end
|
50
55
|
|
51
56
|
# Fetches the list of derivative exchanges listed in CoinGecko.
|
@@ -57,7 +62,7 @@ module CoingeckoRuby
|
|
57
62
|
# @return [Array<Hash>] each derivative exchange's information.
|
58
63
|
#
|
59
64
|
# @example Get one derivative exchange.
|
60
|
-
# client.
|
65
|
+
# client.derivative_exchanges(per_page: 1)
|
61
66
|
# @example Sample response object
|
62
67
|
# [{
|
63
68
|
# "name" => "Binance (Futures)",
|
@@ -73,19 +78,25 @@ module CoingeckoRuby
|
|
73
78
|
# "description" => "",
|
74
79
|
# "url" => "https://www.binance.com/"
|
75
80
|
# }]
|
81
|
+
def derivative_exchanges(**options)
|
82
|
+
get 'derivatives/exchanges', **options
|
83
|
+
end
|
84
|
+
|
85
|
+
# @deprecated Use {#derivative_exchanges} instead
|
76
86
|
def get_derivative_exchanges(options: {})
|
77
|
-
|
87
|
+
derivative_exchanges(**options)
|
78
88
|
end
|
79
89
|
|
80
90
|
# Fetches data for a specific derivative exchange.
|
81
91
|
#
|
82
|
-
# @
|
92
|
+
# @param id [String] the id of the derivative exchange.
|
93
|
+
#
|
83
94
|
# @option options [String] :include_tickers determines whether to display all tickers or only show unexpired tickers. Does not return any ticker data if left blank. Valid values: all, unexpired
|
84
95
|
#
|
85
96
|
# @return [Hash] the derivative exchange's information.
|
86
97
|
#
|
87
98
|
# @example Get data for the Binance Futures derivative exchange.
|
88
|
-
# client.
|
99
|
+
# client.derivative_exchange('binance_futures')
|
89
100
|
# @example Sample response object
|
90
101
|
# {
|
91
102
|
# "name" => "Binance (Futures)",
|
@@ -100,8 +111,13 @@ module CoingeckoRuby
|
|
100
111
|
# "description" => "",
|
101
112
|
# "url" => "https://www.binance.com/"
|
102
113
|
# }
|
114
|
+
def derivative_exchange(id, **options)
|
115
|
+
get "derivatives/exchanges/#{id}", **options
|
116
|
+
end
|
117
|
+
|
118
|
+
# @deprecated Use {#derivative_exchange} instead
|
103
119
|
def get_derivative_exchange(id:, options: {})
|
104
|
-
|
120
|
+
derivative_exchange(id, **options)
|
105
121
|
end
|
106
122
|
|
107
123
|
# Fetches the list ids and names of derivative exchanges listed in CoinGecko.
|
@@ -109,7 +125,7 @@ module CoingeckoRuby
|
|
109
125
|
# @return [Array<Hash>] each derivative exchange's id and name.
|
110
126
|
#
|
111
127
|
# @example Get all unexpired derivatives.
|
112
|
-
# client.
|
128
|
+
# client.derivative_exchanges_ids_and_names
|
113
129
|
# @example Sample response object (truncated)
|
114
130
|
# [
|
115
131
|
# {
|
@@ -125,9 +141,14 @@ module CoingeckoRuby
|
|
125
141
|
# "name" => "FTX (Derivatives)"
|
126
142
|
# }
|
127
143
|
# ]
|
128
|
-
def
|
144
|
+
def derivative_exchanges_ids_and_names
|
129
145
|
get 'derivatives/exchanges/list'
|
130
146
|
end
|
147
|
+
|
148
|
+
# @deprecated Use {#derivative_exchanges_ids_and_names} instead
|
149
|
+
def get_derivative_exchanges_ids_and_names
|
150
|
+
derivative_exchanges_ids_and_names
|
151
|
+
end
|
131
152
|
end
|
132
153
|
end
|
133
154
|
end
|
@@ -14,9 +14,14 @@ module CoingeckoRuby
|
|
14
14
|
# @return [Array<Hash>] each finance platform's name, category, url, facts (description), and centralized status.
|
15
15
|
#
|
16
16
|
# @example Get all upcoming events.
|
17
|
-
# client.
|
17
|
+
# client.events(upcoming_events_only: true)
|
18
|
+
def events(**options)
|
19
|
+
get 'events', **options
|
20
|
+
end
|
21
|
+
|
22
|
+
# @deprecated Use {#events} instead
|
18
23
|
def get_events(options: {})
|
19
|
-
|
24
|
+
events(**options)
|
20
25
|
end
|
21
26
|
|
22
27
|
# Fetches the valid list of countries to fetch events from.
|
@@ -24,7 +29,7 @@ module CoingeckoRuby
|
|
24
29
|
# @return [Hash] each country's name and code and the total country count.
|
25
30
|
#
|
26
31
|
# @example Get all event countries.
|
27
|
-
# client.
|
32
|
+
# client.event_countries
|
28
33
|
# @example Sample response object (truncated)
|
29
34
|
# {
|
30
35
|
# "data" => [{
|
@@ -46,24 +51,34 @@ module CoingeckoRuby
|
|
46
51
|
# ],
|
47
52
|
# "count" => 4
|
48
53
|
# }
|
49
|
-
def
|
54
|
+
def event_countries
|
50
55
|
get 'events/countries'
|
51
56
|
end
|
52
57
|
|
58
|
+
# @deprecated Use {#event_countries} instead
|
59
|
+
def get_event_countries
|
60
|
+
event_countries
|
61
|
+
end
|
62
|
+
|
53
63
|
# Fetches the valid list of events to fetch.
|
54
64
|
#
|
55
65
|
# @return [Array<Hash>] the list of event types and total event types count.
|
56
66
|
#
|
57
67
|
# @example Get all event types.
|
58
|
-
# client.
|
68
|
+
# client.event_types
|
59
69
|
# @example Sample response object
|
60
70
|
# {
|
61
71
|
# "data" => ["Event", "Conference", "Meetup"],
|
62
72
|
# "count" => 3
|
63
73
|
# }
|
64
|
-
def
|
74
|
+
def event_types
|
65
75
|
get 'events/types'
|
66
76
|
end
|
77
|
+
|
78
|
+
# @deprecated Use {#event_types} instead
|
79
|
+
def get_event_types
|
80
|
+
event_types
|
81
|
+
end
|
67
82
|
end
|
68
83
|
end
|
69
84
|
end
|