capwatch 0.2.3 → 0.2.4
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/README.md +3 -3
- data/bin/console +3 -8
- data/capwatch.gemspec +1 -0
- data/exe/capwatch +2 -2
- data/lib/capwatch.rb +1 -2
- data/lib/capwatch/fund.rb +19 -5
- data/lib/capwatch/fund/config.rb +105 -0
- data/lib/capwatch/telegram.rb +1 -1
- data/lib/capwatch/version.rb +1 -1
- metadata +17 -4
- data/lib/capwatch/fund_calculator.rb +0 -31
- data/lib/capwatch/fund_config.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1948bc7ce49d8876cac71b83efadf1614338e50
|
4
|
+
data.tar.gz: 21cc5c7ce8e803633586e33cf72c603bd228a12a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 077e0e4685f19bf2e9ba99f99293879c501afccc0c0410ab2fb1a8d74508fbd02a002b75f4c58b7459671c6f5491ed7ea1f51013d90b5081165f93b396eba431
|
7
|
+
data.tar.gz: 909f0362a1623819a41d3024a1d9263436655fa525dfb27965b3d0bdcac0da4cf0a03ffe26c6cbf54065151493c2c63b79c10f636f497fcf68e4efff6465eda1
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Capwatch
|
2
2
|
|
3
3
|
[](https://travis-ci.org/bugaiov/capwatch)
|
4
|
-
[](https://coveralls.io/github/bugaiov/capwatch)
|
5
5
|
[](https://badge.fury.io/rb/capwatch)
|
6
6
|
|
7
7
|
Watch your cryptoportfolio in a console
|
@@ -13,7 +13,7 @@ Watch your cryptoportfolio in a console
|
|
13
13
|
$ gem install capwatch
|
14
14
|
$ capwatch
|
15
15
|
|
16
|
-
Don't forget to edit `~/.capwatch` with
|
16
|
+
Don't forget to edit `~/.capwatch` with a number of cryptocurrencies you hold.
|
17
17
|
|
18
18
|
## Telegram
|
19
19
|
|
@@ -25,7 +25,7 @@ If you want to get portfolio notifications on demand into your telegram, you'll
|
|
25
25
|
|
26
26
|
$capwatch -e <bot_token>
|
27
27
|
|
28
|
-
Currently Capwatch supports only two commands
|
28
|
+
Currently, Capwatch supports only two commands
|
29
29
|
|
30
30
|
- `/watch` - shows the entire portfolio
|
31
31
|
- `/cap` - shows only the footer of the portfolio, e.g. summaries
|
data/bin/console
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require "bundler/setup"
|
5
4
|
require "capwatch"
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
include Capwatch
|
7
|
+
require "pry"
|
9
8
|
|
10
|
-
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
9
|
+
Pry.start
|
13
10
|
|
14
|
-
require "irb"
|
15
|
-
IRB.start(__FILE__)
|
data/capwatch.gemspec
CHANGED
data/exe/capwatch
CHANGED
@@ -16,12 +16,12 @@ if options.telegram
|
|
16
16
|
Telegram.new(options.telegram).start
|
17
17
|
else
|
18
18
|
loop do
|
19
|
-
config =
|
19
|
+
config = Fund::Config.new
|
20
20
|
provider = Providers::CoinMarketCap.new
|
21
21
|
fund = Fund.new(provider: provider, config: config)
|
22
22
|
system("clear")
|
23
23
|
puts fund.console_table
|
24
|
-
puts "\nHey there! This is a Demo Fund. Please set up your fund by editing the \"#{
|
24
|
+
puts "\nHey there! This is a Demo Fund. Please set up your fund by editing the \"#{Fund::Config::Local::FILE_NAME}\" in your home directory".green if config.demo?
|
25
25
|
sleep options.tick
|
26
26
|
end
|
27
27
|
end
|
data/lib/capwatch.rb
CHANGED
@@ -6,8 +6,7 @@ require "telegram_bot"
|
|
6
6
|
|
7
7
|
require "capwatch/version"
|
8
8
|
require "capwatch/fund"
|
9
|
-
require "capwatch/
|
10
|
-
require "capwatch/fund_calculator"
|
9
|
+
require "capwatch/fund/config"
|
11
10
|
require "capwatch/providers/coin_market_cap"
|
12
11
|
require "capwatch/exchange"
|
13
12
|
require "capwatch/cli"
|
data/lib/capwatch/fund.rb
CHANGED
@@ -41,13 +41,27 @@ module Capwatch
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def build
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
assign_quantity
|
45
|
+
assign_prices
|
46
|
+
distribution
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
|
49
|
+
def assign_quantity
|
50
|
+
coins.each do |coin|
|
51
|
+
coin.quantity = positions[coin.symbol]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def assign_prices
|
56
|
+
coins.each do |coin|
|
57
|
+
provider.update_coin(coin)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def distribution
|
62
|
+
coins.each do |coin|
|
63
|
+
coin.distribution = coin.value_btc / value_btc
|
64
|
+
end
|
51
65
|
end
|
52
66
|
|
53
67
|
def serialize
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Capwatch
|
6
|
+
class Fund
|
7
|
+
class Config
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
attr_reader :parser, :source
|
11
|
+
def_delegators :@parser, :name, :positions, :name=, :positions=
|
12
|
+
|
13
|
+
def initialize(source: nil)
|
14
|
+
@source = source || dynamic_source
|
15
|
+
@parser = Parser.new(source: dynamic_source)
|
16
|
+
end
|
17
|
+
|
18
|
+
def dynamic_source
|
19
|
+
File.exist?(File.expand_path((Remote::FILE_NAME))) ? Remote.new : Local.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def coins
|
23
|
+
positions.map do |symbol, quantity|
|
24
|
+
Coin.new do |coin|
|
25
|
+
coin.symbol = symbol
|
26
|
+
coin.quantity = quantity
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def demo?
|
32
|
+
name == Demo::NAME
|
33
|
+
end
|
34
|
+
|
35
|
+
class Parser
|
36
|
+
attr_accessor :name, :positions, :raw_data
|
37
|
+
|
38
|
+
def initialize(source:)
|
39
|
+
@raw_data = source.get_data
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse
|
43
|
+
@parse ||= JSON.parse(raw_data)
|
44
|
+
end
|
45
|
+
|
46
|
+
def positions
|
47
|
+
@positions ||= parse["symbols"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def name
|
51
|
+
@name ||= parse["name"]
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class Remote
|
57
|
+
FILE_NAME = "~/.capwatch.remote"
|
58
|
+
|
59
|
+
def fetch(remote_url)
|
60
|
+
open(remote_url).read
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_data
|
64
|
+
remote_file_url = File.open(File.expand_path(FILE_NAME)).read.strip
|
65
|
+
fetch(remote_file_url)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
class Local
|
71
|
+
FILE_NAME = "~/.capwatch"
|
72
|
+
|
73
|
+
def get_data
|
74
|
+
create_demo_file!
|
75
|
+
File.open(File.expand_path(FILE_NAME)).read
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_demo_file!
|
79
|
+
Demo.new.create_demo_config unless File.exist?(File.expand_path((Local::FILE_NAME)))
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
class Demo
|
85
|
+
NAME = "Your Demo Fund"
|
86
|
+
|
87
|
+
def demo_fund_raw_data
|
88
|
+
file_path = File.join(__dir__, "..", "..", "funds", "basic.json")
|
89
|
+
demo_fund = File.expand_path(file_path)
|
90
|
+
File.open(demo_fund).read
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_demo_config
|
94
|
+
file_name = File.expand_path(Local::FILE_NAME)
|
95
|
+
File.open(file_name, "w") do |file|
|
96
|
+
file.write(demo_fund_raw_data.gsub!("Basic Fund", NAME))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
data/lib/capwatch/telegram.rb
CHANGED
data/lib/capwatch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capwatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Bugaiov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fakefs
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.11'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.11'
|
111
125
|
description: Watches your cryptoportfolio
|
112
126
|
email:
|
113
127
|
- nick@bugaiov.com
|
@@ -134,8 +148,7 @@ files:
|
|
134
148
|
- lib/capwatch/console.rb
|
135
149
|
- lib/capwatch/exchange.rb
|
136
150
|
- lib/capwatch/fund.rb
|
137
|
-
- lib/capwatch/
|
138
|
-
- lib/capwatch/fund_config.rb
|
151
|
+
- lib/capwatch/fund/config.rb
|
139
152
|
- lib/capwatch/providers/coin_market_cap.rb
|
140
153
|
- lib/capwatch/telegram.rb
|
141
154
|
- lib/capwatch/version.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Capwatch
|
4
|
-
class FundCalculator
|
5
|
-
|
6
|
-
attr_accessor :fund
|
7
|
-
|
8
|
-
def initialize(fund)
|
9
|
-
@fund = fund
|
10
|
-
end
|
11
|
-
|
12
|
-
def assign_quantity
|
13
|
-
fund.coins.each do |coin|
|
14
|
-
coin.quantity = fund.positions[coin.symbol]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def assign_prices
|
19
|
-
fund.coins.each do |coin|
|
20
|
-
fund.provider.update_coin(coin)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def distribution
|
25
|
-
fund.coins.each do |coin|
|
26
|
-
coin.distribution = coin.value_btc / fund.value_btc
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/capwatch/fund_config.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Capwatch
|
4
|
-
class FundConfig
|
5
|
-
|
6
|
-
DEMO_CONFIG_NAME = "Your Demo Fund"
|
7
|
-
DEMO_CONFIG_FILE = "~/.capwatch"
|
8
|
-
|
9
|
-
attr_accessor :name, :positions, :config_path
|
10
|
-
|
11
|
-
def initialize(config_path = nil)
|
12
|
-
@config_path = config_path || File.expand_path(DEMO_CONFIG_FILE)
|
13
|
-
demo_config! unless config_exists?
|
14
|
-
end
|
15
|
-
|
16
|
-
def positions
|
17
|
-
@positions ||= parsed_config["symbols"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def name
|
21
|
-
@name ||= parsed_config["name"]
|
22
|
-
end
|
23
|
-
|
24
|
-
def parsed_config
|
25
|
-
parse @config_path
|
26
|
-
end
|
27
|
-
|
28
|
-
def coins
|
29
|
-
positions.map do |symbol, quantity|
|
30
|
-
Coin.new do |coin|
|
31
|
-
coin.symbol = symbol
|
32
|
-
coin.quantity = quantity
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def demo?
|
38
|
-
name == DEMO_CONFIG_NAME
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def open_config(path)
|
44
|
-
File.open(path).read
|
45
|
-
end
|
46
|
-
|
47
|
-
def parse(path)
|
48
|
-
JSON.parse open_config(path)
|
49
|
-
end
|
50
|
-
|
51
|
-
def config_exists?
|
52
|
-
File.exist? @config_path
|
53
|
-
end
|
54
|
-
|
55
|
-
def demo_fund
|
56
|
-
file_path = File.join(__dir__, "..", "..", "lib", "funds", "basic.json")
|
57
|
-
demo_fund = File.expand_path(file_path)
|
58
|
-
File.open(demo_fund).read
|
59
|
-
end
|
60
|
-
|
61
|
-
def demo_config!
|
62
|
-
@config_path = File.expand_path(@config_path)
|
63
|
-
File.open(@config_path, "w") do |file|
|
64
|
-
file.write(demo_fund.gsub!("Basic Fund", DEMO_CONFIG_NAME))
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|