coinmarketcap_free 0.1.3 → 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.
- checksums.yaml +4 -4
- data/Gemfile +16 -16
- data/Gemfile.lock +30 -30
- data/LICENSE.txt +21 -21
- data/README.md +216 -227
- data/Rakefile +12 -12
- data/lib/coinmarketcap_free/coin_history.rb +109 -0
- data/lib/coinmarketcap_free/coins.rb +176 -0
- data/lib/coinmarketcap_free/helper.rb +22 -6
- data/lib/coinmarketcap_free/icons.rb +28 -0
- data/lib/coinmarketcap_free/version.rb +5 -5
- data/lib/coinmarketcap_free.rb +10 -216
- metadata +5 -9
- data/.idea/.gitignore +0 -8
- data/.idea/coinmarketcap_free.iml +0 -27
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
- data/lib/coinmarketcap_free/base.rb +0 -42
- data/lib/coinmarketcap_free/coin.rb +0 -129
- data/lib/coinmarketcap_free/cryptocurrencies.rb +0 -179
@@ -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,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,129 +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
|
-
class << self
|
58
|
-
@@coin = Coin.new()
|
59
|
-
|
60
|
-
# Returns an interval of historic for the day
|
61
|
-
#
|
62
|
-
# @param [Integer] id Cryptocurrency identifier
|
63
|
-
def history_day(id)
|
64
|
-
history(id, '1D')
|
65
|
-
end
|
66
|
-
# Returns an interval of historic for the seven days
|
67
|
-
#
|
68
|
-
# @param [Integer] id Cryptocurrency identifier
|
69
|
-
def history_seven_days(id)
|
70
|
-
history(id, '7D')
|
71
|
-
end
|
72
|
-
# Returns an interval of historic for the one month
|
73
|
-
#
|
74
|
-
# @param [Integer] id Cryptocurrency identifier
|
75
|
-
def history_one_month(id)
|
76
|
-
history(id, '1M')
|
77
|
-
end
|
78
|
-
# Returns an interval of historic for the three months
|
79
|
-
#
|
80
|
-
# @param [Integer] id Cryptocurrency identifier
|
81
|
-
def history_three_months(id)
|
82
|
-
history(id, '3M')
|
83
|
-
end
|
84
|
-
# Returns an interval of historic for the one year
|
85
|
-
#
|
86
|
-
# @param [Integer] id Cryptocurrency identifier
|
87
|
-
def history_one_year(id)
|
88
|
-
history(id, '1Y')
|
89
|
-
end
|
90
|
-
# Returns an interval of historic for the current year
|
91
|
-
#
|
92
|
-
# @param [Integer] id Cryptocurrency identifier
|
93
|
-
def history_current_year(id)
|
94
|
-
history(id, 'YTD')
|
95
|
-
end
|
96
|
-
# Returns an interval of historic for the current year
|
97
|
-
#
|
98
|
-
# @param [Integer] id Cryptocurrency identifier
|
99
|
-
def history_all(id)
|
100
|
-
history(id, 'ALL')
|
101
|
-
end
|
102
|
-
|
103
|
-
# Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
|
104
|
-
#
|
105
|
-
# Unix Epoch. (SECONDS SINCE JAN 01 1970 (UTC))
|
106
|
-
#
|
107
|
-
# CoinmarketcapFree::Coin.history_custom_time(1, 1675085165, 1675105165)
|
108
|
-
#
|
109
|
-
# @param [Integer] id Cryptocurrency identifier
|
110
|
-
# @param [Integer] from Enter a Timestamp
|
111
|
-
# @param [Integer] to Enter a Timestamp
|
112
|
-
def history_custom_time(id, from, to)
|
113
|
-
history(id, "#{from}~#{to}")
|
114
|
-
end
|
115
|
-
|
116
|
-
private def history(id, range_time)
|
117
|
-
@@coin.id = id
|
118
|
-
@@coin.range_time = range_time
|
119
|
-
@@coin.update ? @@coin.get_data : nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
private
|
124
|
-
def generate_uri_for_data
|
125
|
-
query = "#{URL_API}?id=#{id}&range=#{range_time}"
|
126
|
-
URI(query)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,179 +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. The primary options are:
|
118
|
-
#
|
119
|
-
# @param [Hash] options the parameters for creating a request to the server
|
120
|
-
# @option options [Integer] :start (1) Optionally offset the start (1-based index) of the paginated list of items to return.
|
121
|
-
# @option options [Integer] :limit (100) Optionally specify the number of results to return. Use this parameter and the 'start' parameter to determine your own pagination size.
|
122
|
-
# @option options [String] :sortBy ('market_cap') 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")
|
123
|
-
# @option options [String] :sortType ('desc') The direction in which to order cryptocurrencies against the specified sort. ('asc', 'desc')
|
124
|
-
# @option options [String] :convert ('USD') 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'
|
125
|
-
# @option options [String] :cryptoType ('all') The type of cryptocurrency to include. ('all', 'coins', 'tokens')
|
126
|
-
# @option options [String] :tagType ('all') The tag of cryptocurrency to include. ('all', 'defi', 'filesharing')
|
127
|
-
# @option options [false, true] :audited Show audited 'true' or not 'false'
|
128
|
-
# @option options [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.
|
129
|
-
# @option options [String] :tags If you want to see cryptocurrencies that can be mined, just type 'mineable'.
|
130
|
-
# @option options [String] :volume24hRange Optionally specify a threshold 24 hour USD volume to filter results by. For example, '0~100000000000000000'
|
131
|
-
# @option options [String] :percentChange24hRange Optionally specify a threshold 24 hour percent change to filter results by. For example, '0~100' or '-10~100'
|
132
|
-
# @option options [String] :circulatingSupplyRange Optionally specify a threshold circulating supply to filter results by. For example, '0~100000000000000000'
|
133
|
-
# @option options [String] :priceRange Optionally specify a threshold USD price to filter results by. For example, '0~100000000000000000'
|
134
|
-
# @option options [String] :marketCapRange Optionally specify a threshold market cap to filter results by. For example, '0~100000000000000000'
|
135
|
-
def initialize(options = {})
|
136
|
-
@limit = options[:limit].nil? ? 100 : options[:limit] # Integer
|
137
|
-
@start = options[:start].nil? ? 1 : options[:start] # Integer
|
138
|
-
@sortBy = options[:sortBy] # String
|
139
|
-
@sortType = options[:sortType] # String
|
140
|
-
@convert = options[:convert] # String
|
141
|
-
@cryptoType = options[:cryptoType] # String
|
142
|
-
@tagType = options[:tagType] # String
|
143
|
-
@audited = options[:audited] # Boolean
|
144
|
-
@aux = options[:aux] # String
|
145
|
-
@tags = options[:tags] # String
|
146
|
-
@volume24hRange = options[:volume24hRange] # String
|
147
|
-
@percentChange24hRange = options[:percentChange24hRange] # String
|
148
|
-
@circulatingSupplyRange = options[:circulatingSupplyRange] # String
|
149
|
-
@priceRange = options[:priceRange] # String
|
150
|
-
@marketCapRange = options[:marketCapRange] # String
|
151
|
-
end
|
152
|
-
|
153
|
-
attr_accessor :limit,
|
154
|
-
:start,
|
155
|
-
:sortBy,
|
156
|
-
:sortType,
|
157
|
-
:convert,
|
158
|
-
:cryptoType,
|
159
|
-
:tagType,
|
160
|
-
:audited,
|
161
|
-
:aux,
|
162
|
-
:tags,
|
163
|
-
:volume24hRange,
|
164
|
-
:percentChange24hRange,
|
165
|
-
:circulatingSupplyRange,
|
166
|
-
:priceRange,
|
167
|
-
:marketCapRange
|
168
|
-
|
169
|
-
private
|
170
|
-
def generate_uri_for_data
|
171
|
-
options = self.instance_variables
|
172
|
-
.select { |name_var| not self.instance_variable_get(name_var).nil? }
|
173
|
-
.map {|name_var| "#{name_var.to_s.delete('@')}=#{self.instance_variable_get(name_var)}"}
|
174
|
-
|
175
|
-
query = "#{URL_API}?#{options.join('&')}"
|
176
|
-
URI(query)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|