coingecko 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/bin/coingecko +5 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/coingecko.gemspec +46 -0
- data/lib/coingecko/api.rb +36 -0
- data/lib/coingecko/cli.rb +235 -0
- data/lib/coingecko/cli/version.rb +3 -0
- data/lib/coingecko/coin.rb +51 -0
- data/lib/coingecko/global.rb +33 -0
- data/lib/environment.rb +11 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 483e415b673c3e495f3e42fb9e8c614233d0262fb380f2e2d6e305f924f5b57f
|
4
|
+
data.tar.gz: 1963282232d6bce5012aef417a8111bab0910840a40254474070f214444d03e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d018739632ddcf99b87a227ebf1fe5d1546fbf6cf1e4293d74c2ca7a8ce72f6e291555992259550455338a6925019ccfa48e526940d66719333b223e696139a8
|
7
|
+
data.tar.gz: 761def3d5ac1745ef25a14bee3e71c246735d021843e555c26416d2453e16dfa0f6cd95553e56e97310964b4d0e7b0a8f7b1403d538b7270e6cdf818503d486e
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 'fbohorqu@hotmail.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
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
coingecko (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
json (2.2.0)
|
12
|
+
method_source (0.9.2)
|
13
|
+
mini_portile2 (2.4.0)
|
14
|
+
nokogiri (1.10.3)
|
15
|
+
mini_portile2 (~> 2.4.0)
|
16
|
+
pry (0.12.2)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.9.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.8.0)
|
21
|
+
rspec-core (~> 3.8.0)
|
22
|
+
rspec-expectations (~> 3.8.0)
|
23
|
+
rspec-mocks (~> 3.8.0)
|
24
|
+
rspec-core (3.8.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-expectations (3.8.3)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-mocks (3.8.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-support (3.8.0)
|
33
|
+
terminal-table (1.8.0)
|
34
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
35
|
+
unicode-display_width (1.6.0)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 2.0)
|
42
|
+
coingecko!
|
43
|
+
json
|
44
|
+
nokogiri
|
45
|
+
pry
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
terminal-table (~> 1.8)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 'Felipe Bohorquez'
|
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,47 @@
|
|
1
|
+
# Coingecko - A CoinGecko API with CLI Interface
|
2
|
+
|
3
|
+
Pushes all coin data from Coingecko API. Also lists top 100 coins.
|
4
|
+
|
5
|
+
Disclaimer: This is my first Ruby gem so any feedback is greatly welcomed!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'coingecko'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install coingecko
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
A CLI console is provided to lookup coins or list top 100 coins. It also provides a print feature of basic coin attributes. However, all coin attributes can be read as it pulls directly from Coingecko API. To launch the console just launch it from bin folder E.g.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
ruby bin/coingecko
|
29
|
+
```
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
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.
|
34
|
+
|
35
|
+
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).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/'courageoustuple'/coingecko. 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.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
44
|
+
|
45
|
+
## Code of Conduct
|
46
|
+
|
47
|
+
Everyone interacting in the Coingecko project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'courageoustuple'/coingecko/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/coingecko
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "coingecko/cli"
|
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
data/coingecko.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "coingecko/cli/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coingecko"
|
8
|
+
spec.version = Coingecko::VERSION
|
9
|
+
spec.authors = ["'Felipe Bohorquez'"]
|
10
|
+
spec.email = ["''"]
|
11
|
+
|
12
|
+
spec.summary = "tbd"
|
13
|
+
spec.description = "tbd"
|
14
|
+
spec.homepage = "https://github.com/fbohz/coingecko.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
# spec.metadata["source_code_uri"] = "https://github.com/fbohz/coingecko.git"
|
24
|
+
# spec.metadata["changelog_uri"] = "https://github.com/fbohz/coingecko.git"
|
25
|
+
# else
|
26
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
# "public gem pushes."
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency "nokogiri"
|
43
|
+
spec.add_development_dependency "pry"
|
44
|
+
spec.add_development_dependency "json"
|
45
|
+
spec.add_development_dependency 'terminal-table', '~> 1.8'
|
46
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Coingecko::API
|
2
|
+
|
3
|
+
def self.api_call(endpoint="coins")
|
4
|
+
#defaults to list coins if no argument passed
|
5
|
+
res = open("https://api.coingecko.com/api/v3/#{endpoint}").read
|
6
|
+
@json = JSON.parse(res)
|
7
|
+
@json
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def self.list_top_100(currency="usd")
|
12
|
+
self.api_call("coins/markets?vs_currency=#{currency}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.supported_base
|
16
|
+
self.api_call("simple/supported_vs_currencies")
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def self.get_all_coins
|
21
|
+
self.api_call("coins/list")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.look_up_coin(coin_id)
|
25
|
+
self.api_call("coins/#{coin_id}?tickers=true&market_data=true&community_data=true&developer_data=true&sparkline=true")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_global_info
|
29
|
+
self.api_call("global")
|
30
|
+
end
|
31
|
+
|
32
|
+
# def self.current_price_and_change(currency="usd")
|
33
|
+
# self.api_call("coins/markets?vs_currency=#{currency}")
|
34
|
+
# end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
class Coingecko::CLI
|
2
|
+
@@commands = ["ls", "list", "b", "back", "menu", "m", "q", "quit", "exit", "exit!", "find", "f"]
|
3
|
+
|
4
|
+
def run
|
5
|
+
welcome
|
6
|
+
sleep 0.5
|
7
|
+
selection
|
8
|
+
end
|
9
|
+
|
10
|
+
def welcome
|
11
|
+
puts "\nWelcome to Coingecko! Powered by CoinGecko API.\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
def selection
|
15
|
+
puts "\nWhat would you like to do? For the main menu please type menu."
|
16
|
+
input = gets.strip.downcase
|
17
|
+
self.check_selection(input) #from now on self will be implicit as method receiver.
|
18
|
+
end
|
19
|
+
|
20
|
+
def another_selection?
|
21
|
+
puts "Would you like make another selection?"
|
22
|
+
input = gets.strip.downcase
|
23
|
+
if input == "y" || input == "yes"
|
24
|
+
main_menu
|
25
|
+
elsif input == "n" || input == "no"
|
26
|
+
quit
|
27
|
+
return
|
28
|
+
else
|
29
|
+
check_selection(input)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def main_menu
|
35
|
+
puts "\n-To list the top 100 coins type ls."
|
36
|
+
puts "-To find a coin by name, type find."
|
37
|
+
puts "-To get general info, type gen."
|
38
|
+
puts "-To QUIT: please type q."
|
39
|
+
sleep 1
|
40
|
+
selection
|
41
|
+
end
|
42
|
+
|
43
|
+
def list_top_coins
|
44
|
+
list = Coingecko::Coin.new_from_top_100
|
45
|
+
print_top(list)
|
46
|
+
end
|
47
|
+
|
48
|
+
def check_selection(input)
|
49
|
+
case input
|
50
|
+
when "ls", "list"
|
51
|
+
list_top_coins
|
52
|
+
when "menu", "m", "back", "b"
|
53
|
+
main_menu
|
54
|
+
when "q", "quit", "exit", "exit!"
|
55
|
+
quit
|
56
|
+
when "global", "g", "gen", "general"
|
57
|
+
print_global_info
|
58
|
+
when "find", "f"
|
59
|
+
find
|
60
|
+
else
|
61
|
+
puts "Sorry! Did not Understand that."
|
62
|
+
sleep 1
|
63
|
+
puts "Going back.."
|
64
|
+
sleep 1
|
65
|
+
selection
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def print_top(list)
|
70
|
+
puts "Here are the Top 100 Coins!"
|
71
|
+
sleep 1.0
|
72
|
+
puts ".."
|
73
|
+
sleep 1.0
|
74
|
+
puts "....\n\n"
|
75
|
+
sleep 0.5
|
76
|
+
Coingecko::Coin.top_coins.each_with_index do |coin, index|
|
77
|
+
puts "#{index + 1}. #{coin.name}"
|
78
|
+
end
|
79
|
+
sleep 0.5
|
80
|
+
puts "\n\nWhich coin would you like to check out? Please type a number 1-100."
|
81
|
+
answer = gets.chomp.to_i
|
82
|
+
|
83
|
+
if answer > 0 #if string converted to_i will have value of 0
|
84
|
+
id = Coingecko::Coin.top_coins[answer - 1].id
|
85
|
+
print_coin(id)
|
86
|
+
else
|
87
|
+
check_selection(answer)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def decimal_separator(number) #Helper Method. Separates numbers with decimals or returns ∞ when NaN.
|
92
|
+
if number.is_a? Numeric
|
93
|
+
whole, decimal = number.to_s.split(".")
|
94
|
+
whole_with_commas = whole.chars.to_a.reverse.each_slice(3).map(&:join).join(",").reverse
|
95
|
+
[whole_with_commas, decimal].compact.join(".")
|
96
|
+
else
|
97
|
+
number = "∞"
|
98
|
+
number
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def round_if_num(num)
|
103
|
+
if num.is_a? Numeric
|
104
|
+
num.round(1)
|
105
|
+
else
|
106
|
+
"Coingecko Returned N/A"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def table_printer(rows)
|
111
|
+
table = Terminal::Table.new :rows => rows
|
112
|
+
puts table
|
113
|
+
end
|
114
|
+
|
115
|
+
def print_global_info(currency="usd")
|
116
|
+
global_info = Coingecko::Global.new_from_global
|
117
|
+
rows = []
|
118
|
+
puts "Returning Real-Time Global Info from Coingecko..."
|
119
|
+
sleep 2
|
120
|
+
puts "\nGlobal Info:\n"
|
121
|
+
sleep 0.5
|
122
|
+
rows << ["Total Cryptocurrencies: #{global_info.data["active_cryptocurrencies"]}"]
|
123
|
+
rows << ["Total Market Cap: #{decimal_separator(global_info.data["total_market_cap"][currency])}"]
|
124
|
+
rows << ["Total Volume: #{decimal_separator(global_info.data["total_volume"][currency])}"]
|
125
|
+
table_printer(rows)
|
126
|
+
sleep 2
|
127
|
+
rows_two = []
|
128
|
+
puts "Market Cap Share (Top 10):\n"
|
129
|
+
sleep 1.5
|
130
|
+
global_info.data["market_cap_percentage"].each do |k, v|
|
131
|
+
rows_two << ["#{k.upcase}: #{round_if_num(v)}%"]
|
132
|
+
end
|
133
|
+
table_printer(rows_two)
|
134
|
+
sleep 2
|
135
|
+
another_selection?
|
136
|
+
end
|
137
|
+
|
138
|
+
def find
|
139
|
+
puts "Which coin would you like to find? To go back, please type back."
|
140
|
+
input = gets.strip.downcase
|
141
|
+
|
142
|
+
Coingecko::Global.get_all_coins_list
|
143
|
+
all_coins_basic = Coingecko::Global.all_coins_list
|
144
|
+
returned_id = ""
|
145
|
+
all_coins_basic.each do |coin|
|
146
|
+
if coin.name.strip.downcase == input
|
147
|
+
returned_id = coin.id
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
if !returned_id.empty?
|
152
|
+
sleep 1
|
153
|
+
puts "\nCoin match found!\n\n"
|
154
|
+
sleep 2
|
155
|
+
print_coin(returned_id)
|
156
|
+
else
|
157
|
+
check_selection(input)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
def print_coin(id, currency="usd")
|
163
|
+
puts "Retrieving your coin."
|
164
|
+
sleep 0.5
|
165
|
+
puts ".."
|
166
|
+
sleep 0.5
|
167
|
+
puts "....\n\n"
|
168
|
+
sleep 0.5
|
169
|
+
coin = Coingecko::Coin.get_coin(id)
|
170
|
+
rows = []
|
171
|
+
rows << [ "----------- #{coin.name}(#{coin.symbol}) - Rank##{coin.market_cap_rank} (Real-Time) ------------"]
|
172
|
+
sleep 2
|
173
|
+
rows << [ "\nCurrent Price: $#{decimal_separator(coin.market_data["current_price"][currency])} | Market Cap: $#{decimal_separator(coin.market_data["market_cap"][currency])}"]
|
174
|
+
rows << [ "24hr Trading Vol: $#{decimal_separator(coin.market_data["total_volume"][currency])}"]
|
175
|
+
rows << [ "Available Supply: #{decimal_separator(coin.market_data["total_supply"])} / #{decimal_separator(coin.market_data["circulating_supply"])}\n\n" ]
|
176
|
+
table_printer(rows)
|
177
|
+
sleep 2
|
178
|
+
puts "\nDESCRIPTION:\n"
|
179
|
+
sleep 2
|
180
|
+
puts coin.description["en"].gsub(/<\/?[^>]*>/, "") #.gsub strips HTML tags
|
181
|
+
sleep 2
|
182
|
+
puts "\n----------------QUICK FACTS---------------\n"
|
183
|
+
sleep 1
|
184
|
+
rows_two = []
|
185
|
+
rows_two << ["Percentage Change: \n(7 Days) =>(30 Days) =>(1 Year)"]
|
186
|
+
rows_two << [ "(#{round_if_num(coin.market_data["price_change_percentage_7d_in_currency"][currency])}% #{round_if_num(coin.market_data["price_change_percentage_30d_in_currency"][currency])}% #{round_if_num(coin.market_data["price_change_percentage_1y_in_currency"][currency])}% "]
|
187
|
+
rows_two << [ "\n\nAll-Time High | ATH Date | Since ATH "]
|
188
|
+
rows_two << ["#{coin.market_data["ath"][currency]} #{coin.market_data["ath_date"][currency][0..9]} #{round_if_num(coin.market_data["ath_change_percentage"][currency])}%"]
|
189
|
+
table_printer(rows_two)
|
190
|
+
rows_three = []
|
191
|
+
rows_three << ["Website: #{coin.links["homepage"][0]}"]
|
192
|
+
rows_three << ["Reddit: #{coin.links["subreddit_url"]}"]
|
193
|
+
rows_three << ["Github: #{coin.links["repos_url"]["github"][0]} "]
|
194
|
+
rows_three << ["Twitter Handle: @#{coin.links["twitter_screen_name"]}"]
|
195
|
+
rows_three << ["Genesis Date: #{coin.genesis_date}"] if coin.genesis_date
|
196
|
+
rows_three << ["Last Updated: #{coin.last_updated[0..9]}"]
|
197
|
+
sleep 2
|
198
|
+
table_printer(rows_three)
|
199
|
+
sleep 2
|
200
|
+
another_selection?
|
201
|
+
end
|
202
|
+
|
203
|
+
def quit
|
204
|
+
sleep 0.5
|
205
|
+
puts "\nGoodbye! See you next time."
|
206
|
+
sleep 1
|
207
|
+
system('clear')
|
208
|
+
end
|
209
|
+
|
210
|
+
#FOR FUTURE Feature
|
211
|
+
# def change_base
|
212
|
+
# puts "\nNote: The default base currency is USD. Would you like to change the base currency?"
|
213
|
+
# query = gets.strip.downcase
|
214
|
+
# if query == "yes" || query == "y"
|
215
|
+
# need finish...
|
216
|
+
|
217
|
+
# puts "\nHere all the base coins."
|
218
|
+
# base_list = Coingecko::API.supported_base
|
219
|
+
# #call base_list or maybe printer?
|
220
|
+
# puts "\nPlease type the coin you would like to use as a base. To go back type back."
|
221
|
+
# answer = gets.strip.downcase
|
222
|
+
# if @@commands.include? answer
|
223
|
+
# check_selection(answer)
|
224
|
+
# else
|
225
|
+
# list_top_coins
|
226
|
+
# end
|
227
|
+
# end
|
228
|
+
|
229
|
+
# Change Base COMMENTS_BEGIN
|
230
|
+
#current_price and price change calls class method look up to populate those.
|
231
|
+
# the following NEED base_currency:
|
232
|
+
# current_price, ath, ath_change_percentage, price_change_24h_in_currency, price_change_percentage_7d_in_currency, price_change_percentage_30d_in_currency, price_change_percentage_1y_in_currency
|
233
|
+
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Coingecko::Coin
|
2
|
+
attr_accessor :id, :symbol, :name, :block_time_in_minutes, :categories, :localization, :description, :links, :image, :country_origin, :genesis_date, :market_cap_rank, :coingecko_rank, :coingecko_score, :developer_score, :community_score, :liquidity_score, :public_interest_score, :market_data, :community_data, :developer_data, :public_interest_stats, :status_updates, :last_updated, :tickers, :current_price, :total_volume, :high_24h, :low_24h, :price_change_24h, :market_cap, :homepage, :blockchain_site, :ath, :ath_change_percentage, :ath_date, :price_change_percentage_24h, :price_change_24h_in_currency, :price_change_percentage_7d_in_currency, :price_change_percentage_30d_in_currency, :price_change_percentage_1y_in_currency, :market_cap_change_24h, :market_cap_change_percentage_24h, :circulating_supply, :total_supply, :sparkline_7d, :roi, :coin, :ico_data, :contract_address
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
@@top_coins = []
|
6
|
+
|
7
|
+
def initialize(id=nil, symbol=nil, name=nil, market_cap_rank=nil, last_updated=nil)
|
8
|
+
@id = id
|
9
|
+
@symbol = symbol
|
10
|
+
@name = name
|
11
|
+
@market_cap_rank = market_cap_rank
|
12
|
+
@last_updated = last_updated
|
13
|
+
#@@all << self
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all
|
17
|
+
@@all
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.top_coins
|
21
|
+
@@top_coins
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
@@all << self
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.reset(collection)
|
29
|
+
collection.clear
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def self.new_from_top_100(currency="usd")
|
34
|
+
reset(@@top_coins)
|
35
|
+
json = Coingecko::API.list_top_100(currency)
|
36
|
+
json.each do |coin|
|
37
|
+
@@top_coins << self.new(coin["id"], coin["symbol"], coin["name"], coin["market_cap_rank"], coin["last_updated"])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_coin(coin_id)
|
42
|
+
Coingecko::Coin.new.tap do |coin|
|
43
|
+
Coingecko::API.look_up_coin(coin_id).each do |k,v|
|
44
|
+
coin.send("#{k}=", v)
|
45
|
+
end
|
46
|
+
@@all << coin
|
47
|
+
end
|
48
|
+
#binding.pry
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Coingecko::Global
|
2
|
+
attr_accessor :id, :symbol, :name, :data, :active_cryptocurrencies, :upcoming_icos, :ongoing_icos, :ended_icos, :markets, :total_market_cap, :total_volume, :market_cap_percentage, :market_cap_change_percentage_24h_usd, :updated_at
|
3
|
+
@@all_coins_list = []
|
4
|
+
|
5
|
+
|
6
|
+
def self.new_from_global
|
7
|
+
Coingecko::Global.new.tap do |global_attributes|
|
8
|
+
Coingecko::API.get_global_info.each do |k,v|
|
9
|
+
global_attributes.send("#{k}=", v)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all_coins_list
|
15
|
+
@@all_coins_list
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_all_coins_list
|
19
|
+
@@all_coins_list.clear
|
20
|
+
api_get_all = Coingecko::API.get_all_coins
|
21
|
+
counter = 0
|
22
|
+
while counter < api_get_all.length
|
23
|
+
Coingecko::Global.new.tap do |coin_info|
|
24
|
+
api_get_all[counter].each do |k, v|
|
25
|
+
coin_info.send("#{k}=", v)
|
26
|
+
end
|
27
|
+
@@all_coins_list << coin_info
|
28
|
+
counter += 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/environment.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'json'
|
5
|
+
require 'terminal-table'
|
6
|
+
|
7
|
+
require_relative "coingecko/cli/version"
|
8
|
+
require_relative "coingecko/cli"
|
9
|
+
require_relative "coingecko/api"
|
10
|
+
require_relative "coingecko/coin"
|
11
|
+
require_relative "coingecko/global"
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coingecko
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Felipe Bohorquez'"
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-21 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.8'
|
111
|
+
description: tbd
|
112
|
+
email:
|
113
|
+
- "''"
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- CODE_OF_CONDUCT.md
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/coingecko
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- coingecko.gemspec
|
128
|
+
- lib/coingecko/api.rb
|
129
|
+
- lib/coingecko/cli.rb
|
130
|
+
- lib/coingecko/cli/version.rb
|
131
|
+
- lib/coingecko/coin.rb
|
132
|
+
- lib/coingecko/global.rb
|
133
|
+
- lib/environment.rb
|
134
|
+
homepage: https://github.com/fbohz/coingecko.git
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubygems_version: 3.0.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: tbd
|
157
|
+
test_files: []
|