moex_iss 1.11.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71d87cc339f313c78295e2d5d3569aade22989f93ecef8cf27fcfde8cb151562
4
- data.tar.gz: '0181b5dc0b1e9e01b93a685ce68bee1a84767c354b35ac27d3b50f48eeff2b5c'
3
+ metadata.gz: dc6e59c116501d2490614026723ffe37b22c554da6a7e01283e61875b2ddd2aa
4
+ data.tar.gz: 2db4b513cb7cc9dcdd12ff144c5447b23d94ea4234dc6a856de899f2ae355ff4
5
5
  SHA512:
6
- metadata.gz: d5fc0c6b4c6884de71e79c727bb0c5a9923038783736a10f2d0806eef5c765f5cd50dd9f45ce7670cf08dda27279118dee7766d0baca73e1ac1428dcbb9f8165
7
- data.tar.gz: f6281f2e0f278f577bacdbd179ed3bb7ddd7db31a5ebefc89453de63c5f49235a1658a6e2440cd2cbb387cc3621781d0fdd14866fe7eed2c625d7b98cc8a0568
6
+ metadata.gz: 71eb024e491423c345d14b08a25751cbc6a535a3766773aa8d3b70ff20a68085c8402a6b8bb9058f640d262dfc6a27cb6a4254a00a405cadf1bce5a82f8a9413
7
+ data.tar.gz: 8a0b310f3682a646ee0402e19b990b7ce64c5688df504a35720214321c1ab3b126bfb629f2d4192285f4d4b9d3459d7b7136274a88b214255e29de4f97987557
data/README.md CHANGED
@@ -22,7 +22,7 @@ gem "moex_iss"
22
22
 
23
23
  Или установите его самостоятельно как:
24
24
 
25
- $ gem install moex_api
25
+ $ gem install moex_iss
26
26
 
27
27
  ### Поддерживаемые Ruby версии
28
28
 
@@ -42,8 +42,10 @@ client = MoexIss.client
42
42
  ```ruby
43
43
  currencies = client.currencies # => MoexIss::Market::Currencies
44
44
 
45
- cny_rub = currencues.cny_rub # => MoexIss::Market::Currency
46
- cny_urb.price = 12.5762
45
+ currencies.map(&:short_name) # -> ["USDRUB_TOM", "EURRUB_TOM", "CNYRUB_TOM"]
46
+
47
+ cny_rub = currencies.cny_rub # => MoexIss::Market::Currency
48
+ cny_rub.price = 12.5762
47
49
  ...
48
50
  ```
49
51
 
@@ -10,7 +10,7 @@ module MoexIss
10
10
  def initialize(response, instance_class: Security)
11
11
  @response = response
12
12
  @instance_class = instance_class
13
- @stocks_map = {}
13
+ @collection_map = {}
14
14
 
15
15
  create_instances
16
16
  end
@@ -24,7 +24,7 @@ module MoexIss
24
24
  end
25
25
 
26
26
  def each
27
- @stocks_map.values.each { |stock| yield stock }
27
+ @collection_map.values.each { |stock| yield stock }
28
28
  end
29
29
 
30
30
  private
@@ -34,9 +34,9 @@ module MoexIss
34
34
  end
35
35
 
36
36
  def setup_method(method, data)
37
- @stocks_map[method] = @instance_class.new(data)
37
+ @collection_map[method] = @instance_class.new(data)
38
38
 
39
- self.class.send(:define_method, method) { @stocks_map[method] }
39
+ self.class.send(:define_method, method) { @collection_map[method] }
40
40
  end
41
41
  end
42
42
  end
@@ -2,33 +2,13 @@
2
2
 
3
3
  module MoexIss
4
4
  module Market
5
- class Currency
5
+ class Currency < Security
6
6
  METHODS = {
7
7
  "tradedate" => :trade_date, "tradetime" => :trade_time,
8
8
  "secid" => :secid, "shortname" => :short_name,
9
9
  "price" => :price, "lasttoprevprice" => :last_top_rev_price,
10
10
  "nominal" => :nominal, "decimals" => :decimals
11
11
  }.freeze
12
-
13
- attr_reader(:response, *METHODS.values)
14
-
15
- def initialize(response)
16
- @response = response
17
-
18
- setup_instance_varibales(@response)
19
- end
20
-
21
- private
22
-
23
- def setup_instance_varibales(data)
24
- return if data.nil?
25
-
26
- data.each do |key, value|
27
- next unless METHODS.has_key?(key)
28
-
29
- instance_variable_set("@#{METHODS[key]}", value)
30
- end
31
- end
32
12
  end
33
13
  end
34
14
  end
@@ -3,31 +3,17 @@
3
3
  module MoexIss
4
4
  module Market
5
5
  module History
6
- class Stock
6
+ class Stock < Security
7
7
  METHODS = {
8
8
  "TRADEDATE" => :trade_date, "SHORTNAME" => :short_name, "SECID" => :secid, "VALUE" => :value,
9
9
  "OPEN" => :open, "LOW" => :low, "HIGH" => :high, "LEGALCLOSEPRICE" => :legal_close_price,
10
10
  "VOLUME" => :volume
11
11
  }.freeze
