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,192 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'coinmarketcap_free/helper'
4
- require 'coinmarketcap_free/base'
5
-
6
- module CoinmarketcapFree
7
- # Get a list of cryptocurrencies.
8
- #
9
- # list = CoinmarketcapFree::Cryptocurrencies.new(limit: 100, start: 1)
10
- # list.update
11
- # list.get_data
12
- #
13
- # Result json:
14
- #
15
- # {
16
- # "data": {
17
- # "cryptoCurrencyList": [
18
- # {
19
- # "id": 1,
20
- # "name": "Bitcoin",
21
- # "symbol": "BTC",
22
- # "slug": "bitcoin",
23
- # "tags": [
24
- # "mineable",
25
- # "pow",
26
- # "sha-256",
27
- # "store-of-value",
28
- # "state-channel",
29
- # "coinbase-ventures-portfolio",
30
- # "three-arrows-capital-portfolio",
31
- # "polychain-capital-portfolio",
32
- # "binance-labs-portfolio",
33
- # "blockchain-capital-portfolio",
34
- # "boostvc-portfolio",
35
- # "cms-holdings-portfolio",
36
- # "dcg-portfolio",
37
- # "dragonfly-capital-portfolio",
38
- # "electric-capital-portfolio",
39
- # "fabric-ventures-portfolio",
40
- # "framework-ventures-portfolio",
41
- # "galaxy-digital-portfolio",
42
- # "huobi-capital-portfolio",
43
- # "alameda-research-portfolio",
44
- # "a16z-portfolio",
45
- # "1confirmation-portfolio",
46
- # "winklevoss-capital-portfolio",
47
- # "usv-portfolio",
48
- # "placeholder-ventures-portfolio",
49
- # "pantera-capital-portfolio",
50
- # "multicoin-capital-portfolio",
51
- # "paradigm-portfolio"
52
- # ],
53
- # "cmcRank": 1,
54
- # "marketPairCount": 9922,
55
- # "circulatingSupply": 19256812.0,
56
- # "selfReportedCirculatingSupply": 0,
57
- # "totalSupply": 19256812.0,
58
- # "maxSupply": 21000000.0,
59
- # "isActive": 1,
60
- # "lastUpdated": "2023-01-09T08:25:00.000Z",
61
- # "dateAdded": "2013-04-28T00:00:00.000Z",
62
- # "quotes": [
63
- # {
64
- # "name": "USD",
65
- # "price": 17209.447088639048,
66
- # "volume24h": 13652714044.770432,
67
- # "marketCap": 331399087209.8695,
68
- # "percentChange1h": -0.00692023,
69
- # "percentChange24h": 1.50954046,
70
- # "percentChange7d": 2.78181713,
71
- # "lastUpdated": "2023-01-09T08:25:00.000Z",
72
- # "percentChange30d": 0.30441134,
73
- # "percentChange60d": 3.89490715,
74
- # "percentChange90d": -9.99714982,
75
- # "fullyDilluttedMarketCap": 361398388861.42,
76
- # "marketCapByTotalSupply": 331399087209.8695,
77
- # "dominance": 39.0828,
78
- # "turnover": 0.0411972,
79
- # "ytdPriceChangePercentage": 3.515
80
- # }
81
- # ],
82
- # "isAudited": false
83
- # }
84
- # ...
85
- # ],
86
- # "totalCount": "8857"
87
- # },
88
- # "status": {
89
- # "timestamp": "2023-01-08T15:33:30.271Z",
90
- # "error_code": "0",
91
- # "error_message": "SUCCESS",
92
- # "elapsed": "2",
93
- # "credit_count": 0
94
- # }
95
- # }
96
- #
97
- # 'data' - Results of your query returned as an object map.
98
- # 'cryptoCurrencyList' - Array of cryptocurrency objects matching the list options.
99
- # 'totalCount' - Total number of cryptocurrencies
100
- # 'status' - Standardized status object for API calls.
101
- #
102
- # If you want to sort in ascending, just write parameter:
103
- #
104
- # list = CoinmarketcapFree::Cryptocurrencies.new(limit: 100, start: 1, sortType:'asc')
105
- #
106
- # or
107
- #
108
- # list = CoinmarketcapFree::Cryptocurrencies.new(limit: 100, start: 1)
109
- # list.sortType = 'asc'
110
- #
111
- # Also see other parameters.
112
- class Cryptocurrencies < BASE
113
-
114
- URL_API = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing'.freeze
115
- private_constant :URL_API
116
-
117
- # Returns the CoinmarketcapFree::Cryptocurrencies that's dictated by the options hash.
118
- #
119
- # @param [Integer] start Optionally offset the start (1-based index) of the paginated list of items to return.
120
- # @param [Integer] limit Optionally specify the number of results to return. Use this parameter and the 'start' parameter to determine your own pagination size.
121
- # @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")
122
- # @param [String (frozen)] sortType The direction in which to order cryptocurrencies against the specified sort. ('asc', 'desc')
123
- # @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'
124
- # @param [String (frozen)] cryptoType The type of cryptocurrency to include. ('all', 'coins', 'tokens')
125
- # @param [String (frozen)] tagType The tag of cryptocurrency to include. ('all', 'defi', 'filesharing')
126
- # @param [TrueClass, FalseClass] audited Show audited 'true' or not 'false'
127
- # @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.
128
- # @param [String (frozen)] tags If you want to see cryptocurrencies that can be mined, just type 'mineable'.
129
- # @param [String (frozen)] volume24hRange Optionally specify a threshold 24 hour USD volume to filter results by. For example, '0~100000000000000000'
130
- # @param [String (frozen)] percentChange24hRange Optionally specify a threshold 24 hour percent change to filter results by. For example, '0~100' or '-10~100'
131
- # @param [String (frozen)] circulatingSupplyRange Optionally specify a threshold circulating supply to filter results by. For example, '0~100000000000000000'
132
- # @param [String (frozen)] priceRange Optionally specify a threshold USD price to filter results by. For example, '0~100000000000000000'
133
- # @param [String (frozen)] marketCapRange Optionally specify a threshold market cap to filter results by. For example, '0~100000000000000000'
134
- def initialize(start:1,
135
- limit:100,
136
- sortBy: 'market_cap',
137
- sortType:'desc',
138
- convert:'USD',
139
- cryptoType:'all',
140
- tagType:'all',
141
- audited:false,
142
- aux:nil,
143
- tags:nil,
144
- volume24hRange:nil,
145
- percentChange24hRange:nil,
146
- circulatingSupplyRange:nil,
147
- priceRange:nil,
148
- marketCapRange:nil)
149
- @limit = limit # Integer
150
- @start = start # Integer
151
- @sortBy = sortBy # String
152
- @sortType = sortType # String
153
- @convert = convert # String
154
- @cryptoType = cryptoType # String
155
- @tagType = tagType # String
156
- @audited = audited # Boolean
157
- @aux = aux # String
158
- @tags = tags # String
159
- @volume24hRange = volume24hRange # String
160
- @percentChange24hRange = percentChange24hRange # String
161
- @circulatingSupplyRange = circulatingSupplyRange # String
162
- @priceRange = priceRange # String
163
- @marketCapRange = marketCapRange # String
164
- end
165
-
166
- attr_accessor :limit,
167
- :start,
168
- :sortBy,
169
- :sortType,
170
- :convert,
171
- :cryptoType,
172
- :tagType,
173
- :audited,
174
- :aux,
175
- :tags,
176
- :volume24hRange,
177
- :percentChange24hRange,
178
- :circulatingSupplyRange,
179
- :priceRange,
180
- :marketCapRange
181
-
182
- private
183
- def generate_uri_for_data
184
- options = self.instance_variables
185
- .select { |name_var| not self.instance_variable_get(name_var).nil? }
186
- .map {|name_var| "#{name_var.to_s.delete('@')}=#{self.instance_variable_get(name_var)}"}
187
-
188
- query = "#{URL_API}?#{options.join('&')}"
189
- URI(query)
190
- end
191
- end
192
- end