sbi-security 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c1e960daaccd91b38d3c574cba635d29e393737
4
- data.tar.gz: 0c146bc14278e453047aaa327b3a35b7944364d6
3
+ metadata.gz: 9e69337392b0e46a91cdf5158e5c6d5742688129
4
+ data.tar.gz: 3995e86bdb82046a77afebf11f04a77c6497e073
5
5
  SHA512:
6
- metadata.gz: a62fb8304e2319b90f4856fb8e9d7a86afdbd0ebaf5074776a8b2fc58d3de258d58ee9cf4ef875ee1daec9cdc409e1177e786fb7707ae6050757c34dfd6803c9
7
- data.tar.gz: cefa0c2a8db7d326752c02ef95e5e38ea19f80d058e44e3cf8ff3c2baf23f641f9ac13920c8b5468d9a0c459b0fa3bb91154b1a895d39b1873d2da64de3e345b
6
+ metadata.gz: 4f36e009baac158e8892bf15e60e0215001cd5fa7441bd2c19ea7cfd7d0de4b2e5679ee2e8dd86daba11ef11703dbe2c5e6418e0a800d79c67d42c7f7c11ca0a
7
+ data.tar.gz: a4e833b76541eaa5125b5c67710e5440b6c295a59fdf77a3734b11f9921c2122606ab4b523288dbdfb1ae23882821dbc24877bab7d27d78deb6f20f66846b048
data/README.md CHANGED
@@ -46,6 +46,34 @@ $ sbisec stock 3633
46
46
  +--------+--------------+--------+--------+---------+-------+-------+-------+----------+--------+-----------+
47
47
  | 3633 | GMOペパボ | 3,390 | -20 | -0.59 | 3,405 | 3,405 | 3,380 | 3,410 | 500 | 1,696,000 |
48
48
  +--------+--------------+--------+--------+---------+-------+-------+-------+----------+--------+-----------+
