coinmarketcap_free 0.1.4 → 0.2.0
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/.rubocop.yml +204 -0
- data/Gemfile +16 -16
- data/Gemfile.lock +30 -30
- data/LICENSE.txt +21 -21
- data/README.md +236 -227
- data/Rakefile +12 -12
- data/coinmarketcap_free.gemspec +37 -0
- data/lib/coinmarketcap_free/coin.rb +161 -64
- data/lib/coinmarketcap_free/coin_history.rb +108 -0
- data/lib/coinmarketcap_free/helper.rb +24 -6
- data/lib/coinmarketcap_free/icon.rb +28 -0
- data/lib/coinmarketcap_free/version.rb +5 -5
- data/lib/coinmarketcap_free.rb +10 -303
- metadata +8 -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/cryptocurrencies.rb +0 -192
@@ -1,64 +1,161 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
module CoinmarketcapFree
|
6
|
+
# All about cryptocurrencies and their prices.
|
7
|
+
module Coin
|
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::Coin.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::Coin.list(limit: 100, start: 1, sort_type:'asc')
|
108
|
+
#
|
109
|
+
# or
|
110
|
+
#
|
111
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'desc')
|
112
|
+
#
|
113
|
+
# You can also adding sort by:
|
114
|
+
#
|
115
|
+
# list = CoinmarketcapFree::Coin.list(limit: 100, start: 1, sort_type:'asc', sort_by: 'name')
|
116
|
+
#
|
117
|
+
# Convert cryptocurrency to::
|
118
|
+
#
|
119
|
+
# list = CoinmarketcapFree::Coin.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 list(**params)
|
139
|
+
options = {}
|
140
|
+
|
141
|
+
options[:start] = params[:start] || 1 # Integer
|
142
|
+
options[:limit] = params[:limit] || 100 # Integer
|
143
|
+
options[:sortBy] = params[:sort_by] || 'market_cap' # String
|
144
|
+
options[:sortType] = params[:sort_type] || 'desc' # String
|
145
|
+
options[:convert] = params[:convert] || 'USD' # String
|
146
|
+
options[:cryptoType] = params[:crypto_type] || 'all' # String
|
147
|
+
options[:tagType] = params[:tag_type] || 'all' # String
|
148
|
+
options[:audited] = params[:audited] || false # Boolean
|
149
|
+
options[:aux] = params[:aux] # String
|
150
|
+
options[:tags] = params[:tags] # String
|
151
|
+
options[:volume24hRange] = params[:volume24h_range] # String
|
152
|
+
options[:percentChange24hRange] = params[:percent_change24h_range] # String
|
153
|
+
options[:circulatingSupplyRange] = params[:circulating_supply_range] # String
|
154
|
+
options[:priceRange] = params[:price_range] # String
|
155
|
+
options[:marketCapRange] = params[:market_cap_range] # String
|
156
|
+
|
157
|
+
Helper.http_get(URL_API, options)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,108 @@
|
|
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
|
+
Helper.http_get(URL_API, { id: id, range: range_time })
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns an interval of historic for the day
|
59
|
+
#
|
60
|
+
# @param [Integer] id Cryptocurrency identifier
|
61
|
+
def interval_day(id)
|
62
|
+
custom_time(id, '1D')
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns an interval of historic for the seven days
|
66
|
+
#
|
67
|
+
# @param [Integer] id Cryptocurrency identifier
|
68
|
+
def interval_seven_days(id)
|
69
|
+
custom_time(id, '7D')
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns an interval of historic for the one month
|
73
|
+
#
|
74
|
+
# @param [Integer] id Cryptocurrency identifier
|
75
|
+
def interval_one_month(id)
|
76
|
+
custom_time(id, '1M')
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns an interval of historic for the three months
|
80
|
+
#
|
81
|
+
# @param [Integer] id Cryptocurrency identifier
|
82
|
+
def interval_three_months(id)
|
83
|
+
custom_time(id, '3M')
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns an interval of historic for the one year
|
87
|
+
#
|
88
|
+
# @param [Integer] id Cryptocurrency identifier
|
89
|
+
def interval_one_year(id)
|
90
|
+
custom_time(id, '1Y')
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns an interval of historic for the current year
|
94
|
+
#
|
95
|
+
# @param [Integer] id Cryptocurrency identifier
|
96
|
+
def interval_current_year(id)
|
97
|
+
custom_time(id, 'YTD')
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns an interval of historic for the current year
|
101
|
+
#
|
102
|
+
# @param [Integer] id Cryptocurrency identifier
|
103
|
+
def interval_all_time(id)
|
104
|
+
custom_time(id, 'ALL')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -1,6 +1,24 @@
|
|
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 http_get(url, data = nil)
|
13
|
+
uri = URI(generate_url(url, data))
|
14
|
+
Net::HTTP.get(uri)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def generate_url(url, data = nil)
|
20
|
+
"#{url}#{data ? '?' : ''}#{data.map { |key, value| "#{key}=#{value}" }.join('&')}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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 Icon
|
6
|
+
class << self
|
7
|
+
# Get coin logo URI
|
8
|
+
#
|
9
|
+
# logo = CoinmarketcapFree::Icon.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 generate_url(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 =
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinmarketcapFree
|
4
|
+
VERSION = '0.2.0'
|
5
|
+
end
|