coinmarketcap_free 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,303 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "coinmarketcap_free/coin"
4
- require_relative "coinmarketcap_free/cryptocurrencies"
5
- require_relative "coinmarketcap_free/base"
6
- require_relative "coinmarketcap_free/version"
7
-
8
- module CoinmarketcapFree
9
- class << self
10
- @@cryptocurrencies = Cryptocurrencies.new
11
- @@coin = Coin.new
12
-
13
- # Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
14
- #
15
- # history = CoinmarketcapFree.coins(1, '1D')
16
- #
17
- # Result json:
18
- #
19
- # {
20
- # "data": {
21
- # "points": {
22
- # "1673192010": {
23
- # "v": [
24
- # 16953.771282696678,
25
- # 7609543976.45,
26
- # 326457581376.786557398500,
27
- # 1,
28
- # 19255750.00000000000000000000
29
- # ],
30
- # "c": [
31
- # 16953.771282696678,
32
- # 7609543976.45,
33
- # 326457581376.786557398500
34
- # ]
35
- # },
36
- # ...
37
- # }
38
- # },
39
- # "status": {
40
- # "timestamp": "2023-01-08T15:33:30.271Z",
41
- # "error_code": "0",
42
- # "error_message": "SUCCESS",
43
- # "elapsed": "2",
44
- # "credit_count": 0
45
- # }
46
- # }
47
- #
48
- # 'data' - Results of your query returned as an object map.
49
- # 'points' - Price range history
50
- # 'status' - Standardized status object for API calls.
51
- #
52
- # @param id [Integer] Cryptocurrency identifier from coinmarketcap. For example, Bitcoin has the number 1
53
- # @param range_time [String] Range time. For example, '1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom range '1668981600~1671659999'
54
- # @return [String, nil]
55
- def coin_history(id, range_time)
56
- @@coin.id = id
57
- @@coin.range_time = range_time
58
- @@coin.update ? @@coin.get_data : nil
59
- end
60
-
61
- # Returns an interval of historic for the day
62
- #
63
- # @param [Integer] id Cryptocurrency identifier
64
- def coin_history_day(id)
65
- coin_history(id, '1D')
66
- end
67
-
68
- # Returns an interval of historic for the seven days
69
- #
70
- # @param [Integer] id Cryptocurrency identifier
71
- def coin_history_seven_days(id)
72
- coin_history(id, '7D')
73
- end
74
-
75
- # Returns an interval of historic for the one month
76
- #
77
- # @param [Integer] id Cryptocurrency identifier
78
- def coin_history_one_month(id)
79
- coin_history(id, '1M')
80
- end
81
-
82
- # Returns an interval of historic for the three months
83
- #
84
- # @param [Integer] id Cryptocurrency identifier
85
- def coin_history_three_months(id)
86
- coin_history(id, '3M')
87
- end
88
-
89
- # Returns an interval of historic for the one year
90
- #
91
- # @param [Integer] id Cryptocurrency identifier
92
- def coin_history_one_year(id)
93
- coin_history(id, '1Y')
94
- end
95
-
96
- # Returns an interval of historic for the current year
97
- #
98
- # @param [Integer] id Cryptocurrency identifier
99
- def coin_history_current_year(id)
100
- coin_history(id, 'YTD')
101
- end
102
-
103
- # Returns an interval of historic for the current year
104
- #
105
- # @param [Integer] id Cryptocurrency identifier
106
- def coin_history_all(id)
107
- coin_history(id, 'ALL')
108
- end
109
-
110
- # Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
111
- #
112
- # Unix Epoch. (SECONDS SINCE JAN 01 1970 (UTC))
113
- #
114
- # CoinmarketcapFree.coin_history_custom_time(1, 1675085165, 1675105165)
115
- #
116
- # @param [Integer] id Cryptocurrency identifier
117
- # @param [Integer] from Enter a Timestamp
118
- # @param [Integer] to Enter a Timestamp
119
- def coin_history_custom_time(id, from, to)
120
- coin_history(id, "#{from}~#{to}")
121
- end
122
-
123
- # Get a list of cryptocurrencies
124
- #
125
- # list = CoinmarketcapFree.coins(limit: 100, start: 1)
126
- #
127
- # Result json:
128
- #
129
- # {
130
- # "data": {
131
- # "cryptoCurrencyList": [
132
- # {
133
- # "id": 1,
134
- # "name": "Bitcoin",
135
- # "symbol": "BTC",
136
- # "slug": "bitcoin",
137
- # "tags": [
138
- # "mineable",
139
- # "pow",
140
- # "sha-256",
141
- # "store-of-value",
142
- # "state-channel",
143
- # "coinbase-ventures-portfolio",
144
- # "three-arrows-capital-portfolio",
145
- # "polychain-capital-portfolio",
146
- # "binance-labs-portfolio",
147
- # "blockchain-capital-portfolio",
148
- # "boostvc-portfolio",
149
- # "cms-holdings-portfolio",
150
- # "dcg-portfolio",
151
- # "dragonfly-capital-portfolio",
152
- # "electric-capital-portfolio",
153
- # "fabric-ventures-portfolio",
154
- # "framework-ventures-portfolio",
155
- # "galaxy-digital-portfolio",
156
- # "huobi-capital-portfolio",
157
- # "alameda-research-portfolio",
158
- # "a16z-portfolio",
159
- # "1confirmation-portfolio",
160
- # "winklevoss-capital-portfolio",
161
- # "usv-portfolio",
162
- # "placeholder-ventures-portfolio",
163
- # "pantera-capital-portfolio",
164
- # "multicoin-capital-portfolio",
165
- # "paradigm-portfolio"
166
- # ],
167
- # "cmcRank": 1,
168
- # "marketPairCount": 9922,
169
- # "circulatingSupply": 19256812.0,
170
- # "selfReportedCirculatingSupply": 0,
171
- # "totalSupply": 19256812.0,
172
- # "maxSupply": 21000000.0,
173
- # "isActive": 1,
174
- # "lastUpdated": "2023-01-09T08:25:00.000Z",
175
- # "dateAdded": "2013-04-28T00:00:00.000Z",
176
- # "quotes": [
177
- # {
178
- # "name": "USD",
179
- # "price": 17209.447088639048,
180
- # "volume24h": 13652714044.770432,
181
- # "marketCap": 331399087209.8695,
182
- # "percentChange1h": -0.00692023,
183
- # "percentChange24h": 1.50954046,
184
- # "percentChange7d": 2.78181713,
185
- # "lastUpdated": "2023-01-09T08:25:00.000Z",
186
- # "percentChange30d": 0.30441134,
187
- # "percentChange60d": 3.89490715,
188
- # "percentChange90d": -9.99714982,
189
- # "fullyDilluttedMarketCap": 361398388861.42,
190
- # "marketCapByTotalSupply": 331399087209.8695,
191
- # "dominance": 39.0828,
192
- # "turnover": 0.0411972,
193
- # "ytdPriceChangePercentage": 3.515
194
- # }
195
- # ],
196
- # "isAudited": false
197
- # }
198
- # ...
199
- # ],
200
- # "totalCount": "8857"
201
- # },
202
- # "status": {
203
- # "timestamp": "2023-01-08T15:33:30.271Z",
204
- # "error_code": "0",
205
- # "error_message": "SUCCESS",
206
- # "elapsed": "2",
207
- # "credit_count": 0
208
- # }
209
- # }
210
- #
211
- # 'data' - Results of your query returned as an object map.
212
- # 'cryptoCurrencyList' - Array of cryptocurrency objects matching the list options.
213
- # 'totalCount' - Total number of cryptocurrencies
214
- # 'status' - Standardized status object for API calls.
215
- #
216
- # If you want to sort in ascending, just write parameter:
217
- #
218
- # list = CoinmarketcapFree.coins(limit: 100, start: 1, sortType:'asc')
219
- #
220
- # or
221
- #
222
- # list = CoinmarketcapFree.coins(limit: 100, start: 1, sortType:'desc')
223
- #
224
- # You can also adding sort by:
225
- #
226
- # list = CoinmarketcapFree.coins(limit: 100, start: 1, sortType:'asc', sortBy: 'name')
227
- #
228
- # Convert cryptocurrency to::
229
- #
230
- # list = CoinmarketcapFree.coins(limit: 100, start: 1, convert: 'USD,BTC,ETH')
231
- #
232
- #
233
- # @return [String, nil]
234
- # @param [Integer] start Optionally offset the start (1-based index) of the paginated list of items to return.
235
- # @param [Integer] limit Optionally specify the number of results to return. Use this parameter and the 'start' parameter to determine your own pagination size.
236
- # @param [String (frozen)] sortBy What field to sort the list of cryptocurrencies by. ('rank', 'name', 'symbol', 'date_added', 'market_cap', 'market_cap_strict', 'price', 'circulating_supply', 'total_supply', 'max_supply', 'num_market_pairs', 'volume_24h', 'percent_change_1h', 'percent_change_24h', 'percent_change_7d', 'market_cap_by_total_supply_strict', 'volume_7d', 'volume_30d")
237
- # @param [String (frozen)] sortType The direction in which to order cryptocurrencies against the specified sort. ('asc', 'desc')
238
- # @param [String (frozen)] convert Select cryptocurrencies to exchange ('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'). For example, many 'USD,BTC,ETH' to convert or only one 'USD'
239
- # @param [String (frozen)] cryptoType The type of cryptocurrency to include. ('all', 'coins', 'tokens')
240
- # @param [String (frozen)] tagType The tag of cryptocurrency to include. ('all', 'defi', 'filesharing')
241
- # @param [TrueClass, FalseClass] audited Show audited 'true' or not 'false'
242
- # @param [String (frozen)] aux Optionally specify a comma-separated list of supplemental data fields to return. Pass 'ath, atl, high24h, low24h, num_market_pairs, cmc_rank, date_added, max_supply, circulating_supply, total_supply, volume_7d, volume_30d, self_reported_circulating_supply, self_reported_market_cap' to include all auxiliary fields.
243
- # @param [String (frozen)] tags If you want to see cryptocurrencies that can be mined, just type 'mineable'.
244
- # @param [String (frozen)] volume24hRange Optionally specify a threshold 24 hour USD volume to filter results by. For example, '0~100000000000000000'
245
- # @param [String (frozen)] percentChange24hRange Optionally specify a threshold 24 hour percent change to filter results by. For example, '0~100' or '-10~100'
246
- # @param [String (frozen)] circulatingSupplyRange Optionally specify a threshold circulating supply to filter results by. For example, '0~100000000000000000'
247
- # @param [String (frozen)] priceRange Optionally specify a threshold USD price to filter results by. For example, '0~100000000000000000'
248
- # @param [String (frozen)] marketCapRange Optionally specify a threshold market cap to filter results by. For example, '0~100000000000000000'
249
- def coins(start: 1,
250
- limit: 100,
251
- sortBy: 'market_cap',
252
- sortType: 'desc',
253
- convert: 'USD',
254
- cryptoType: 'all',
255
- tagType: 'all',
256
- audited: false,
257
- aux: nil,
258
- tags: nil,
259
- volume24hRange: nil,
260
- percentChange24hRange: nil,
261
- circulatingSupplyRange: nil,
262
- priceRange: nil,
263
- marketCapRange: nil)
264
- @@cryptocurrencies.limit = limit # Integer
265
- @@cryptocurrencies.start = start # Integer
266
- @@cryptocurrencies.sortBy = sortBy # String
267
- @@cryptocurrencies.sortType = sortType # String
268
- @@cryptocurrencies.convert = convert # String
269
- @@cryptocurrencies.cryptoType = cryptoType # String
270
- @@cryptocurrencies.tagType = tagType # String
271
- @@cryptocurrencies.audited = audited # Boolean
272
- @@cryptocurrencies.aux = aux # String
273
- @@cryptocurrencies.tags = tags # String
274
- @@cryptocurrencies.volume24hRange = volume24hRange # String
275
- @@cryptocurrencies.percentChange24hRange = percentChange24hRange # String
276
- @@cryptocurrencies.circulatingSupplyRange = circulatingSupplyRange # String
277
- @@cryptocurrencies.priceRange = priceRange # String
278
- @@cryptocurrencies.marketCapRange = marketCapRange # String
279
-
280
- @@cryptocurrencies.update ? @@cryptocurrencies.get_data : nil
281
- end
282
-
283
- # Get coin logo URL from coinmarketcap
284
- #
285
- # logo = CoinmarketcapFree.img_coin(1, 64)
286
- #
287
- # Result:
288
- # "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
289
- #
290
- # @return [String] Return URL from coinmarketcap
291
- # @param [Integer] id_coin Identify coin. For example, bitcoin has 1
292
- # @param [Integer] size Choose one size: 64, 128, 200
293
- def img_coin_url(id_coin, size)
294
- size_x_size = case size
295
- when 64, 128, 200
296
- "#{size}x#{size}"
297
- else
298
- raise ArgumentError, "Can't find this value: #{size}"
299
- end
300
- "https://s2.coinmarketcap.com/static/img/coins/#{size_x_size}/#{id_coin}.png"
301
- end
302
- end
303
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'coinmarketcap_free/coin_history'
4
+ require_relative 'coinmarketcap_free/coins'
5
+ require_relative 'coinmarketcap_free/icons'
6
+ require_relative 'coinmarketcap_free/version'
7
+
8
+ # Get data from Coinmarketcap API without requiring an API key.
9
+ module CoinmarketcapFree
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinmarketcap_free
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cosmic-1
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-05 00:00:00.000000000 Z
11
+ date: 2023-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cryptocurrency information from the Coinmarketcap site without a key.
14
14
  email:
@@ -17,20 +17,16 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".idea/.gitignore"
21
- - ".idea/coinmarketcap_free.iml"
22
- - ".idea/modules.xml"
23
- - ".idea/vcs.xml"
24
20
  - Gemfile
25
21
  - Gemfile.lock
26
22
  - LICENSE.txt
27
23
  - README.md
28
24
  - Rakefile
29
25
  - lib/coinmarketcap_free.rb
30
- - lib/coinmarketcap_free/base.rb
31
- - lib/coinmarketcap_free/coin.rb
32
- - lib/coinmarketcap_free/cryptocurrencies.rb
26
+ - lib/coinmarketcap_free/coin_history.rb
27
+ - lib/coinmarketcap_free/coins.rb
33
28
  - lib/coinmarketcap_free/helper.rb
29
+ - lib/coinmarketcap_free/icons.rb
34
30
  - lib/coinmarketcap_free/version.rb
35
31
  homepage:
36
32
  licenses:
data/.idea/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- # Default ignored files
2
- /shelf/
3
- /workspace.xml
4
- # Editor-based HTTP Client requests
5
- /httpRequests/
6
- # Datasource local storage ignored files
7
- /dataSources/
8
- /dataSources.local.xml
@@ -1,27 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="ModuleRunConfigurationManager">
4
- <shared />
5
- </component>
6
- <component name="NewModuleRootManager">
7
- <content url="file://$MODULE_DIR$">
8
- <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
- <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
- </content>
12
- <orderEntry type="jdk" jdkName="Remote-rbenv: ruby-3.1.3-p185" jdkType="RUBY_SDK" />
13
- <orderEntry type="sourceFolder" forTests="false" />
14
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.26, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="minitest (v5.16.3, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="net-http (v0.3.0, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="openssl (v3.0.1, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="uri (v0.12.0, Remote-rbenv: ruby-3.1.3-p185) [gem]" level="application" />
21
- </component>
22
- <component name="RakeTasksCache">
23
- <option name="myRootTask">
24
- <RakeTaskImpl id="rake" />
25
- </option>
26
- </component>
27
- </module>
data/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/coinmarketcap_free.iml" filepath="$PROJECT_DIR$/.idea/coinmarketcap_free.iml" />
6
- </modules>
7
- </component>
8
- </project>
data/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'coinmarketcap_free/helper'
4
-
5
- module CoinmarketcapFree
6
- class BASE
7
- protected
8
-
9
- # @param [URI] url
10
- # @return [String]
11
- def request_to_read_data(url)
12
- response = Net::HTTP.get_response(url, Hash('Accept': '*/*'))
13
-
14
- raise HTTPBadResponse if response.code.match? /[45][0-9]{2}/
15
-
16
- response.read_body
17
- end
18
-
19
- # @return [String]
20
- def generate_uri_for_data
21
- raise NotImplementedError
22
- end
23
-
24
- public
25
-
26
- attr_reader :get_data
27
-
28
- # @return [false, true] true data update is good If false is bad request, wrong parameter values, or the API has been updated
29
- def update
30
- begin
31
- url = generate_uri_for_data
32
- data = request_to_read_data(url)
33
- rescue
34
- @get_data = nil
35
- false
36
- else
37
- @get_data = data
38
- true
39
- end
40
- end
41
- end
42
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'coinmarketcap_free/helper'
4
- require 'coinmarketcap_free/base'
5
-
6
- module CoinmarketcapFree
7
- # Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
8
- #
9
- # Result json:
10
- #
11
- # {
12
- # "data": {
13
- # "points": {
14
- # "1673192010": {
15
- # "v": [
16
- # 16953.771282696678,
17
- # 7609543976.45,
18
- # 326457581376.786557398500,
19
- # 1,
20
- # 19255750.00000000000000000000
21
- # ],
22
- # "c": [
23
- # 16953.771282696678,
24
- # 7609543976.45,
25
- # 326457581376.786557398500
26
- # ]
27
- # },
28
- # ...
29
- # }
30
- # },
31
- # "status": {
32
- # "timestamp": "2023-01-08T15:33:30.271Z",
33
- # "error_code": "0",
34
- # "error_message": "SUCCESS",
35
- # "elapsed": "2",
36
- # "credit_count": 0
37
- # }
38
- # }
39
- #
40
- # 'data' - Results of your query returned as an object map.
41
- # 'points' - Price range history
42
- # 'status' - Standardized status object for API calls.
43
- class Coin < BASE
44
- URL_API = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail/chart'.freeze
45
- private_constant :URL_API
46
-
47
- attr_accessor :id,
48
- :range_time
49
-
50
- # Returns the CoinmarketcapFree::Coin.
51
- # @param id [Integer] Cryptocurrency identifier from coinmarketcap. For example, Bitcoin has the number 1
52
- # @param range_time [String] Range time. For example, '1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom range '1668981600~1671659999'
53
- def initialize(id = 1, range_time = '1D')
54
- @id = id
55
- @range_time = range_time
56
- end
57
-
58
- private
59
- def generate_uri_for_data
60
- query = "#{URL_API}?id=#{id}&range=#{range_time}"
61
- URI(query)
62
- end
63
- end
64
- end