49
+
50
+
51
+ +------------+--------+------------+
52
+ | 売気配株数 | 気配値 | 買気配株数 |
53
+ +------------+--------+------------+
54
+ | 3,800 | OVER | |
55
+ | 100 | 3,490 | |
56
+ | 400 | 3,450 | |
57
+ | 500 | 3,445 | |
58
+ | 500 | 3,435 | |
59
+ | 400 | 3,430 | |
60
+ | 100 | 3,420 | |
61
+ | 1,300 | 3,415 | |
62
+ | 200 | 3,410 | |
63
+ | 300 | 3,405 | |
64
+ | 前 200 | 3,400 | |
65
+ | | 3,390 | 前 500 |
66
+ | | 3,370 | 400 |
67
+ | | 3,365 | 200 |
68
+ | | 3,360 | 200 |
69
+ | | 3,355 | 100 |
70
+ | | 3,350 | 200 |
71
+ | | 3,345 | 200 |
72
+ | | 3,340 | 200 |
73
+ | | 3,335 | 200 |
74
+ | | 3,330 | 300 |
75
+ | | UNDER | 3,000 |
76
+ +------------+--------+------------+
49
77
  ```
50
78
 
51
79
  ## TODO
@@ -24,8 +24,17 @@ module Sbi::Security
24
24
  rows << stock.decorate.header
25
25
  rows << :separator
26
26
  rows << stock.decorate.format
27
+ stock_table = Terminal::Table.new(rows: rows)
27
28
 
28
- Terminal::Table.new(rows: rows)
29
+ rows = []
30
+ rows << stock.decorate.order_book_header
31
+ rows << :separator
32
+ stock.order_books.each do |order_book|
33
+ rows << order_book.decorate.format
34
+ end
35
+ order_book_table = Terminal::Table.new(rows: rows)
36
+
37
+ "#{stock_table}\n\n#{order_book_table}"
29
38
  end
30
39
  end
31
40
  end
@@ -19,7 +19,7 @@ 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"]').drop(1).each_with_index.map do |tr, i|
22
+ stocks = all(:xpath, '//table[@width="100%"]/tbody/tr[@align="center"]').drop(1).each_with_index.map do |tr, i|
23
23
  _, code_and_name, _, count, value, price, price_ratio, price_ratio_percentage, profit, profit_percentage,
24
24
  total_value = tr.all("td").map { |td| td.text.gsub(/,/, "") }
25
25
 
@@ -41,24 +41,34 @@ module Sbi::Security
41
41
  end
42
42
 
43
43
  def stock(code)
44
- fill_in :i_stock_sec, with: code
44
+ find(:xpath, "//input[@id='top_stock_sec']").set code
45
45
  find("img[title='株価検索']").click
46
46
 
47
47
  # SBI security has XHR for fetching information. Need to wait until page finish to emulate JavaScript.
48
48
  loop do
49
- if page.find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text != "--"
49
+ if find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text != "--"
50
50
  break
51
51
  end
52
52
  sleep 1
53
53
  end
54
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(/,/, "") }
55
+ price_ratio, price_ratio_percentage = 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 = all(:xpath, "//table[@class='tbl690']/tbody/tr/td/p/span[@class='fm01']").map { |td| td.text.gsub(/,/, "") }
57
+
58
+ order_books = all(:xpath, "//div[@class='itaTbl02']/table/tbody/tr").drop(1).map do |tr|
59
+ sell_volume, price, buy_volume = tr.all(:xpath, "./td").map(&:text)
60
+
61
+ OrderBook.new(
62
+ volume: sell_volume.empty? ? buy_volume : sell_volume,
63
+ price: price,
64
+ type: sell_volume.empty? ? "buy" : "sell"
65
+ )
66
+ end
57
67
 
58
68
  Stock.new(
59
69
  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(/,/, ""),
70
+ name: find(:xpath, "//h3/span[@class='fxx01']").text,
71
+ price: find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text.gsub(/,/, ""),
62
72
  price_ratio: empty_string_to_num(price_ratio).to_i,
63
73
  price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
64
74
  start_price: start_price.to_i,
@@ -66,7 +76,8 @@ module Sbi::Security
66
76
  highest_price: highest_price.to_i,
67
77
  total_stock: total_stock.to_i,
68
78
  lowest_price: lowest_price.to_i,
69
- total_price: total_price.to_i * 1000
79
+ total_price: total_price.to_i * 1000,
80
+ order_books: order_books
70
81
  )
71
82
  end
72
83
 
@@ -0,0 +1,14 @@
1
+ module Sbi::Security
2
+ class OrderBookDecorator < SimpleDelegator
3
+ def format
4
+ sell_volume = type == "sell" ? volume : ""
5
+ buy_volume = type == "buy" ? volume : ""
6
+
7
+ [
8
+ sell_volume,
9
+ price,
10
+ buy_volume
11
+ ]
12
+ end
13
+ end
14
+ end
@@ -21,5 +21,9 @@ module Sbi::Security
21
21
  currency(total_price)
22
22
  ]
23
23
  end
24
+
25
+ def order_book_header
26
+ %w(売気配株数 気配値 買気配株数)
27
+ end
24
28
  end
25
29
  end
@@ -0,0 +1,10 @@
1
+ module Sbi::Security
2
+ class OrderBook
3
+ include Decorator
4
+ include Virtus.model(strict: true)
5
+
6
+ attribute :price, String
7
+ attribute :volume, String
8
+ attribute :type, String
9
+ end
10
+ end
@@ -17,5 +17,6 @@ module Sbi::Security
17
17
  attribute :total_stock
18
18
  attribute :lowest_price
19
19
  attribute :total_price
20
+ attribute :order_books, Array[OrderBook]
20
21
  end
21
22
  end
@@ -1,5 +1,5 @@
1
1
  module Sbi
2
2
  module Security
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
data/lib/sbi/security.rb CHANGED
@@ -18,7 +18,9 @@ require "sbi/security/decorator"
18
18
  require "sbi/security/decorator/portfolio_decorator"
19
19
  require "sbi/security/decorator/portfolio_stock_decorator"
20
20
  require "sbi/security/decorator/stock_decorator"
21
+ require "sbi/security/decorator/order_book_decorator"
21
22
  require "sbi/security/portfolio"
22
23
  require "sbi/security/portfolio_stock"
24
+ require "sbi/security/order_book"
23
25
  require "sbi/security/stock"
24
26
  require "sbi/security/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbi-security
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - camelmasa
@@ -156,10 +156,12 @@ files:
156
156
  - lib/sbi/security/client.rb
157
157
  - lib/sbi/security/crawler.rb
158
158
  - lib/sbi/security/decorator.rb
159
+ - lib/sbi/security/decorator/order_book_decorator.rb
159
160
  - lib/sbi/security/decorator/portfolio_decorator.rb
160
161
  - lib/sbi/security/decorator/portfolio_stock_decorator.rb
161
162
  - lib/sbi/security/decorator/stock_decorator.rb
162
163
  - lib/sbi/security/formatter.rb
164
+ - lib/sbi/security/order_book.rb
163
165
  - lib/sbi/security/portfolio.rb
164
166
  - lib/sbi/security/portfolio_stock.rb
165
167
  - lib/sbi/security/stock.rb