sbi-security 0.0.3 → 0.0.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 +13 -1
- data/bin/sbisec +8 -0
- data/lib/sbi/security.rb +2 -0
- data/lib/sbi/security/cli.rb +11 -0
- data/lib/sbi/security/client.rb +4 -0
- data/lib/sbi/security/crawler.rb +46 -15
- data/lib/sbi/security/decorator/portfolio_stock_decorator.rb +20 -0
- data/lib/sbi/security/decorator/stock_decorator.rb +10 -5
- data/lib/sbi/security/formatter.rb +3 -3
- data/lib/sbi/security/portfolio_stock.rb +21 -0
- data/lib/sbi/security/stock.rb +6 -6
- data/lib/sbi/security/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c1e960daaccd91b38d3c574cba635d29e393737
|
4
|
+
data.tar.gz: 0c146bc14278e453047aaa327b3a35b7944364d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a62fb8304e2319b90f4856fb8e9d7a86afdbd0ebaf5074776a8b2fc58d3de258d58ee9cf4ef875ee1daec9cdc409e1177e786fb7707ae6050757c34dfd6803c9
|
7
|
+
data.tar.gz: cefa0c2a8db7d326752c02ef95e5e38ea19f80d058e44e3cf8ff3c2baf23f641f9ac13920c8b5468d9a0c459b0fa3bb91154b1a895d39b1873d2da64de3e345b
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Note: You need to set environment variables `SBI_SECURITY_USER_ID` and `SBI_SECU
|
|
26
26
|
|
27
27
|
### Show portfolio
|
28
28
|
|
29
|
-
```
|
29
|
+
```
|
30
30
|
$ sbisec portfolio
|
31
31
|
|
32
32
|
+--------+--------------+------+----------+--------+--------+---------+---------+----------+-----------+
|
@@ -36,6 +36,18 @@ $ sbisec portfolio
|
|
36
36
|
+--------+--------------+------+----------+--------+--------+---------+---------+----------+-----------+
|
37
37
|
```
|
38
38
|
|
39
|
+
### Show stock
|
40
|
+
|
41
|
+
$ sbisec stock 3633
|
42
|
+
|
43
|
+
```
|
44
|
+
+--------+--------------+--------+--------+---------+-------+-------+-------+----------+--------+-----------+
|
45
|
+
| コード | 銘柄 | 現在値 | 前日比 | 前日(%) | 始値 | 高値 | 安値 | 前日終値 | 出来高 | 売買代金 |
|
46
|
+
+--------+--------------+--------+--------+---------+-------+-------+-------+----------+--------+-----------+
|
47
|
+
| 3633 | GMOペパボ | 3,390 | -20 | -0.59 | 3,405 | 3,405 | 3,380 | 3,410 | 500 | 1,696,000 |
|
48
|
+
+--------+--------------+--------+--------+---------+-------+-------+-------+----------+--------+-----------+
|
49
|
+
```
|
50
|
+
|
39
51
|
## TODO
|
40
52
|
|
41
53
|
- Implement `Sbi::Security::Client#buy`
|
data/bin/sbisec
CHANGED
@@ -16,6 +16,14 @@ Commander.configure do
|
|
16
16
|
puts Sbi::Security::CLI.new(ENV["SBI_SECURITY_USER_ID"], ENV["SBI_SECURITY_PASSWORD"]).portfolio
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
command :stock do |c|
|
21
|
+
c.syntax = 'sbisec stock [code]'
|
22
|
+
c.description = 'Display stock information'
|
23
|
+
c.action do |args, options|
|
24
|
+
puts Sbi::Security::CLI.new(ENV["SBI_SECURITY_USER_ID"], ENV["SBI_SECURITY_PASSWORD"]).stock(args.first)
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|
20
28
|
|
21
29
|
exit 0
|
data/lib/sbi/security.rb
CHANGED
@@ -16,7 +16,9 @@ require "sbi/security/crawler"
|
|
16
16
|
require "sbi/security/formatter"
|
17
17
|
require "sbi/security/decorator"
|
18
18
|
require "sbi/security/decorator/portfolio_decorator"
|
19
|
+
require "sbi/security/decorator/portfolio_stock_decorator"
|
19
20
|
require "sbi/security/decorator/stock_decorator"
|
20
21
|
require "sbi/security/portfolio"
|
22
|
+
require "sbi/security/portfolio_stock"
|
21
23
|
require "sbi/security/stock"
|
22
24
|
require "sbi/security/version"
|
data/lib/sbi/security/cli.rb
CHANGED
@@ -16,5 +16,16 @@ module Sbi::Security
|
|
16
16
|
|
17
17
|
Terminal::Table.new(rows: rows)
|
18
18
|
end
|
19
|
+
|
20
|
+
def stock(code)
|
21
|
+
stock = @client.stock(code)
|
22
|
+
|
23
|
+
rows = []
|
24
|
+
rows << stock.decorate.header
|
25
|
+
rows << :separator
|
26
|
+
rows << stock.decorate.format
|
27
|
+
|
28
|
+
Terminal::Table.new(rows: rows)
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
data/lib/sbi/security/client.rb
CHANGED
data/lib/sbi/security/crawler.rb
CHANGED
@@ -19,30 +19,57 @@ module Sbi::Security
|
|
19
19
|
def portfolio
|
20
20
|
find("img[title='ポートフォリオ']").click
|
21
21
|
|
22
|
-
stocks = page.all(:xpath, '//table[@width="100%"]/tbody/tr[@align="center"]').each_with_index.map do |tr, i|
|
23
|
-
# Ignore title row
|
24
|
-
next if i == 0
|
25
|
-
|
22
|
+
stocks = page.all(:xpath, '//table[@width="100%"]/tbody/tr[@align="center"]').drop(1).each_with_index.map do |tr, i|
|
26
23
|
_, code_and_name, _, count, value, price, price_ratio, price_ratio_percentage, profit, profit_percentage,
|
27
|
-
total_value = tr.all("td").map(
|
24
|
+
total_value = tr.all("td").map { |td| td.text.gsub(/,/, "") }
|
28
25
|
|
29
|
-
|
26
|
+
PortfolioStock.new(
|
30
27
|
code: code_and_name.split(" ").first,
|
31
28
|
name: code_and_name.split(" ").last,
|
32
|
-
count: count
|
33
|
-
value: value
|
34
|
-
price: price
|
35
|
-
price_ratio: (price_ratio
|
36
|
-
price_ratio_percentage: (price_ratio_percentage
|
37
|
-
profit: profit
|
38
|
-
profit_percentage: profit_percentage
|
39
|
-
total_value: total_value
|
29
|
+
count: count,
|
30
|
+
value: value,
|
31
|
+
price: price,
|
32
|
+
price_ratio: empty_string_to_num(price_ratio).to_i,
|
33
|
+
price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
|
34
|
+
profit: profit,
|
35
|
+
profit_percentage: profit_percentage,
|
36
|
+
total_value: total_value
|
40
37
|
)
|
41
|
-
end
|
38
|
+
end
|
42
39
|
|
43
40
|
Portfolio.new(stocks)
|
44
41
|
end
|
45
42
|
|
43
|
+
def stock(code)
|
44
|
+
fill_in :i_stock_sec, with: code
|
45
|
+
find("img[title='株価検索']").click
|
46
|
+
|
47
|
+
# SBI security has XHR for fetching information. Need to wait until page finish to emulate JavaScript.
|
48
|
+
loop do
|
49
|
+
if page.find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text != "--"
|
50
|
+
break
|
51
|
+
end
|
52
|
+
sleep 1
|
53
|
+
end
|
54
|
+
|
55
|
+
price_ratio, price_ratio_percentage = page.all(:xpath, "//td[@id='MTB0_1']/p/span").map { |td| td.text.gsub(/,/, "") }
|
56
|
+
start_price, end_price, highest_price, total_stock, lowest_price, total_price = page.all(:xpath, "//table[@class='tbl690']/tbody/tr/td/p/span[@class='fm01']").map { |td| td.text.gsub(/,/, "") }
|
57
|
+
|
58
|
+
Stock.new(
|
59
|
+
code: code,
|
60
|
+
name: page.find(:xpath, "//h3/span[@class='fxx01']").text,
|
61
|
+
price: page.find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text.gsub(/,/, ""),
|
62
|
+
price_ratio: empty_string_to_num(price_ratio).to_i,
|
63
|
+
price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
|
64
|
+
start_price: start_price.to_i,
|
65
|
+
end_price: end_price,
|
66
|
+
highest_price: highest_price.to_i,
|
67
|
+
total_stock: total_stock.to_i,
|
68
|
+
lowest_price: lowest_price.to_i,
|
69
|
+
total_price: total_price.to_i * 1000
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
46
73
|
private
|
47
74
|
|
48
75
|
def login(user_id, password)
|
@@ -51,5 +78,9 @@ module Sbi::Security
|
|
51
78
|
fill_in :user_password, with: password
|
52
79
|
find_button(class: "ov").click
|
53
80
|
end
|
81
|
+
|
82
|
+
def empty_string_to_num(string)
|
83
|
+
string == "--" ? nil : string
|
84
|
+
end
|
54
85
|
end
|
55
86
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sbi::Security
|
2
|
+
class PortfolioStockDecorator < 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
|
@@ -2,18 +2,23 @@ module Sbi::Security
|
|
2
2
|
class StockDecorator < SimpleDelegator
|
3
3
|
include Sbi::Security::Formatter
|
4
4
|
|
5
|
+
def header
|
6
|
+
%w(コード 銘柄 現在値 前日比 前日(%) 始値 高値 安値 前日終値 出来高 売買代金)
|
7
|
+
end
|
8
|
+
|
5
9
|
def format
|
6
10
|
[
|
7
11
|
code,
|
8
12
|
name,
|
9
|
-
currency(count),
|
10
|
-
currency(value),
|
11
13
|
currency(price),
|
12
14
|
sign(price_ratio),
|
13
15
|
sign(price_ratio_percentage),
|
14
|
-
|
15
|
-
|
16
|
-
currency(
|
16
|
+
currency(start_price),
|
17
|
+
currency(highest_price),
|
18
|
+
currency(lowest_price),
|
19
|
+
currency(end_price),
|
20
|
+
currency(total_stock),
|
21
|
+
currency(total_price)
|
17
22
|
]
|
18
23
|
end
|
19
24
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sbi::Security
|
2
|
+
class PortfolioStock
|
3
|
+
include Decorator
|
4
|
+
include Virtus.model(strict: true)
|
5
|
+
|
6
|
+
attribute :code, Integer
|
7
|
+
attribute :name, String
|
8
|
+
attribute :count, Integer
|
9
|
+
attribute :value, Float
|
10
|
+
attribute :price, Integer
|
11
|
+
|
12
|
+
# Basically, price_ratio is Integer and price_ratio_percentage is Float.
|
13
|
+
# Those are nil after 9:00 JST so we can't define type.
|
14
|
+
attribute :price_ratio
|
15
|
+
attribute :price_ratio_percentage
|
16
|
+
|
17
|
+
attribute :profit, Integer
|
18
|
+
attribute :profit_percentage, Float
|
19
|
+
attribute :total_value, Integer
|
20
|
+
end
|
21
|
+
end
|
data/lib/sbi/security/stock.rb
CHANGED
@@ -5,17 +5,17 @@ module Sbi::Security
|
|
5
5
|
|
6
6
|
attribute :code, Integer
|
7
7
|
attribute :name, String
|
8
|
-
attribute :count, Integer
|
9
|
-
attribute :value, Float
|
10
8
|
attribute :price, Integer
|
11
9
|
|
12
10
|
# Basically, price_ratio is Integer and price_ratio_percentage is Float.
|
13
11
|
# Those are nil after 9:00 JST so we can't define type.
|
14
12
|
attribute :price_ratio
|
15
13
|
attribute :price_ratio_percentage
|
16
|
-
|
17
|
-
attribute :
|
18
|
-
attribute :
|
19
|
-
attribute :
|
14
|
+
attribute :start_price
|
15
|
+
attribute :end_price, Integer
|
16
|
+
attribute :highest_price
|
17
|
+
attribute :total_stock
|
18
|
+
attribute :lowest_price
|
19
|
+
attribute :total_price
|
20
20
|
end
|
21
21
|
end
|
data/lib/sbi/security/version.rb
CHANGED
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.4
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -157,9 +157,11 @@ files:
|
|
157
157
|
- lib/sbi/security/crawler.rb
|
158
158
|
- lib/sbi/security/decorator.rb
|
159
159
|
- lib/sbi/security/decorator/portfolio_decorator.rb
|
160
|
+
- lib/sbi/security/decorator/portfolio_stock_decorator.rb
|
160
161
|
- lib/sbi/security/decorator/stock_decorator.rb
|
161
162
|
- lib/sbi/security/formatter.rb
|
162
163
|
- lib/sbi/security/portfolio.rb
|
164
|
+
- lib/sbi/security/portfolio_stock.rb
|
163
165
|
- lib/sbi/security/stock.rb
|
164
166
|
- lib/sbi/security/version.rb
|
165
167
|
- sbi-security.gemspec
|