blade_coin 0.1.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -14
- data/bin/coin +10 -13
- data/bin/coin-cli +18 -0
- data/blade_coin.gemspec +4 -6
- data/lib/blade/coin/version.rb +1 -1
- data/lib/blade/coin.rb +57 -6
- data/top_10.png +0 -0
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 161fb9639b0822ee44c9203384573447f90771c788c1b8287e0dd8c8d8e22b91
|
4
|
+
data.tar.gz: 159ba0c17cfeb2c1ea446e02461c54e0399b527129ce842adf4d3bc02539fbe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7c088164bf44557117f9cb7d09a956a68c01d6edcfc103c473dff228859b75afd5bbd9f91c8391bcdad12b77b1fe8d88d0de605e3b7de4170142ea53d0f798
|
7
|
+
data.tar.gz: 2282f4122753d95f8fba33b2d72a2ad9ffd9af8663e5ae9ce4b6b487c7e0bafb19b9ab5dcc89cdf8f0f19ebbe347574c7184a5c02e1f9517f46cf29ea674e476
|
data/README.md
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
# BladeCoin
|
2
2
|
|
3
|
-
|
3
|
+
💰 A cryptocurrency price monitoring tool
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
$ gem install blade_coin
|
8
8
|
|
9
|
-
|
10
|
-
gem 'blade_coin'
|
11
|
-
```
|
9
|
+
## Usage
|
12
10
|
|
13
|
-
|
11
|
+
To check the top 10 cryptocurrencies ranked by their market cap, simply enter
|
12
|
+
```
|
13
|
+
$ coin
|
14
|
+
```
|
14
15
|
|
15
|
-
|
16
|
+
Result Output Example:
|
16
17
|
|
17
|
-
|
18
|
+
![](./top_10.png)
|
18
19
|
|
19
|
-
|
20
|
+
## Options
|
20
21
|
|
21
|
-
|
22
|
+
### Find specific coin(s)
|
22
23
|
|
23
24
|
like `btc`
|
24
25
|
|
@@ -32,15 +33,33 @@ BTC_USDT
|
|
32
33
|
66065.69
|
33
34
|
```
|
34
35
|
|
35
|
-
|
36
|
+
### Find top coin(s)
|
37
|
+
|
38
|
+
You can use the `-t` (or `--top`) with the index to find the top n cryptocurrencies ranked by their market cap.
|
36
39
|
|
37
|
-
|
40
|
+
```
|
41
|
+
$ coin -t 50 // find top 50
|
42
|
+
```
|
38
43
|
|
39
|
-
|
44
|
+
### CLI
|
45
|
+
|
46
|
+
You can quickly query the symbol you want to search for
|
47
|
+
|
48
|
+
```
|
49
|
+
coin-cli
|
50
|
+
```
|
51
|
+
|
52
|
+
### Show option menu
|
53
|
+
|
54
|
+
You can use the `-h` (or `--help`) to find all valid options of coin
|
55
|
+
|
56
|
+
```
|
57
|
+
$ coin -h
|
58
|
+
```
|
40
59
|
|
41
60
|
## Contributing
|
42
61
|
|
43
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gith-u-b/blade_coin. 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.
|
44
63
|
|
45
64
|
## License
|
46
65
|
|
data/bin/coin
CHANGED
@@ -3,25 +3,22 @@
|
|
3
3
|
require_relative '../lib/blade/coin'
|
4
4
|
|
5
5
|
help = <<HELP
|
6
|
-
coin:
|
7
|
-
$ coin symbol
|
8
|
-
$ coin
|
6
|
+
coin: 💰 A cryptocurrency price monitoring tools in the command line
|
7
|
+
$ coin symbol Find specific coin(s), eg: coin btc
|
8
|
+
$ coin To check the top 10 cryptocurrencies ranked by their market cap
|
9
|
+
$ coin -t [top] To query and display the number of cryptocurrencies ranked by market cap based on the 'top' parameter you input
|
10
|
+
$ coin-cli Coin's CLI, you can quickly query the symbol you want to search for
|
9
11
|
> enter the loop mode, ctrl+c to exit
|
10
12
|
HELP
|
11
13
|
|
12
14
|
if ARGV.empty?
|
13
|
-
|
14
|
-
loop do
|
15
|
-
print '> '
|
16
|
-
input = gets.chomp
|
17
|
-
next if input == ''
|
18
|
-
puts Blade::Coin.new(input).result
|
19
|
-
end
|
20
|
-
rescue Interrupt
|
21
|
-
puts 'bye bye'
|
22
|
-
end
|
15
|
+
puts Blade::Coin.new('').get_top_markets
|
23
16
|
elsif %w{-h --help}.any? { |c| ARGV.include? c }
|
24
17
|
puts help
|
18
|
+
elsif %w{-t --top}.any? { |c| ARGV.include? c }
|
19
|
+
index = ARGV.index('-t') || ARGV.index('--top')
|
20
|
+
top = ARGV[index + 1].to_i
|
21
|
+
puts Blade::Coin.new('').get_top_markets(top)
|
25
22
|
else
|
26
23
|
puts Blade::Coin.new(ARGV.join(' ')).result
|
27
24
|
end
|
data/bin/coin-cli
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/blade/coin'
|
4
|
+
|
5
|
+
if ARGV.empty?
|
6
|
+
begin
|
7
|
+
loop do
|
8
|
+
print '> '
|
9
|
+
input = gets.chomp
|
10
|
+
next if input == ''
|
11
|
+
puts Blade::Coin.new(input).result
|
12
|
+
end
|
13
|
+
rescue Interrupt
|
14
|
+
puts 'bye bye'
|
15
|
+
end
|
16
|
+
else
|
17
|
+
puts Blade::Coin.new(ARGV.join(' ')).result
|
18
|
+
end
|
data/blade_coin.gemspec
CHANGED
@@ -9,14 +9,12 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["sai"]
|
10
10
|
spec.email = ["rubyer1993@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = "
|
13
|
-
spec.description = "
|
12
|
+
spec.summary = "A cryptocurrency price monitoring tool"
|
13
|
+
spec.description = "A cryptocurrency price monitoring tool, you can run 'coin -h' for more help, or read the 'README.md'."
|
14
14
|
spec.homepage = "https://github.com/gith-u-b/blade_coin"
|
15
15
|
spec.license = "MIT"
|
16
|
-
spec.add_dependency 'rainbow'
|
17
|
-
|
18
|
-
# Specify which files should be added to the gem when it is released.
|
19
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.add_dependency 'rainbow', "~> 2.1.0"
|
17
|
+
spec.add_dependency 'terminal-table', '~> 1.8'
|
20
18
|
|
21
19
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
data/lib/blade/coin/version.rb
CHANGED
data/lib/blade/coin.rb
CHANGED
@@ -2,6 +2,7 @@ require "uri"
|
|
2
2
|
require "net/http"
|
3
3
|
require "json"
|
4
4
|
require "rainbow/ext/string"
|
5
|
+
require "terminal-table"
|
5
6
|
|
6
7
|
module Blade
|
7
8
|
class Coin
|
@@ -12,20 +13,61 @@ module Blade
|
|
12
13
|
|
13
14
|
def query_for_hash
|
14
15
|
query_url = get_mxc_single_market(@coin)
|
15
|
-
|
16
|
-
@result_hash = JSON.parse(result_json)
|
16
|
+
@result_hash = make_http_request(query_url)
|
17
17
|
end
|
18
18
|
|
19
19
|
def get_mxc_single_market(coin)
|
20
20
|
"https://www.mexc.com/open/api/v2/market/ticker?symbol=#{coin}_USDT"
|
21
21
|
end
|
22
22
|
|
23
|
+
def get_top_markets(top = 10)
|
24
|
+
query_url = "https://api.coincap.io/v2/assets?limit=#{top}"
|
25
|
+
result_json = make_http_request(query_url)
|
26
|
+
data = result_json[:data]
|
27
|
+
|
28
|
+
timestamp = result_json[:timestamp] / 1000 rescue ''
|
29
|
+
formatted_time = Time.at(timestamp).strftime("%I:%M:%S %p")
|
30
|
+
puts green_colorize("Data source from coincap.io at #{formatted_time}")
|
31
|
+
|
32
|
+
display_market_data(data)
|
33
|
+
end
|
34
|
+
|
35
|
+
def display_market_data(data)
|
36
|
+
title = '💰Wishing you prosperity and wealth(恭喜发财)💰'.color(226)
|
37
|
+
table = Terminal::Table.new(title: "\e[33m#{title}\e[0m") do |t|
|
38
|
+
t.headings = [orange_colorize('Rank'), orange_colorize('Coin'), orange_colorize('Price (USD)'), orange_colorize('ChangePercent24Hr'), orange_colorize('Vwap24Hr'), orange_colorize('Market Cap (USD)')]
|
39
|
+
t.rows = data.map do |d|
|
40
|
+
[
|
41
|
+
green_colorize(d[:rank] || 0),
|
42
|
+
green_colorize(d[:symbol] || 0),
|
43
|
+
green_colorize(format("%.4f", d[:priceUsd].to_f)),
|
44
|
+
yellow_colorize(format("%.2f", d[:changePercent24Hr].to_f)),
|
45
|
+
yellow_colorize(format("%.2f", d[:vwap24Hr].to_f)),
|
46
|
+
green_colorize(format("%.4f", d[:marketCapUsd].to_f))
|
47
|
+
]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
table
|
51
|
+
end
|
52
|
+
|
53
|
+
def green_colorize(str)
|
54
|
+
colorize(str, :green)
|
55
|
+
end
|
56
|
+
|
57
|
+
def orange_colorize(str)
|
58
|
+
colorize(str, :orange)
|
59
|
+
end
|
60
|
+
|
61
|
+
def yellow_colorize(str)
|
62
|
+
colorize(str, :yellow)
|
63
|
+
end
|
64
|
+
|
23
65
|
def usdt_result
|
24
|
-
return [] unless @result_hash[
|
66
|
+
return [] unless @result_hash[:data]
|
25
67
|
lines = []
|
26
|
-
data = @result_hash[
|
27
|
-
lines << data[
|
28
|
-
lines << data[
|
68
|
+
data = @result_hash[:data][0]
|
69
|
+
lines << data[:symbol].color(:red)
|
70
|
+
lines << data[:last].color(:green)
|
29
71
|
lines << ""
|
30
72
|
end
|
31
73
|
|
@@ -34,5 +76,14 @@ module Blade
|
|
34
76
|
output << usdt_result
|
35
77
|
output.flatten
|
36
78
|
end
|
79
|
+
|
80
|
+
def make_http_request(url)
|
81
|
+
response = Net::HTTP.get_response(URI(url))
|
82
|
+
JSON.parse(response.body, symbolize_names: true)
|
83
|
+
end
|
84
|
+
|
85
|
+
def colorize(str, color)
|
86
|
+
str.color(color) rescue ''
|
87
|
+
end
|
37
88
|
end
|
38
89
|
end
|
data/top_10.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blade_coin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sai
|
@@ -14,16 +14,30 @@ dependencies:
|
|
14
14
|
name: rainbow
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: terminal-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '1.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,11 +80,13 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '3.0'
|
69
|
-
description:
|
83
|
+
description: A cryptocurrency price monitoring tool, you can run 'coin -h' for more
|
84
|
+
help, or read the 'README.md'.
|
70
85
|
email:
|
71
86
|
- rubyer1993@gmail.com
|
72
87
|
executables:
|
73
88
|
- coin
|
89
|
+
- coin-cli
|
74
90
|
- console
|
75
91
|
- setup
|
76
92
|
extensions: []
|
@@ -85,11 +101,13 @@ files:
|
|
85
101
|
- README.md
|
86
102
|
- Rakefile
|
87
103
|
- bin/coin
|
104
|
+
- bin/coin-cli
|
88
105
|
- bin/console
|
89
106
|
- bin/setup
|
90
107
|
- blade_coin.gemspec
|
91
108
|
- lib/blade/coin.rb
|
92
109
|
- lib/blade/coin/version.rb
|
110
|
+
- top_10.png
|
93
111
|
homepage: https://github.com/gith-u-b/blade_coin
|
94
112
|
licenses:
|
95
113
|
- MIT
|
@@ -112,5 +130,5 @@ requirements: []
|
|
112
130
|
rubygems_version: 3.2.32
|
113
131
|
signing_key:
|
114
132
|
specification_version: 4
|
115
|
-
summary:
|
133
|
+
summary: A cryptocurrency price monitoring tool
|
116
134
|
test_files: []
|