crypto_compare_api 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a79ce31641ff7c3979b5d155dcbe62d681bda555b64d918a8670a6eeccd50e8b
4
+ data.tar.gz: bea1c820ea0ef71d50e1588f55805b28b6e0223b3d56abaf2bdd08d30241307b
5
+ SHA512:
6
+ metadata.gz: 6d30b76915f73e79e4453b690590abbe67a7fecb7a4152ccddd4aa41ee58663edb4636725e8eaf1f4f21180daf52b654cb1257b59ba4744ff37cae8aee2b6d16
7
+ data.tar.gz: 45a68a1e388bbc67002c4abceaa3ebd525013ee4a73ecde65c5130efc246fb0523df64e99300348ad79067e9bbcf00bc5634f0d4beb33530b77366b311ecd486
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at filipe.l.custodio@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in crypto_compare_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 filipe custodio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # CryptoCompareApi
2
+
3
+ Welcome to CryptoCompareApi Gem! This gem is designed to fetch information from https://www.cryptocompare.com/ using built in methods. It uses RESTClient API but don't worry everything will be installed for you.
4
+
5
+ This gem is 100% open source which means anyone can contribute to it or open issues if bugs are found or wish to add extra functionality to it.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'crypto_compare_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install crypto_compare_api
22
+
23
+ If you are prompt with install errors run:
24
+
25
+ $ bundle update
26
+
27
+ Also this gem will work without an API key but it is recommended that you create one at https://www.cryptocompare.com/
28
+
29
+ After creating your profile and generating a new key do:
30
+
31
+ $ touch .env
32
+
33
+ and copy paste your key like this:
34
+
35
+ CRYPTO_COMPARE_API_KEY = your_key
36
+
37
+ ## Usage
38
+
39
+ This gem works as a service so anytime you wanna call a built in method you need to type -> CryptoCompareApi::CryptoCompareApi.new.INSERT_METHOD
40
+
41
+ It packs with the following methods:
42
+
43
+ The initialize
44
+
45
+ Everytime you create an instance of CryptoCompareApi the constructor creates an empty string, an empty array and the base urls used for the specific methods built in. This is designed this way because CryptoCompareApi uses different urls to fetch different information which doesn't have an easy turnaround simply by changing the RestClient query params.
46
+
47
+ The CRYPTO_HASH comes with 41 cryptocurrencies which are the following:
48
+
49
+ CRYPTO_HASH = {
50
+ Bitcoin: 'BTC',
51
+ Ripple: 'XRP',
52
+ Ethereum: 'ETH',
53
+ Stellar: 'XLM',
54
+ BitcoinCash: 'BCH',
55
+ Eos: 'EOS',
56
+ Litecoin: 'LTC',
57
+ Cardano: 'ADA',
58
+ BinanceCoin: 'BNB',
59
+ Siacoin: 'SC',
60
+ Zcash: 'ZEC',
61
+ EthereumClassic: 'ETC',
62
+ Aeternity: 'AE',
63
+ Iota: 'IOT',
64
+ OmiseGO: 'OMG',
65
+ Neo: 'NEO',
66
+ Icon: 'ICX',
67
+ Tron: 'TRX',
68
+ Nano: 'NANO',
69
+ Monero: 'XMR',
70
+ Ox: 'ZRX',
71
+ DigiByte: 'DGB',
72
+ Zilliqa: 'ZIL',
73
+ Decentraland: 'MANA',
74
+ VeChain: 'VET',
75
+ Gifto: 'GTO',
76
+ Qtum: 'QTUM',
77
+ Waves: 'WAVES',
78
+ Augur: 'REP',
79
+ Stratis: 'STRAT',
80
+ OKEX: 'OKB',
81
+ Dash: 'DASH',
82
+ BitcoinSV: 'BSV',
83
+ Tether: 'USDT',
84
+ NEM: 'XEM',
85
+ Dogecoin: 'DOGE',
86
+ Tezos: 'XTZ',
87
+ TrueUSD: 'TUSD',
88
+ USDCoin: 'USDC',
89
+ BitcoinGold: 'BTG',
90
+ BasicAttentionToken: 'BAT',
91
+ Paxos: 'PAX'
92
+ }
93
+
94
+ But fear not young padawan! If you want to add a cryptocurrency that is not there we'll get there in just a few seconds! :)
95
+
96
+ Fast forward, this is a demonstration of how you should use it and the results you'll get once you call the methods.
97
+
98
+ CryptoCompareApi::CryptoCompareApi.new.call_current.prices
99
+
100
+ THIS WILL RETURN AN HASH OF HASHES LIKE THIS
101
+ {"Bitcoin"=>{"BTC"=>3443.67}, "Ethereum"=>{"ETH"=>200.04}}
102
+
103
+ CryptoCompareApi::CryptoCompareApi.new.call_historical_prices('BTC','daily')
104
+
105
+ THIS RETURNS AN ARRAY LIKE THIS
106
+ [8.59, 8.29, 7.75, 7.96, 7.33, 6.77, 6.29, 6.36, 6.9, 5.92, 6.25]
107
+
108
+ Note that the first argument passed into the method is the ticker code of the cryptocurrency and the second one will define the timeframe. The smaller the timeframe the bigger the array. This is designed so you can then build charts if you want to. Also the smaller the index the older the price.
109
+
110
+ The timeframes you can use are -> 'daily', 'hourly', 'minutely'
111
+
112
+ CryptoCompareApi::CryptoCompareApi.new.call_latest_news
113
+
114
+ This will return a bunch of information ! From urls to pictures, descriptions etc etc. The result is an array of hashes with news articles so feel free to use whatever fits your needs!
115
+
116
+ CryptoCompareApi::CryptoCompareApi.new.call_top5_traded
117
+
118
+ this will return something like this
119
+ {:Bitcoin=>"BTC", :Ethereum=>"ETH", :EOS=>"EOS", :XRP=>"XRP", :ZCash=>"ZEC"}
120
+ Also this is top5 by 24 HOURS VOLUME AROUND THE WORLD not based on your app! Keep a reminder of that. This has nothing to do with the CRYPTO_HASH that comes with the gem.
121
+
122
+ CryptoCompareApi::CryptoCompareApi.new.call_top5_winners
123
+
124
+ this returns an hash like this
125
+ {"REP"=>8.108108108108116, "WAVES"=>6.535947712418292, "BNB"=>4.228486646884287, "BAT"=>2.183984116479158, "QTUM"=>1.8749999999999878}
126
+
127
+ Also, this is only for top5 winners that are inside the Crypto_Hash of the gem. And as a bonus it is sorted for you from biggest winner to smallest winner because why not !
128
+
129
+ CryptoCompareApi::CryptoCompareApi.new.call_top5_losers
130
+
131
+ this returns an hash like this
132
+ {"DIG"=>-22.26890756302521, "BCH"=>-4.433786825878439, "ZEC"=>-4.110072323161049, "XLM"=>-3.729401561144838, "LSK"=>-3.361344537815129}
133
+
134
+ As you can guess it works just like the top5 winners!
135
+
136
+ And Last but not Least, we don't want you to only use the default cryptocurrencies. So there's a method you can use to add the cryptocurrency you want just make sure to follow the right rules!
137
+
138
+ CryptoCompareApi::CryptoCompareApi.new.add_crypto_to_hash('NEM','XEM')
139
+
140
+ Make sure you add the correct ticker name and ticker code. And that's it!
141
+
142
+ This is my first gem and it was pulled from a project service I made. So any criticism or contribution is very welcomed!
143
+
144
+ ## Development
145
+
146
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
147
+
148
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
149
+
150
+ ## Contributing
151
+
152
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fcustodio90/crypto_compare_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
153
+
154
+ ## License
155
+
156
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
157
+
158
+ ## Code of Conduct
159
+
160
+ Everyone interacting in the CryptoCompareApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/crypto_compare_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "crypto_compare_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'crypto_compare_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'crypto_compare_api'
7
+ spec.version = CryptoCompareApi::VERSION
8
+ spec.authors = ['filipe custodio']
9
+ spec.email = ['filipe.l.custodio@gmail.com']
10
+
11
+ spec.summary = %q{Gem to fetch information from https://www.cryptocompare.com/ API}
12
+ spec.description = %q{This gem has built in methods that fetch different information about cryptocurrencies using Restclient API.}
13
+ spec.homepage = 'https://github.com/fcustodio90/crypto_compare_api'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ # spec.metadata["homepage_uri"] = spec.homepage
22
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
23
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against " \
26
+ # "public gem pushes."
27
+ # end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rest-client'
41
+ end
@@ -0,0 +1,240 @@
1
+ require 'crypto_compare_api/version'
2
+ require 'rest-client'
3
+
4
+ module CryptoCompareApi
5
+ class CryptoCompareApi
6
+ # BUILDING CRYPTOCURRENCIES HASH TO FETCH TO BUILD SEEDS AND FETCH TO API LATER
7
+
8
+ # IF YOU WANNA ADD A CRYPTOCURRENCY JUST ADD TICKER_NAME WITH A COMMA TO THE HASH
9
+
10
+ # AND TICKER_CODE AS VALUE
11
+
12
+ CRYPTO_HASH = {
13
+ Bitcoin: 'BTC',
14
+ Ripple: 'XRP',
15
+ Ethereum: 'ETH',
16
+ Stellar: 'XLM',
17
+ BitcoinCash: 'BCH',
18
+ Eos: 'EOS',
19
+ Litecoin: 'LTC',
20
+ Cardano: 'ADA',
21
+ BinanceCoin: 'BNB',
22
+ Siacoin: 'SC',
23
+ Zcash: 'ZEC',
24
+ EthereumClassic: 'ETC',
25
+ Aeternity: 'AE',
26
+ Iota: 'IOT',
27
+ OmiseGO: 'OMG',
28
+ Neo: 'NEO',
29
+ Icon: 'ICX',
30
+ Tron: 'TRX',
31
+ Nano: 'NANO',
32
+ Monero: 'XMR',
33
+ Ox: 'ZRX',
34
+ DigiByte: 'DGB',
35
+ Zilliqa: 'ZIL',
36
+ Decentraland: 'MANA',
37
+ VeChain: 'VET',
38
+ Gifto: 'GTO',
39
+ Qtum: 'QTUM',
40
+ Waves: 'WAVES',
41
+ Augur: 'REP',
42
+ Stratis: 'STRAT',
43
+ OKEX: 'OKB',
44
+ Dash: 'DASH',
45
+ BitcoinSV: 'BSV',
46
+ Tether: 'USDT',
47
+ NEM: 'XEM',
48
+ Dogecoin: 'DOGE',
49
+ Tezos: 'XTZ',
50
+ TrueUSD: 'TUSD',
51
+ USDCoin: 'USDC',
52
+ BitcoinGold: 'BTG',
53
+ BasicAttentionToken: 'BAT',
54
+ Paxos: 'PAX'
55
+ }
56
+
57
+ FIAT_CURRENCIES = 'USD'
58
+
59
+ def initialize
60
+ # initializing with empty string that will be filled with tickers
61
+ @crypto_string_with_tickers = ''
62
+
63
+ # initializing with empty array that will be filled with names
64
+ @crypto_array_with_names = []
65
+
66
+ # base url for get requests with multi currencies and current prices
67
+ @base_url_current_prices = 'https://min-api.cryptocompare.com/data/pricemultifull'
68
+
69
+ # base url for get requests for historical data
70
+ @base_url_historical_prices = 'https://min-api.cryptocompare.com/data/histo'
71
+
72
+ # base url for get requests for latest news
73
+ @base_url_current_news = 'https://min-api.cryptocompare.com/data/v2/news/?lang=EN'
74
+
75
+ # base url for get requests for top10 traded
76
+ # be careful because the minium number for request is 10 with a max 100
77
+ # since we only need the top5 i left the limit=10 in the base url
78
+ @base_url_top_traded = 'https://min-api.cryptocompare.com/data/top/totalvolfull?limit=10'
79
+
80
+ @api_key = ENV['CRYPTO_COMPARE_API_KEY']
81
+ end
82
+
83
+ def call_current_prices
84
+ # call the previous method
85
+ hash_to_string_and_array
86
+
87
+ query_params = {
88
+ fsyms: @crypto_string_with_tickers,
89
+ tsyms: FIAT_CURRENCIES,
90
+ api_key: @api_key
91
+ }
92
+
93
+ # WARNING: DO NOT DELETE THIS VARIABLE BECAUSE WE MIGHT NEED IT IN THE
94
+ # FUTURE TO DEBUG SOME STUFF.
95
+ # Transform the ex string "BTC,ETH,XRP," into "BTC,ETH,XRP"
96
+ # @crypto_string_with_tickers = @crypto_string_with_tickers.chomp(",")
97
+
98
+ # Transform the crypto string into a crypto array with tickers ex: ["BTC","ETH","XRP"]
99
+ crypto_array_with_tickers = @crypto_string_with_tickers.split(',')
100
+ # Building the API GET Request and Parsing the Response
101
+ response = RestClient.get(@base_url_current_prices, params: query_params)
102
+
103
+ response_parsed = JSON.parse(response)
104
+ # Empty hash to build an hash of hashes
105
+ crypto_seeds_hash = {}
106
+
107
+ # THIS RETURNS AN HASH LIKE THIS {btc: 3017.24, eth: 3014.24}
108
+ crypto_array_with_tickers.each do |crypto|
109
+ crypto_seeds_hash[crypto] = response_parsed['RAW'][crypto][FIAT_CURRENCIES]['PRICE']
110
+ end
111
+
112
+ # THIS WILL RETURN AN HASH OF HASHES LIKE THIS
113
+ # {"Bitcoin"=>{"BTC"=>3443.67}, "Ethereum"=>{"ETH"=>200.04}}
114
+ Hash[@crypto_array_with_names.zip(crypto_seeds_hash.to_a)].transform_values!{|a| Hash[*a]}
115
+ end
116
+
117
+ def call_historical_prices(crypto, type = nil)
118
+ if type == 'daily'
119
+ limit = 365
120
+ call_type = 'day'
121
+ elsif type == 'hourly'
122
+ limit = 720
123
+ call_type = 'hour'
124
+ elsif type == 'minutely'
125
+ limit = 1440
126
+ call_type = 'minute'
127
+ end
128
+
129
+ url = @base_url_historical_prices + call_type
130
+
131
+ query_params = {
132
+ fsym: crypto,
133
+ tsym: FIAT_CURRENCIES,
134
+ limit: limit,
135
+ toTs: Time.new.to_i,
136
+ api_key: @api_key
137
+ }
138
+ # Building the API GET Request and Parsing the Response
139
+ response = RestClient.get(url, {params: query_params})
140
+ # RAW RESPONSE
141
+ response_parsed = JSON.parse(response)
142
+ # RAW RESPONSE WITH FILTERS
143
+ historical_data = response_parsed['Data']
144
+ # EMPTY ARRAY THAT WILL BE FILLED WITH DATA LATER
145
+ historical_data_days_array = []
146
+
147
+ historical_data.each do |data|
148
+ historical_data_days_array << data['close']
149
+ end
150
+ # THIS RETURNS AN ARRAY LIKE THIS
151
+ # [8.59, 8.29, 7.75, 7.96, 7.33, 6.77, 6.29, 6.36, 6.9, 5.92, 6.25]
152
+ historical_data_days_array
153
+ end
154
+
155
+ def call_latest_news
156
+ query_params = { api_key: @api_key }
157
+ # Building the API GET Request and Parsing the response
158
+ response = RestClient.get(@base_url_current_news, params: query_params)
159
+ JSON.parse(response)['Data']
160
+ # This returns an array of hashes with news articles
161
+ end
162
+
163
+ def call_top5_traded
164
+ query_params = {
165
+ tsym: FIAT_CURRENCIES,
166
+ api_key: @api_key
167
+ }
168
+ # Empty hash to be filled later with data
169
+ crypto_top_5_hash = {}
170
+
171
+ # Building the API GET Request and Parsing the response
172
+ response = RestClient.get(@base_url_top_traded, params: query_params)
173
+ JSON.parse(response)['Data'].first(5).each do |crypto|
174
+ crypto_top_5_hash[crypto['CoinInfo']['FullName']] = crypto['CoinInfo']['Name']
175
+ end
176
+ # this will return something like this
177
+ # {:Bitcoin=>"BTC", :Ethereum=>"ETH", :EOS=>"EOS", :XRP=>"XRP", :ZCash=>"ZEC"}
178
+ crypto_top_5_hash
179
+ end
180
+
181
+ def call_top5_winners
182
+ # this returns an hash like this
183
+ # {"REP"=>8.108108108108116, "WAVES"=>6.535947712418292, "BNB"=>4.228486646884287, "BAT"=>2.183984116479158, "QTUM"=>1.8749999999999878}
184
+ Hash[top5_winners_and_losers.to_a.reverse].first(5).to_h
185
+ end
186
+
187
+ def call_top5_losers
188
+ # this returns an hash like this
189
+ # {"DIG"=>-22.26890756302521, "BCH"=>-4.433786825878439, "ZEC"=>-4.110072323161049, "XLM"=>-3.729401561144838, "LSK"=>-3.361344537815129}
190
+ top5_winners_and_losers.first(5).to_h
191
+ end
192
+
193
+ def add_crypto_to_hash(ticker_name, ticker_code)
194
+ CRYPTO_HASH[ticker_name] = ticker_code
195
+ end
196
+
197
+ private
198
+
199
+ def hash_to_string_and_array
200
+ # Iterate through the crypto_hash
201
+ crypto_array = []
202
+ crypto_array_with_names = []
203
+ CRYPTO_HASH.each do |key, value|
204
+ # Build an array with all cryptocurrency tickers
205
+ crypto_array << value
206
+ # build an array with all cryptocurrency names
207
+ crypto_array_with_names << key.to_s
208
+ end
209
+ # build a string with ticker names without duplicates
210
+ # ex: ["BTC","ETC","ETH",XRP]
211
+ @crypto_string_with_tickers = crypto_array.uniq.join(',')
212
+ # build an array with names ["Bitcoin", "Ethereum"] etc.
213
+ @crypto_array_with_names = crypto_array_with_names.uniq
214
+ end
215
+
216
+ def top5_winners_and_losers
217
+ # call the method
218
+ hash_to_string_and_array
219
+
220
+ @crypto_array_with_tickers = @crypto_string_with_tickers.split(',')
221
+
222
+ query_params = {
223
+ fsyms: @crypto_string_with_tickers,
224
+ tsyms: FIAT_CURRENCIES,
225
+ api_key: @api_key
226
+ }
227
+
228
+ # Building the API GET Request and Parsing the response
229
+ response = RestClient.get(@base_url_current_prices, params: query_params)
230
+ response_parsed = JSON.parse(response)
231
+ # Empty hash to build an hash of hashes
232
+ top5_hash = {}
233
+ @crypto_array_with_tickers.each do |crypto|
234
+ top5_hash[crypto] = response_parsed['RAW'][crypto][FIAT_CURRENCIES]['CHANGEPCTDAY']
235
+ end
236
+ # this returns an hash sorted by key.values from low negatives to high positives
237
+ top5_hash.sort_by { |_key, value| value }.to_h
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,3 @@
1
+ module CryptoCompareApi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crypto_compare_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - filipe custodio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This gem has built in methods that fetch different information about
56
+ cryptocurrencies using Restclient API.
57
+ email:
58
+ - filipe.l.custodio@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - crypto_compare_api.gemspec
72
+ - lib/crypto_compare_api.rb
73
+ - lib/crypto_compare_api/version.rb
74
+ homepage: https://github.com/fcustodio90/crypto_compare_api
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.0.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Gem to fetch information from https://www.cryptocompare.com/ API
97
+ test_files: []