coinmarketcap 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62cefa3f1ddfe4a8c142dcf9dbfd6337140fcb16
4
- data.tar.gz: 63f977f36f55db8cef16fa043bb88a77f0a0e1ba
3
+ metadata.gz: dc9d2054f652d321b6c6137ab4651e479d8e21e5
4
+ data.tar.gz: d8c4060feb6324a66569ec83d7afc96a3e5b7346
5
5
  SHA512:
6
- metadata.gz: 7638e027668a14a0ac3863f2b362db9827772999986630047f37237e36c14bab32c83edb52a03baddbf6c28096179c06682f8454eb74f53f283ee06718ae755d
7
- data.tar.gz: ada461209b89108fcf0558e93fb8f54c47aee4331add639827111621d2ff656adcf8f6463a15a5f237050fb88dce74ce8898ab13bcf85c3e38abff8c9c46f835
6
+ metadata.gz: f8dcc70708fc2209699da2c5ab2d731e895f27f107d9432e2b3b7561ccb995d7f6cdc36f9029cb24e6dd080188c316d4b7e92210b0ae7c846b13b8b943061912
7
+ data.tar.gz: e5587b209c3f50f96be7502aa6b2b243f1e794ea6f3029336e8670ba4831d6007ad6a320674622b9205d4b2bd95d8beea8daf000c87079b9de11928accf70185
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  # Coinmarketcap
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/coinmarketcap`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- TODO: Delete this and the text above, and describe your gem
5
+ A ruby wrapper for the [coinmarketcap.com API](https://coinmarketcap.com/api/).
8
6
 
9
7
  ## Installation
10
8
 
@@ -24,7 +22,236 @@ Or install it yourself as:
24
22
 
25
23
  ## Usage
26
24
 
27
- TODO: Write usage instructions here
25
+ ### Coins
26
+ To get information for multiple coins use the `coins` method.
27
+
28
+ **Parameters**
29
+
30
+ | Name | Type | Description |
31
+ | :------------- | :------------- | :------------- |
32
+ | `limit` | int | Return a maximum of `limit` results (default is nil which returns all results) |
33
+
34
+ **Examples**
35
+ ```ruby
36
+ Coinmarketcap.coins
37
+ #=> returns array of all available coins sorted by rank
38
+
39
+ Coinmarketcap.coins(limit = 20)
40
+ #=> returns array of only 20 coins sorted by rank
41
+ ```
42
+ **Sample Response**
43
+ ```json
44
+ {
45
+ "data": [
46
+ {
47
+ "id": 1,
48
+ "name": "Bitcoin",
49
+ "symbol": "BTC",
50
+ "website_slug": "bitcoin",
51
+ "rank": 1,
52
+ "circulating_supply": 17243837.0,
53
+ "total_supply": 17243837.0,
54
+ "max_supply": 21000000.0,
55
+ "quotes": {
56
+ "USD": {
57
+ "price": 7046.61259816,
58
+ "volume_24h": 4289789887.93929,
59
+ "market_cap": 121510639045.0,
60
+ "percent_change_1h": -0.09,
61
+ "percent_change_24h": 1.42,
62
+ "percent_change_7d": 4.74
63
+ }
64
+ },
65
+ "last_updated": 1535812825
66
+ },
67
+ {
68
+ "id": 1027,
69
+ "name": "Ethereum",
70
+ "symbol": "ETH",
71
+ "website_slug": "ethereum",
72
+ "rank": 2,
73
+ "circulating_supply": 101689192.0,
74
+ "total_supply": 101689192.0,
75
+ "max_supply": null,
76
+ "quotes": {
77
+ "USD": {
78
+ "price": 287.025145487,
79
+ "volume_24h": 1359873785.37404,
80
+ "market_cap": 29187355119.0,
81
+ "percent_change_1h": 0.5,
82
+ "percent_change_24h": 2.93,
83
+ "percent_change_7d": 2.34
84
+ }
85
+ },
86
+ "last_updated": 1535812836
87
+ }
88
+ ],
89
+ "metadata": {
90
+ "timestamp": 1535812339,
91
+ "num_cryptocurrencies": 1910,
92
+ "error": null
93
+ }
94
+ }
95
+ ```
96
+
97
+ ### Coin
98
+ To get information for a specific coin use the `coin` method.
99
+
100
+ **Parameters**
101
+
102
+ | Name | Type | Description |
103
+ | :------------- | :------------- | :------------- |
104
+ | `id` | integer | **required**. Use the ID returned from all coins api |
105
+ | `currency` | string | return *price*, *24h volume*, and *market cap* in terms of another currency. Valid values are "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", "RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR". (default is "USD") |
106
+
107
+ **Examples**
108
+ ```ruby
109
+ Coinmarketcap.coin(1)
110
+ #=> returns information about coin with '1' as its id.
111
+ # Price, 24h volume and market cap are in USD
112
+ ```
113
+ **Sample Response**
114
+ ```json
115
+ {
116
+ "data": {
117
+ "id": 1,
118
+ "name": "Bitcoin",
119
+ "symbol": "BTC",
120
+ "website_slug": "bitcoin",
121
+ "rank": 1,
122
+ "circulating_supply": 17243837.0,
123
+ "total_supply": 17243837.0,
124
+ "max_supply": 21000000.0,
125
+ "quotes": {
126
+ "USD": {
127
+ "price": 7056.36503616,
128
+ "volume_24h": 4310812630.28682,
129
+ "market_cap": 121678808496.0,
130
+ "percent_change_1h": 0.04,
131
+ "percent_change_24h": 1.54,
132
+ "percent_change_7d": 4.88
133
+ }
134
+ },
135
+ "last_updated": 1535813063
136
+ },
137
+ "metadata": {
138
+ "timestamp": 1535812601,
139
+ "error": null
140
+ }
141
+ }
142
+ ```
143
+
144
+ ```ruby
145
+ Coinmarketcap.coin(1, 'EUR')
146
+ #=> returns information about coin with '1' as its id.
147
+ # Price, 24h volume and market cap are in EUR
148
+ ```
149
+ **Sample Response**
150
+ ```json
151
+ {
152
+ "data": {
153
+ "id": 1,
154
+ "name": "Bitcoin",
155
+ "symbol": "BTC",
156
+ "website_slug": "bitcoin",
157
+ "rank": 1,
158
+ "circulating_supply": 17243837.0,
159
+ "total_supply": 17243837.0,
160
+ "max_supply": 21000000.0,
161
+ "quotes": {
162
+ "USD": {
163
+ "price": 7057.5191433,
164
+ "volume_24h": 4315628117.49539,
165
+ "market_cap": 121698709731.0,
166
+ "percent_change_1h": 0.06,
167
+ "percent_change_24h": 1.56,
168
+ "percent_change_7d": 4.9
169
+ },
170
+ "EUR": {
171
+ "price": 6077.93548621,
172
+ "volume_24h": 3716618934.7870364,
173
+ "market_cap": 104806928821.0,
174
+ "percent_change_1h": 0.06,
175
+ "percent_change_24h": 1.56,
176
+ "percent_change_7d": 4.9
177
+ }
178
+ },
179
+ "last_updated": 1535813303
180
+ },
181
+ "metadata": {
182
+ "timestamp": 1535812810,
183
+ "error": null
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### Global
189
+ To get global (general) data, use the `global` method.
190
+
191
+ **Parameters**
192
+
193
+ | Name | Type | Description |
194
+ | :------------- | :------------- | :------------- |
195
+ | `currency` | string | return *price*, *24h volume*, and *market cap* in terms of another currency. Valid values are "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", "RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR". (default is "USD") |
196
+
197
+ **Examples**
198
+ ```ruby
199
+ Coinmarketcap.global
200
+ #=> returns global data
201
+ # Price, 24h volume and market cap are in USD
202
+ ```
203
+ **Sample Response**
204
+ ```json
205
+ {
206
+ "data": {
207
+ "active_cryptocurrencies": 1910,
208
+ "active_markets": 13693,
209
+ "bitcoin_percentage_of_market_cap": 52.38,
210
+ "quotes": {
211
+ "USD": {
212
+ "total_market_cap": 232365707542.0,
213
+ "total_volume_24h": 12929935868.0
214
+ }
215
+ },
216
+ "last_updated": 1535813364
217
+ },
218
+ "metadata": {
219
+ "timestamp": 1535812887,
220
+ "error": null
221
+ }
222
+ }
223
+ ```
224
+
225
+ ```ruby
226
+ Coinmarketcap.global('EUR')
227
+ #=> returns global data
228
+ # Price, 24h volume and market cap are in EUR
229
+ ```
230
+ **Sample Response**
231
+ ```json
232
+ {
233
+ "data": {
234
+ "active_cryptocurrencies": 1910,
235
+ "active_markets": 13693,
236
+ "bitcoin_percentage_of_market_cap": 52.38,
237
+ "quotes": {
238
+ "USD": {
239
+ "total_market_cap": 232328115855.0,
240
+ "total_volume_24h": 12928585948.0
241
+ },
242
+ "EUR": {
243
+ "total_market_cap": 200080973374.0,
244
+ "total_volume_24h": 11134098218.0
245
+ }
246
+ },
247
+ "last_updated": 1535813303
248
+ },
249
+ "metadata": {
250
+ "timestamp": 1535812850,
251
+ "error": null
252
+ }
253
+ }
254
+ ```
28
255
 
29
256
  ## Development
30
257
 
@@ -34,7 +261,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
261
 
35
262
  ## Contributing
36
263
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/coinmarketcap. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
264
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ankitsamarthya/coinmarketcap. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
265
 
39
266
  ## License
40
267
 
@@ -42,4 +269,4 @@ The gem is available as open source under the terms of the [MIT License](http://
42
269
 
43
270
  ## Code of Conduct
44
271
 
45
- Everyone interacting in the Coinmarketcap project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/coinmarketcap/blob/master/CODE_OF_CONDUCT.md).
272
+ Everyone interacting in the Coinmarketcap project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ankitsamarthya/coinmarketcap/blob/master/CODE_OF_CONDUCT.md).
@@ -4,31 +4,26 @@ require 'httparty'
4
4
  require 'nokogiri'
5
5
 
6
6
  module Coinmarketcap
7
-
8
7
  def self.coins(limit = nil)
9
8
  if limit.nil?
10
- HTTParty.get('https://api.coinmarketcap.com/v1/ticker/')
9
+ HTTParty.get('https://api.coinmarketcap.com/v2/ticker/?structure=array')
11
10
  else
12
- HTTParty.get("https://api.coinmarketcap.com/v1/ticker/?limit=#{limit}")
11
+ HTTParty.get("https://api.coinmarketcap.com/v2/ticker/?limit=#{limit}&structure=array")
13
12
  end
14
13
  end
15
14
 
16
- def self.coin(id)
17
- HTTParty.get("https://api.coinmarketcap.com/v1/ticker/#{id}/")
15
+ def self.coin(id, currency = 'USD')
16
+ HTTParty.get("https://api.coinmarketcap.com/v2/ticker/#{id}/?convert=#{currency}")
18
17
  end
19
18
 
20
19
  def self.global(currency = 'USD')
21
- HTTParty.get("https://api.coinmarketcap.com/v1/global/?convert=#{currency}")
20
+ HTTParty.get("https://api.coinmarketcap.com/v2/global/?convert=#{currency}")
22
21
  end
23
22
 
24
- def self.get_historical_price(id, start_date, end_date) #20170908
23
+ def self.get_historical_price(id, start_date, end_date) # 20170908
25
24
  prices = []
26
25
  doc = Nokogiri::HTML(open("https://coinmarketcap.com/currencies/#{id}/historical-data/?start=#{start_date}&end=#{end_date}"))
27
26
  rows = doc.css('tr')
28
- if rows.count == 31
29
- doc = Nokogiri::HTML(open("https://coinmarketcap.com/assets/#{id}/historical-data/?start=#{start_date}&end=#{end_date}"))
30
- rows = doc.css('tr')
31
- end
32
27
  rows.shift
33
28
  rows.each do |row|
34
29
  begin
@@ -40,14 +35,13 @@ module Coinmarketcap
40
35
  price_bundle[:high] = each_row[2].text.to_f
41
36
  price_bundle[:low] = each_row[3].text.to_f
42
37
  price_bundle[:close] = each_row[4].text.to_f
43
- price_bundle[:avg] = ( price_bundle[:high] + price_bundle[:low] ) / 2.0
38
+ price_bundle[:avg] = (price_bundle[:high] + price_bundle[:low]) / 2.0
44
39
  prices << price_bundle
45
40
  end
46
- rescue => error
41
+ rescue
47
42
  next
48
43
  end
49
44
  end
50
45
  prices
51
46
  end
52
-
53
47
  end
@@ -1,3 +1,3 @@
1
1
  module Coinmarketcap
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinmarketcap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankit Samarthya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.5.1
196
+ rubygems_version: 2.6.14
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Coinmarketcap.com API ruby wrapper