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.
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
10
- end
11
-
12
- task default: :test
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ module CoinmarketcapFree
6
+ # All history cryptocurrency and their prices.
7
+ module CoinHistory
8
+ URL_API = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail/chart'
9
+ private_constant :URL_API
10
+
11
+ class << self
12
+ # Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
13
+ #
14
+ # history = CoinmarketcapFree::CoinHistory.custom_time(1, '1D')
15
+ #
16
+ # Result json:
17
+ #
18
+ # {
19
+ # "data": {
20
+ # "points": {
21
+ # "1673192010": {
22
+ # "v": [
23
+ # 16953.771282696678,
24
+ # 7609543976.45,
25
+ # 326457581376.786557398500,
26
+ # 1,
27
+ # 19255750.00000000000000000000
28
+ # ],
29
+ # "c": [
30
+ # 16953.771282696678,
31
+ # 7609543976.45,
32
+ # 326457581376.786557398500
33
+ # ]
34
+ # },
35
+ # ...
36
+ # }
37
+ # },
38
+ # "status": {
39
+ # "timestamp": "2023-01-08T15:33:30.271Z",
40
+ # "error_code": "0",
41
+ # "error_message": "SUCCESS",
42
+ # "elapsed": "2",
43
+ # "credit_count": 0
44
+ # }
45
+ # }
46
+ #
47
+ # 'data' - Results of your query returned as an object map.
48
+ # 'points' - Price range history
49
+ # 'status' - Standardized status object for API calls.
50
+ #
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
+ # @return [String]
54
+ def custom_time(id, range_time)
55
+ uri = Helper.generate_uri_for_data(URL_API, { id: id, range: range_time })
56
+ Helper.request_to_read_data(uri)
57
+ end
58
+
59
+ # Returns an interval of historic for the day
60
+ #
61
+ # @param [Integer] id Cryptocurrency identifier
62
+ def interval_day(id)
63
+ custom_time(id, '1D')
64
+ end
65
+
66
+ # Returns an interval of historic for the seven days
67
+ #
68
+ # @param [Integer] id Cryptocurrency identifier
69
+ def interval_seven_days(id)
70
+ custom_time(id, '7D')
71
+ end
72
+
73
+ # Returns an interval of historic for the one month
74
+ #
75
+ # @param [Integer] id Cryptocurrency identifier
76
+ def interval_one_month(id)
77
+ custom_time(id, '1M')
78
+ end
79
+
80
+ # Returns an interval of historic for the three months
81
+ #
82
+ # @param [Integer] id Cryptocurrency identifier
83
+ def interval_three_months(id)
84
+ custom_time(id, '3M')
85
+ end
86
+
87
+ # Returns an interval of historic for the one year
88
+ #
89
+ # @param [Integer] id Cryptocurrency identifier
90
+ def interval_one_year(id)
91
+ custom_time(id, '1Y')
92
+ end
93
+
94
+ # Returns an interval of historic for the current year
95
+ #
96
+ # @param [Integer] id Cryptocurrency identifier
97
+ def interval_current_year(id)
98
+ custom_time(id, 'YTD')
99
+ end
100
+
101
+ # Returns an interval of historic for the current year
102
+ #
103
+ # @param [Integer] id Cryptocurrency identifier
104
+ def interval_all_time(id)
105
+ custom_time(id, 'ALL')
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,176 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ module CoinmarketcapFree
6
+ # All about cryptocurrencies and their prices.
7
+ module Coins
8
+ URL_API = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing'
9
+ private_constant :URL_API
10
+
11
+ class << self
12
+ # Get a list of cryptocurrencies
13
+ #
14
+ # list = CoinmarketcapFree::Coins.get_list(limit: 100, start: 1)
15
+ #
16
+ # Result json:
17
+ #
18
+ # {
19
+ # "data": {
20
+ # "cryptoCurrencyList": [
21
+ # {
22
+ # "id": 1,
23
+ # "name": "Bitcoin",
24
+ # "symbol": "BTC",
25
+ # "slug": "bitcoin",
26
+ # "tags": [
27
+ # "mineable",
28
+ # "pow",
29
+ # "sha-256",
30
+ # "store-of-value",
31
+ # "state-channel",
32
+ # "coinbase-ventures-portfolio",
33
+ # "three-arrows-capital-portfolio",
34
+ # "polychain-capital-portfolio",
35
+ # "binance-labs-portfolio",
36
+ # "blockchain-capital-portfolio",
37
+ # "boostvc-portfolio",
38
+ # "cms-holdings-portfolio",
39
+ # "dcg-portfolio",
40
+ # "dragonfly-capital-portfolio",
41
+ # "electric-capital-portfolio",
42
+ # "fabric-ventures-portfolio",
43
+ # "framework-ventures-portfolio",
44
+ # "galaxy-digital-portfolio",
45
+ # "huobi-capital-portfolio",
46
+ # "alameda-research-portfolio",
47
+ # "a16z-portfolio",
48
+ # "1confirmation-portfolio",
49
+ # "winklevoss-capital-portfolio",
50
+ # "usv-portfolio",
51
+ # "placeholder-ventures-portfolio",
52
+ # "pantera-capital-portfolio",
53
+ # "multicoin-capital-portfolio",
54
+ # "paradigm-portfolio"
55
+ # ],
56
+ # "cmcRank": 1,
57
+ # "marketPairCount": 9922,
58
+ # "circulatingSupply": 19256812.0,
59
+ # "selfReportedCirculatingSupply": 0,
60
+ # "totalSupply": 19256812.0,
61
+ # "maxSupply": 21000000.0,
62
+ # "isActive": 1,
63
+ # "lastUpdated": "2023-01-09T08:25:00.000Z",
64
+ # "dateAdded": "2013-04-28T00:00:00.000Z",
65
+ # "quotes": [
66
+ # {
67
+ # "name": "USD",
68
+ # "price": 17209.447088639048,
69
+ # "volume24h": 13652714044.770432,
70
+ # "marketCap": 331399087209.8695,
71
+ # "percentChange1h": -0.00692023,
72
+ # "percentChange24h": 1.50954046,
73
+ # "percentChange7d": 2.78181713,
74
+ # "lastUpdated": "2023-01-09T08:25:00.000Z",
75
+ # "percentChange30d": 0.30441134,
76
+ # "percentChange60d": 3.89490715,
77
+ # "percentChange90d": -9.99714982,
78
+ # "fullyDilluttedMarketCap": 361398388861.42,
79
+ # "marketCapByTotalSupply": 331399087209.8695,
80
+ # "dominance": 39.0828,
81
+ # "turnover": 0.0411972,
82
+ # "ytdPriceChangePercentage": 3.515
83
+ # }
84
+ # ],
85
+ # "isAudited": false
86
+ # }
87
+ # ...
88
+ # ],
89
+ # "totalCount": "8857"
90
+ # },
91
+ # "status": {
92
+ # "timestamp": "2023-01-08T15:33:30.271Z",
93
+ # "error_code": "0",
94
+ # "error_message": "SUCCESS",
95
+ # "elapsed": "2",
96
+ # "credit_count": 0
97
+ # }
98
+ # }
99
+ #
100
+ # 'data' - Results of your query returned as an object map.
101
+ # 'cryptoCurrencyList' - Array of cryptocurrency objects matching the list options.
102
+ # 'totalCount' - Total number of cryptocurrencies
103
+ # 'status' - Standardized status object for API calls.
104
+ #
105
+ # If you want to sort in ascending, just write parameter:
106
+ #
107
+ # list = CoinmarketcapFree::Coins.get_list(limit: 100, start: 1, sort_type:'asc')
108
+ #
109
+ # or
110
+ #
111
+ # list = CoinmarketcapFree::Coins.get_list(limit: 100, start: 1, sort_type:'desc')
112
+ #
113
+ # You can also adding sort by:
114
+ #
115
+ # list = CoinmarketcapFree::Coins.get_list(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
116
+ #
117
+ # Convert cryptocurrency to::
118
+ #
119
+ # list = CoinmarketcapFree::Coins.get_list(limit: 100, start: 1, convert: 'USD,BTC,ETH')
120
+ #
121
+ #
122
+ # @return [String]
123
+ # @param [Integer] start Optionally offset the start (1-based index) of the paginated list of items to return.
124
+ # @param [Integer] limit Optionally specify the number of results to return. Use this parameter and the 'start' parameter to determine your own pagination size.
125
+ # @param [String] sort_by 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")
126
+ # @param [String] sort_type The direction in which to order cryptocurrencies against the specified sort. ('asc', 'desc')
127
+ # @param [String] 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'
128
+ # @param [String] crypto_type The type of cryptocurrency to include. ('all', 'coins', 'tokens')
129
+ # @param [String] tag_type The tag of cryptocurrency to include. ('all', 'defi', 'filesharing')
130
+ # @param [TrueClass, FalseClass] audited Show audited 'true' or not 'false'
131
+ # @param [String] 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.
132
+ # @param [String] tags If you want to see cryptocurrencies that can be mined, just type 'mineable'.
133
+ # @param [String] volume24h_range Optionally specify a threshold 24 hour USD volume to filter results by. For example, '0~100000000000000000'
134
+ # @param [String] percent_change24h_range Optionally specify a threshold 24 hour percent change to filter results by. For example, '0~100' or '-10~100'
135
+ # @param [String] circulating_supply_range Optionally specify a threshold circulating supply to filter results by. For example, '0~100000000000000000'
136
+ # @param [String] price_range Optionally specify a threshold USD price to filter results by. For example, '0~100000000000000000'
137
+ # @param [String] market_cap_range Optionally specify a threshold market cap to filter results by. For example, '0~100000000000000000'
138
+ def get_list(start: 1,
139
+ limit: 100,
140
+ sort_by: 'market_cap',
141
+ sort_type: 'desc',
142
+ convert: 'USD',
143
+ crypto_type: 'all',
144
+ tag_type: 'all',
145
+ audited: false,
146
+ aux: nil,
147
+ tags: nil,
148
+ volume24h_range: nil,
149
+ percent_change24h_range: nil,
150
+ circulating_supply_range: nil,
151
+ price_range: nil,
152
+ market_cap_range: nil)
153
+ options = {
154
+ start: start, # Integer
155
+ limit: limit, # Integer
156
+ sortBy: sort_by, # String
157
+ sortType: sort_type, # String
158
+ convert: convert, # String
159
+ cryptoType: crypto_type, # String
160
+ tagType: tag_type, # String
161
+ audited: audited, # Boolean
162
+ aux: aux, # String
163
+ tags: tags, # String
164
+ volume24hRange: volume24h_range, # String
165
+ percentChange24hRange: percent_change24h_range, # String
166
+ circulatingSupplyRange: circulating_supply_range, # String
167
+ priceRange: price_range, # String
168
+ marketCapRange: market_cap_range # String
169
+ }
170
+
171
+ uri = Helper.generate_uri_for_data(URL_API, options)
172
+ Helper.request_to_read_data(uri)
173
+ end
174
+ end
175
+ end
176
+ end
@@ -1,6 +1,22 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'net/http'
5
- require 'openssl'
6
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'openssl'
6
+ require 'json'
7
+
8
+ module CoinmarketcapFree
9
+ # Helper module for CoinmarketcapFree
10
+ module Helper
11
+ class << self
12
+ def request_to_read_data(uri_string)
13
+ uri = URI(uri_string)
14
+ Net::HTTP.get(uri)
15
+ end
16
+
17
+ def generate_uri_for_data(url, data)
18
+ "#{url}?#{data.map { |key, value| "#{key}=#{value}" }.join('&')}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CoinmarketcapFree
4
+ # Get static image of a coin from coinmarketcap.com
5
+ module Icons
6
+ class << self
7
+ # Get coin logo URI
8
+ #
9
+ # logo = CoinmarketcapFree.img_coin(1, 64)
10
+ #
11
+ # Result:
12
+ # "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
13
+ #
14
+ # @param [Integer] id_coin Identify coin. For example, bitcoin has 1
15
+ # @param [Integer] size Choose one size: 64, 128, 200
16
+ # @return [String] Return URI from coinmarketcap
17
+ def get_coin_logo_uri(id_coin, size)
18
+ size_x_size = case size
19
+ when 64, 128, 200
20
+ "#{size}x#{size}"
21
+ else
22
+ raise ArgumentError, "Can't find this value: #{size}"
23
+ end
24
+ "https://s2.coinmarketcap.com/static/img/coins/#{size_x_size}/#{id_coin}.png"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module CoinmarketcapFree
4
- VERSION = "0.1.4"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module CoinmarketcapFree
4
+ VERSION = '0.1.5'
5
+ end