sbi-security 0.0.2 → 0.0.3
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 +4 -3
- data/bin/sbisec +12 -23
- data/lib/sbi/security/cli.rb +20 -0
- data/lib/sbi/security/decorator/portfolio_decorator.rb +7 -0
- data/lib/sbi/security/decorator/stock_decorator.rb +20 -0
- data/lib/sbi/security/decorator.rb +7 -0
- data/lib/sbi/security/formatter.rb +17 -0
- data/lib/sbi/security/portfolio.rb +2 -0
- data/lib/sbi/security/stock.rb +1 -0
- data/lib/sbi/security/version.rb +1 -1
- data/lib/sbi/security.rb +7 -1
- data/sbi-security.gemspec +1 -0
- metadata +21 -3
- data/lib/sbi/security/format.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d73397285cf7f9d4161679ef56dd8560f7e54d7e
|
4
|
+
data.tar.gz: 1ec53a44798377bf9a5cf3ccc8f609860e8609b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56e12fdcf31161f47678fd62a6019b241eadd83acce0676264053ab6d8082a35ec336e23422b6ad1b87c9ddd1ecbef1eee953186200d773becc5e19d9bb88cfc
|
7
|
+
data.tar.gz: 3344d204d76a698457e975d5a18935046b9e4a4e1ba2cd2507a0c38ba54aa1d0275fd13842126a3c276325176c07e075abdf3fcf79eb7d53319851af55515cd4
|
data/README.md
CHANGED
@@ -26,8 +26,9 @@ Note: You need to set environment variables `SBI_SECURITY_USER_ID` and `SBI_SECU
|
|
26
26
|
|
27
27
|
### Show portfolio
|
28
28
|
|
29
|
-
```
|
30
|
-
sbisec
|
29
|
+
```bash
|
30
|
+
$ sbisec portfolio
|
31
|
+
|
31
32
|
+--------+--------------+------+----------+--------+--------+---------+---------+----------+-----------+
|
32
33
|
| コード | 銘柄 | 数量 | 参考単価 | 現在値 | 前日比 | 前日(%) | 損益 | 損益(%) | 評価額 |
|
33
34
|
+--------+--------------+------+----------+--------+--------+---------+---------+----------+-----------+
|
@@ -40,7 +41,7 @@ sbisec
|
|
40
41
|
- Implement `Sbi::Security::Client#buy`
|
41
42
|
- Implement `Sbi::Security::Client#sell`
|
42
43
|
- Update cli options
|
43
|
-
- Like `sbisec
|
44
|
+
- Like `sbisec buy 3633 3300 100` and `sbisec sell 3633 3000 100`
|
44
45
|
- Add test
|
45
46
|
|
46
47
|
## Contributing
|
data/bin/sbisec
CHANGED
@@ -2,31 +2,20 @@
|
|
2
2
|
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
3
|
|
4
4
|
require 'sbi/security'
|
5
|
-
require '
|
6
|
-
require 'terminal-table'
|
7
|
-
require 'colorize'
|
5
|
+
require 'commander'
|
8
6
|
|
9
|
-
|
7
|
+
Commander.configure do
|
8
|
+
program :name, 'CLI for SBI Security'
|
9
|
+
program :version, Sbi::Security::VERSION
|
10
|
+
program :description, 'You can check your portfolio.'
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
stock.code,
|
19
|
-
stock.name,
|
20
|
-
number_to_currency(stock.count),
|
21
|
-
number_to_currency(stock.value),
|
22
|
-
number_to_currency(stock.price),
|
23
|
-
format(stock.price_ratio),
|
24
|
-
format(stock.price_ratio_percentage),
|
25
|
-
format(stock.profit),
|
26
|
-
format(stock.profit_percentage),
|
27
|
-
number_to_currency(stock.total_value)
|
28
|
-
]
|
12
|
+
command :portfolio do |c|
|
13
|
+
c.syntax = 'sbisec portfolio'
|
14
|
+
c.description = 'Display your portfolio'
|
15
|
+
c.action do |args, options|
|
16
|
+
puts Sbi::Security::CLI.new(ENV["SBI_SECURITY_USER_ID"], ENV["SBI_SECURITY_PASSWORD"]).portfolio
|
17
|
+
end
|
18
|
+
end
|
29
19
|
end
|
30
20
|
|
31
|
-
puts Terminal::Table.new(rows: rows)
|
32
21
|
exit 0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sbi::Security
|
2
|
+
class CLI
|
3
|
+
def initialize(user_id, password)
|
4
|
+
@client = Sbi::Security::Client.new(user_id, password)
|
5
|
+
end
|
6
|
+
|
7
|
+
def portfolio
|
8
|
+
portfolio = @client.portfolio
|
9
|
+
|
10
|
+
rows = []
|
11
|
+
rows << portfolio.decorate.header
|
12
|
+
rows << :separator
|
13
|
+
portfolio.stocks.each do |stock|
|
14
|
+
rows << stock.decorate.format
|
15
|
+
end
|
16
|
+
|
17
|
+
Terminal::Table.new(rows: rows)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sbi::Security
|
2
|
+
class StockDecorator < SimpleDelegator
|
3
|
+
include Sbi::Security::Formatter
|
4
|
+
|
5
|
+
def format
|
6
|
+
[
|
7
|
+
code,
|
8
|
+
name,
|
9
|
+
currency(count),
|
10
|
+
currency(value),
|
11
|
+
currency(price),
|
12
|
+
sign(price_ratio),
|
13
|
+
sign(price_ratio_percentage),
|
14
|
+
sign(profit),
|
15
|
+
sign(profit_percentage),
|
16
|
+
currency(total_value)
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Sbi::Security
|
2
|
+
module Formatter
|
3
|
+
def currency(number)
|
4
|
+
number.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,')
|
5
|
+
end
|
6
|
+
|
7
|
+
def sign(number)
|
8
|
+
if number.to_i == 0
|
9
|
+
number.to_s
|
10
|
+
elsif number < 0
|
11
|
+
currency(number).colorize(:blue)
|
12
|
+
else
|
13
|
+
"+#{currency(number)}".colorize(:red)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/sbi/security/stock.rb
CHANGED
data/lib/sbi/security/version.rb
CHANGED
data/lib/sbi/security.rb
CHANGED
@@ -2,7 +2,8 @@ require "capybara"
|
|
2
2
|
require 'capybara/dsl'
|
3
3
|
require 'selenium-webdriver'
|
4
4
|
require 'virtus'
|
5
|
-
require '
|
5
|
+
require 'terminal-table'
|
6
|
+
require 'colorize'
|
6
7
|
|
7
8
|
module Sbi
|
8
9
|
module Security
|
@@ -10,7 +11,12 @@ module Sbi
|
|
10
11
|
end
|
11
12
|
|
12
13
|
require "sbi/security/client"
|
14
|
+
require "sbi/security/cli"
|
13
15
|
require "sbi/security/crawler"
|
16
|
+
require "sbi/security/formatter"
|
17
|
+
require "sbi/security/decorator"
|
18
|
+
require "sbi/security/decorator/portfolio_decorator"
|
19
|
+
require "sbi/security/decorator/stock_decorator"
|
14
20
|
require "sbi/security/portfolio"
|
15
21
|
require "sbi/security/stock"
|
16
22
|
require "sbi/security/version"
|
data/sbi-security.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "virtus", "~> 1.0"
|
25
25
|
spec.add_dependency "terminal-table", "~> 1.8"
|
26
26
|
spec.add_dependency "colorize", "~> 0.8"
|
27
|
+
spec.add_dependency "commander", "~> 4.4"
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.15"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbi-security
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- camelmasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: commander
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.4'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.4'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,9 +152,13 @@ files:
|
|
138
152
|
- Rakefile
|
139
153
|
- bin/sbisec
|
140
154
|
- lib/sbi/security.rb
|
155
|
+
- lib/sbi/security/cli.rb
|
141
156
|
- lib/sbi/security/client.rb
|
142
157
|
- lib/sbi/security/crawler.rb
|
143
|
-
- lib/sbi/security/
|
158
|
+
- lib/sbi/security/decorator.rb
|
159
|
+
- lib/sbi/security/decorator/portfolio_decorator.rb
|
160
|
+
- lib/sbi/security/decorator/stock_decorator.rb
|
161
|
+
- lib/sbi/security/formatter.rb
|
144
162
|
- lib/sbi/security/portfolio.rb
|
145
163
|
- lib/sbi/security/stock.rb
|
146
164
|
- lib/sbi/security/version.rb
|
data/lib/sbi/security/format.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Sbi::Security
|
2
|
-
module Format
|
3
|
-
def format(number)
|
4
|
-
if number.nil? || number == 0
|
5
|
-
return number.to_s
|
6
|
-
end
|
7
|
-
|
8
|
-
if number > 0
|
9
|
-
"+#{number_to_currency(number)}".colorize(:red)
|
10
|
-
else
|
11
|
-
"#{number_to_currency(number)}".colorize(:blue)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def number_to_currency(number)
|
16
|
-
number.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|