capwatch 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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capwatch.gemspec +31 -0
- data/exe/capwatch +14 -0
- data/lib/capwatch.rb +211 -0
- data/lib/capwatch/version.rb +3 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a934d8a761e346d0ab2dcb852fe541d32c07954f
|
4
|
+
data.tar.gz: 8f054359548fbfa45509f2e51b77b9494dc6442d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99e5575e7dd8128827d981708964e2196a3fbe28d7d00346e55a46bc328b8cc9b05871f3ff8612d1303e60af2aa0ee69b977aca670627af47b6e8263da9a7918
|
7
|
+
data.tar.gz: 4da02578277a26144ce9bf0110607ece20cb215840f65415f0aa8937d4e2ac738a1a53e158370c3578126d5647001ae31e8d06a0f4a759d6da84768f8d645cb5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Nick Bugaiov
|
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,38 @@
|
|
1
|
+
# Capwatch
|
2
|
+
|
3
|
+
Watch you cryptoportfolio in a console
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install capwatch
|
8
|
+
|
9
|
+
```bash
|
10
|
+
cat <<EOT > ~/.capwatch
|
11
|
+
{
|
12
|
+
"name": "My Fund",
|
13
|
+
"symbols": {
|
14
|
+
"ETH": 10,
|
15
|
+
"BTC": 10,
|
16
|
+
"XRP": 1,
|
17
|
+
"LTC": 1,
|
18
|
+
"ETC": 1,
|
19
|
+
"DASH": 1,
|
20
|
+
"XEM": 1,
|
21
|
+
"MIOTA": 1,
|
22
|
+
"XMR": 1,
|
23
|
+
"STRAT": 1,
|
24
|
+
"BCC": 1,
|
25
|
+
"EOS": 1,
|
26
|
+
"USDT": 1,
|
27
|
+
"ZEC": 1,
|
28
|
+
"ANS": 1,
|
29
|
+
"VERI": 1,
|
30
|
+
"BTS": 1,
|
31
|
+
"STEEM": 1,
|
32
|
+
"BCN": 1
|
33
|
+
}
|
34
|
+
}
|
35
|
+
EOT
|
36
|
+
```
|
37
|
+
|
38
|
+
$ capwatch
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'capwatch'
|
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/capwatch.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capwatch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'capwatch'
|
8
|
+
spec.version = Capwatch::VERSION
|
9
|
+
spec.authors = ['Nick Bugaiov']
|
10
|
+
spec.email = ['nick@bugaiov.com']
|
11
|
+
|
12
|
+
spec.summary = 'Cryptoportfolio watch'
|
13
|
+
spec.description = 'Watches your cryptoportfolio'
|
14
|
+
spec.homepage = 'https://cryptowatch.one'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'terminal-table', '~> 1.8'
|
26
|
+
spec.add_dependency 'colorize', '~> 0.8'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
end
|
data/exe/capwatch
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'capwatch'
|
4
|
+
include Capwatch
|
5
|
+
|
6
|
+
options = CLI.parse(ARGV)
|
7
|
+
fund = JSON.parse(File.open(ARGV[0] || File.expand_path('~/.capwatch')).read)
|
8
|
+
|
9
|
+
loop do
|
10
|
+
table = Calculator.fund_hash(fund, CoinMarketCap.fetch)
|
11
|
+
system('clear')
|
12
|
+
puts Console.draw_table(table)
|
13
|
+
sleep options.tick
|
14
|
+
end
|
data/lib/capwatch.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'terminal-table'
|
3
|
+
|
4
|
+
require 'capwatch/version'
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
require 'optparse'
|
8
|
+
require 'ostruct'
|
9
|
+
require 'net/http'
|
10
|
+
|
11
|
+
module Capwatch
|
12
|
+
class Calculator
|
13
|
+
def self.fund_hash(fund, coinmarketcap_json)
|
14
|
+
table_array = []
|
15
|
+
|
16
|
+
title = fund['name']
|
17
|
+
symbols = fund['symbols']
|
18
|
+
fund_keys = symbols.keys
|
19
|
+
|
20
|
+
price_eth_btc = coinmarketcap_json.find do |x|
|
21
|
+
x['symbol'] == 'ETH'
|
22
|
+
end['price_usd'].to_f
|
23
|
+
|
24
|
+
filtered_response_json = coinmarketcap_json.select do |x|
|
25
|
+
fund_keys.include?(x['symbol'])
|
26
|
+
end
|
27
|
+
|
28
|
+
total_value_usd = filtered_response_json.inject(0) do |sum, n|
|
29
|
+
sum + symbols[n['symbol']] * n['price_usd'].to_f
|
30
|
+
end
|
31
|
+
|
32
|
+
total_value_btc = filtered_response_json.inject(0) do |sum, n|
|
33
|
+
sum + symbols[n['symbol']] * n['price_btc'].to_f
|
34
|
+
end
|
35
|
+
|
36
|
+
total_value_eth = filtered_response_json.inject(0) do |sum, n|
|
37
|
+
sum + symbols[n['symbol']] * n['price_usd'].to_f / price_eth_btc
|
38
|
+
end
|
39
|
+
|
40
|
+
distribution_hash = {}
|
41
|
+
|
42
|
+
fund_keys.each do |x|
|
43
|
+
x = filtered_response_json.find { |e| e['symbol'] == x }
|
44
|
+
symbol = x['symbol']
|
45
|
+
asset_name = "#{x['name']} (#{symbol})"
|
46
|
+
quant_value = symbols[symbol]
|
47
|
+
price = x['price_usd'].to_f
|
48
|
+
value_btc = quant_value * x['price_btc'].to_f
|
49
|
+
value_eth = quant_value * x['price_usd'].to_f / price_eth_btc
|
50
|
+
value_usd = quant_value * x['price_usd'].to_f
|
51
|
+
distribution_float = value_usd / total_value_usd
|
52
|
+
distribution_hash[symbol] = distribution_float
|
53
|
+
distribution = distribution_float * 100
|
54
|
+
percent_change_1h = x['percent_change_1h'].to_f || 0
|
55
|
+
percent_change_24h = x['percent_change_24h'].to_f || 0
|
56
|
+
percent_change_7d = x['percent_change_7d'].to_f || 0
|
57
|
+
table_array << [
|
58
|
+
asset_name,
|
59
|
+
quant_value,
|
60
|
+
price,
|
61
|
+
value_usd,
|
62
|
+
value_btc,
|
63
|
+
value_eth,
|
64
|
+
distribution,
|
65
|
+
percent_change_1h,
|
66
|
+
percent_change_24h,
|
67
|
+
percent_change_7d
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
a_1h = filtered_response_json.inject(0) do |sum, n|
|
72
|
+
sum + n['percent_change_1h'].to_f * distribution_hash[n['symbol']].to_f
|
73
|
+
end
|
74
|
+
|
75
|
+
a_24h = filtered_response_json.inject(0) do |sum, n|
|
76
|
+
sum + n['percent_change_24h'].to_f * distribution_hash[n['symbol']].to_f
|
77
|
+
end
|
78
|
+
|
79
|
+
a_7d = filtered_response_json.inject(0) do |sum, n|
|
80
|
+
sum + n['percent_change_7d'].to_f * distribution_hash[n['symbol']].to_f
|
81
|
+
end
|
82
|
+
|
83
|
+
footer_row = [
|
84
|
+
'',
|
85
|
+
'',
|
86
|
+
'',
|
87
|
+
total_value_usd,
|
88
|
+
total_value_btc,
|
89
|
+
total_value_eth,
|
90
|
+
'',
|
91
|
+
a_1h,
|
92
|
+
a_24h,
|
93
|
+
a_7d
|
94
|
+
]
|
95
|
+
|
96
|
+
table_array.sort_by! { |a| -a[6].to_f } # DIST (%)
|
97
|
+
|
98
|
+
{}
|
99
|
+
.merge(title: title)
|
100
|
+
.merge(table_array: table_array)
|
101
|
+
.merge(footer_row: footer_row)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class CLI
|
106
|
+
def self.parse(args)
|
107
|
+
options = OpenStruct.new
|
108
|
+
options.tick = 60 * 5
|
109
|
+
opt_parser = OptionParser.new do |opts|
|
110
|
+
opts.on('-t', '--tick [Integer]', Integer, 'Tick Interval') do |t|
|
111
|
+
options.tick = t
|
112
|
+
end
|
113
|
+
end
|
114
|
+
opt_parser.parse!(args)
|
115
|
+
options
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class CoinMarketCap
|
120
|
+
def self.fetch
|
121
|
+
JSON.parse(Net::HTTP.get(URI('http://api.coinmarketcap.com/v1/ticker/')))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
module ConsoleFormatter
|
126
|
+
def fmt(n)
|
127
|
+
'$' + n.round(2).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
128
|
+
end
|
129
|
+
|
130
|
+
def format_btc(value)
|
131
|
+
format('฿%.2f', value)
|
132
|
+
end
|
133
|
+
|
134
|
+
def format_eth(value)
|
135
|
+
format('Ξ%.2f', value)
|
136
|
+
end
|
137
|
+
|
138
|
+
def format_percent(value)
|
139
|
+
format('%.2f%', value)
|
140
|
+
end
|
141
|
+
|
142
|
+
def condition_color(value)
|
143
|
+
percent_value = value.to_f
|
144
|
+
if percent_value > 1
|
145
|
+
value.green
|
146
|
+
elsif percent_value < 0
|
147
|
+
value.red
|
148
|
+
else
|
149
|
+
value.green
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class Console
|
155
|
+
extend ConsoleFormatter
|
156
|
+
|
157
|
+
def self.colorize_table(hash)
|
158
|
+
hash[:table_array].each do |x|
|
159
|
+
x[2] = fmt(x[2])
|
160
|
+
x[3] = fmt(x[3])
|
161
|
+
x[4] = format_btc(x[4])
|
162
|
+
x[5] = format_eth(x[5])
|
163
|
+
x[6] = format_percent(x[6])
|
164
|
+
x[7] = condition_color(format_percent(x[7]))
|
165
|
+
x[8] = condition_color(format_percent(x[8]))
|
166
|
+
x[9] = condition_color(format_percent(x[9]))
|
167
|
+
end
|
168
|
+
hash[:footer_row][3] = fmt(hash[:footer_row][3])
|
169
|
+
hash[:footer_row][4] = format_btc(hash[:footer_row][4])
|
170
|
+
hash[:footer_row][5] = format_eth(hash[:footer_row][5])
|
171
|
+
hash[:footer_row][7] = condition_color(format_percent(hash[:footer_row][7]))
|
172
|
+
hash[:footer_row][8] = condition_color(format_percent(hash[:footer_row][8]))
|
173
|
+
hash[:footer_row][9] = condition_color(format_percent(hash[:footer_row][9]))
|
174
|
+
hash
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.draw_table(hash)
|
178
|
+
hash = colorize_table(hash)
|
179
|
+
table = Terminal::Table.new do |t|
|
180
|
+
t.title = hash[:title].upcase
|
181
|
+
t.style = {
|
182
|
+
border_top: false,
|
183
|
+
border_bottom: false,
|
184
|
+
border_y: '',
|
185
|
+
border_i: '',
|
186
|
+
padding_left: 1,
|
187
|
+
padding_right: 1
|
188
|
+
}
|
189
|
+
t.headings = [
|
190
|
+
'ASSET',
|
191
|
+
'QUANTITY',
|
192
|
+
'PRICE',
|
193
|
+
'VALUE (USD)',
|
194
|
+
'VALUE (BTC)',
|
195
|
+
'VALUE (ETH)',
|
196
|
+
'DIST (%)',
|
197
|
+
'%(1H)',
|
198
|
+
'%(24H)',
|
199
|
+
'%(7D)'
|
200
|
+
]
|
201
|
+
hash[:table_array].each do |x|
|
202
|
+
t << x
|
203
|
+
end
|
204
|
+
t.add_separator
|
205
|
+
t.add_row hash[:footer_row]
|
206
|
+
end
|
207
|
+
|
208
|
+
table
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capwatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Bugaiov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: terminal-table
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.15'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.15'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Watches your cryptoportfolio
|
84
|
+
email:
|
85
|
+
- nick@bugaiov.com
|
86
|
+
executables:
|
87
|
+
- capwatch
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- capwatch.gemspec
|
101
|
+
- exe/capwatch
|
102
|
+
- lib/capwatch.rb
|
103
|
+
- lib/capwatch/version.rb
|
104
|
+
homepage: https://cryptowatch.one
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.11
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Cryptoportfolio watch
|
128
|
+
test_files: []
|