12
12
 
13
- attr_reader(:response, *METHODS.values)
14
-
15
13
  def initialize(response)
16
- @response = response
17
-
18
- setup_instance_varibales(@response["history"])
19
- end
20
-
21
- private
22
-
23
- def setup_instance_varibales(data)
24
- return if data.nil?
25
-
26
- data.each do |key, value|
27
- next unless METHODS.has_key?(key)
14
+ setup_methods(response["history"])
28
15
 
29
- instance_variable_set("@#{METHODS[key]}", value)
30
- end
16
+ super
31
17
  end
32
18
  end
33
19
  end
@@ -3,19 +3,19 @@
3
3
  module MoexIss
4
4
  module Market
5
5
  module History
6
- class Stocks < MoexIss::Market::Collection
6
+ class Stocks < Collection
7
7
  def initialize(response, instance_class: MoexIss::Market::History::Stock)
8
8
  super
9
9
  end
10
10
 
11
11
  def create_instances
12
12
  @response["history"].each do |data|
13
- @stocks_map[data["TRADEDATE"]] = History::Stock.new({"history" => data})
13
+ @collection_map[data["TRADEDATE"]] = @instance_class.new({"history" => data})
14
14
  end
15
15
  end
16
16
 
17
17
  def [](key)
18
- @stocks_map[key]
18
+ @collection_map[key]
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoexIss
4
+ module Market
5
+ class Security
6
+ attr_reader :response
7
+
8
+ def initialize(response)
9
+ @response = response
10
+
11
+ setup_methods(response)
12
+ end
13
+
14
+ private
15
+
16
+ def setup_methods(data)
17
+ return if data.nil?
18
+
19
+ data.each do |key, value|
20
+ next unless self.class::METHODS.has_key?(key)
21
+
22
+ define_singleton_method self.class::METHODS[key] do
23
+ value
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,40 +2,24 @@
2
2
 
3
3
  module MoexIss
4
4
  module Market
5
- class Stock
5
+ class Stock < Security
6
6
  METHODS = {
7
7
  "BID" => :bid, "MARKETPRICETODAY" => :market_price_today,
8
8
  "MARKETPRICE" => :market_price, "SECID" => :secid,
9
9
  "SHORTNAME" => :short_name, "LATNAME" => :lat_name,
10
10
  "BOARDID" => :board_id, "BOARDNAME" => :board_name,
11
11
  "ISIN" => :isin, "PREVPRICE" => :prev_price,
12
- "PREVDATE" => :prev_date
12
+ "PREVDATE" => :prev_date, "CLOSEPRICE" => :close_price,
13
+ "OPEN" => :open, "LOW" => :low, "HIGH" => :high,
14
+ "LAST" => :last, "VALUE" => :value, "SYSTIME" => :systime
13
15
  }.freeze
14
16
 
15
- MARKET_DATA = %w[CLOSEPRICE OPEN LOW HIGH LAST VALUE SYSTIME]
16
-
17
- attr_reader(:response, :market_data, *METHODS.values)
18
-
19
17
  def initialize(response)
20
18
  @response = response.is_a?(Array) ? response.first : response
21
19
 
22
- setup_instance_varibales(@response["securities"])
23
- setup_instance_varibales(@response["marketdata"])
24
- setup_instance_varibales(@response["history"])
25
-
26
- @market_data = @response["marketdata"]&.slice(*MARKET_DATA)
27
- end
28
-
29
- private
30
-
31
- def setup_instance_varibales(data)
32
- return if data.nil?
33
-
34
- data.each do |key, value|
35
- next unless METHODS.has_key?(key)
36
-
37
- instance_variable_set("@#{METHODS[key]}", value)
38
- end
20
+ setup_methods(@response["securities"])
21
+ setup_methods(@response["marketdata"])
22
+ setup_methods(@response["history"])
39
23
  end
40
24
  end
41
25
  end
@@ -7,14 +7,6 @@ module MoexIss
7
7
  super
8
8
  end
9
9
 
10
- def create_instances_stock
11
- @response.each do |data|
12
- method = method_name(data)
13
-
14
- setup_method(method, data)
15
- end
16
- end
17
-
18
10
  private
19
11
 
20
12
  def method_name(data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoexIss # :nodoc:
4
- VERSION = "1.11.0"
4
+ VERSION = "1.11.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moex_iss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vyacheslav Konovalov
@@ -101,6 +101,7 @@ files:
101
101
  - lib/moex_iss/market/currency.rb
102
102
  - lib/moex_iss/market/history/stock.rb
103
103
  - lib/moex_iss/market/history/stocks.rb
104
+ - lib/moex_iss/market/security.rb
104
105
  - lib/moex_iss/market/stock.rb
105
106
  - lib/moex_iss/market/stocks.rb
106
107
  - lib/moex_iss/request.rb