moex_iss 1.1.0 → 1.11.0

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: e2a3f9ad4ce42c5fe38d5b16bf09ec3d937654cf12225360c2c24f4a16b0322a
4
- data.tar.gz: fa3d5358f2ce99cf174c31a1eb27da86f2ba827d632bcd1214e19cd356080431
3
+ metadata.gz: 71d87cc339f313c78295e2d5d3569aade22989f93ecef8cf27fcfde8cb151562
4
+ data.tar.gz: '0181b5dc0b1e9e01b93a685ce68bee1a84767c354b35ac27d3b50f48eeff2b5c'
5
5
  SHA512:
6
- metadata.gz: 5a9374940f414e6309bbb3fa1249c1406fb34932deeeb33d50a99c762faffede6a063dd891fa4fac96ec479da194c4dff5c8af5b7c81335cfe29243d40a268e9
7
- data.tar.gz: feee8548808c648d93726e2a79ac4240f15bd9afd4f469f7123cc743a714e8d12a56ea7d2147d4e42c9b9328fc492d07bb0ac0e048ca390ca3ac7cdb39984f47
6
+ metadata.gz: d5fc0c6b4c6884de71e79c727bb0c5a9923038783736a10f2d0806eef5c765f5cd50dd9f45ce7670cf08dda27279118dee7766d0baca73e1ac1428dcbb9f8165
7
+ data.tar.gz: f6281f2e0f278f577bacdbd179ed3bb7ddd7db31a5ebefc89453de63c5f49235a1658a6e2440cd2cbb387cc3621781d0fdd14866fe7eed2c625d7b98cc8a0568
data/CHANGELOG.md CHANGED
@@ -4,4 +4,7 @@
4
4
  Формат основан на ведении журнала изменений, и этот проект придерживается семантического управления версиями.
5
5
  ## [1.1.0] - 2023-12-30
6
6
  ### Добавлено
7
- - Возможность работы с историческими данными акции
7
+ - Возможность работы с историческими данными акции
8
+ ## [1.11.0] - 2024-01-03
9
+ ### Добавлено
10
+ - Возможность получать данные об актуальных курсах валют ЦБ РФ
data/README.md CHANGED
@@ -37,6 +37,16 @@ gem "moex_iss"
37
37
  client = MoexIss.client
38
38
  ```
39
39
 
40
+ ### Валюты
41
+ Для получения последних актульных данных о курсах валют:
42
+ ```ruby
43
+ currencies = client.currencies # => MoexIss::Market::Currencies
44
+
45
+ cny_rub = currencues.cny_rub # => MoexIss::Market::Currency
46
+ cny_urb.price = 12.5762
47
+ ...
48
+ ```
49
+
40
50
  ### Акции
41
51
 
42
52
  Для получения последних актульных данных:
@@ -65,9 +75,10 @@ stocks['2023-12-03'] # => MoexIss::Market::History::Stock
65
75
 
66
76
  Аргументы `from` и `till` можно использовать по одиночке
67
77
 
78
+ ### Обратите внимание
68
79
 
69
80
  Все экземпляры классов отвечает на метод `response`, который содержит полный ответ от MOEX ISS, из которого можно получать доп.параметры,
70
- так же у кажого класса свой набор спецефических методов для удобства работы с данными.
81
+ так же у каждого класса свой набор специфических методов для удобства работы с данными.
71
82
  ```ruby
72
83
  # Пример
73
84
  client.stock(:sber).market_price # => 271.37
@@ -6,15 +6,16 @@ module MoexIss
6
6
  include MoexIss::Hendler
7
7
 
8
8
  STOCKS_ENDPOINT = "engines/stock/markets/shares/boards/tqbr/securities"
9
+ CURRENCIES_ENDPOINT = "statistics/engines/currency/markets/selt/rates"
9
10
  STANDARD_PARAMS = {
10
11
  "iss.json" => "extended",
11
- "iss.only" => "securities,marketdata",
12
12
  "iss.meta" => "off"
13
13
  }
14
14
 
15
15
  def stocks
16
16
  endpoint = "#{STOCKS_ENDPOINT}.json"
17
17
  params = STANDARD_PARAMS
18
+ params["iss.only"] = "securities,marketdata"
18
19
 
19
20
  raw_response = get(endpoint, params)
20
21
 
@@ -26,12 +27,23 @@ module MoexIss
26
27
 
27
28
  endpoint = "#{STOCKS_ENDPOINT}/#{isin}.json"
28
29
  params = STANDARD_PARAMS
30
+ params["iss.only"] = "securities,marketdata"
29
31
 
30
32
  raw_response = get(endpoint, params)
31
33
 
32
34
  MoexIss::Market::Stock.new(handle_response(raw_response))
33
35
  end
34
36
 
37
+ def currencies
38
+ endpoint = "#{CURRENCIES_ENDPOINT}.json"
39
+ params = STANDARD_PARAMS
40
+ params["iss.only"] = "wap_rates"
41
+
42
+ raw_response = get(endpoint, params)
43
+
44
+ MoexIss::Market::Currencies.new(handle_response(raw_response))
45
+ end
46
+
35
47
  private
36
48
 
37
49
  def historical_data_of_the_stock(isin, from, till)
@@ -34,5 +34,3 @@ module MoexIss
34
34
  end
35
35
  end
36
36
  end
37
-
38
- # CURENCY https://iss.moex.com/iss/statistics/engines/currency/markets/selt/rates.json?iss.meta=off&iss.json=extended&iss.only=wap_rates
@@ -4,7 +4,8 @@ module MoexIss
4
4
  module Hendler
5
5
  def handle_response(response)
6
6
  return standard_hendler(response) if standard_schema?(response)
7
- return history_hendler(response) if history_schema?(response)
7
+ return response[1] if history_schema?(response)
8
+ return response[1] if currencies_schema?(response)
8
9
 
9
10
  fail MoexIss::Error::ResponseSchemaError, "Неизвестная схема ответа"
10
11
  end
@@ -22,14 +23,14 @@ module MoexIss
22
23
  response.is_a?(Array) && response[1]&.has_key?("history")
23
24
  end
24
25
 
26
+ def currencies_schema?(response)
27
+ response.is_a?(Array) && response[1]&.has_key?("wap_rates")
28
+ end
29
+
25
30
  def standard_hendler(response)
26
31
  response[1]["securities"].map.with_index do |x, i|
27
32
  {"securities" => x, "marketdata" => response[1]["marketdata"][i]}
28
33
  end
29
34
  end
30
-
31
- def history_hendler(response)
32
- response[1]
33
- end
34
35
  end
35
36
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoexIss
4
+ module Market
5
+ class Collection
6
+ include Enumerable
7
+
8
+ attr_reader :response
9
+
10
+ def initialize(response, instance_class: Security)
11
+ @response = response
12
+ @instance_class = instance_class
13
+ @stocks_map = {}
14
+
15
+ create_instances
16
+ end
17
+
18
+ def create_instances
19
+ @response.each do |data|
20
+ method = method_name(data)
21
+
22
+ setup_method(method, data)
23
+ end
24
+ end
25
+
26
+ def each
27
+ @stocks_map.values.each { |stock| yield stock }
28
+ end
29
+
30
+ private
31
+
32
+ def method_name(data)
33
+ :some_name
34
+ end
35
+
36
+ def setup_method(method, data)
37
+ @stocks_map[method] = @instance_class.new(data)
38
+
39
+ self.class.send(:define_method, method) { @stocks_map[method] }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoexIss
4
+ module Market
5
+ class Currencies < Collection
6
+ def initialize(response, instance_class: MoexIss::Market::Currency)
7
+ super
8
+ end
9
+
10
+ def create_instances
11
+ @response["wap_rates"].each do |data|
12
+ method = method_name(data)
13
+
14
+ setup_method(method, data)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def method_name(data)
21
+ data["shortname"]
22
+ .split("_")
23
+ .first.downcase
24
+ .insert(3, "_")
25
+ .to_sym
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoexIss
4
+ module Market
5
+ class Currency
6
+ METHODS = {
7
+ "tradedate" => :trade_date, "tradetime" => :trade_time,
8
+ "secid" => :secid, "shortname" => :short_name,
9
+ "price" => :price, "lasttoprevprice" => :last_top_rev_price,
10
+ "nominal" => :nominal, "decimals" => :decimals
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
+ end
33
+ end
34
+ end
@@ -3,8 +3,12 @@
3
3
  module MoexIss
4
4
  module Market
5
5
  module History
6
- class Stocks < MoexIss::Market::Stocks
7
- def create_instances_stock
6
+ class Stocks < MoexIss::Market::Collection
7
+ def initialize(response, instance_class: MoexIss::Market::History::Stock)
8
+ super
9
+ end
10
+
11
+ def create_instances
8
12
  @response["history"].each do |data|
9
13
  @stocks_map[data["TRADEDATE"]] = History::Stock.new({"history" => data})
10
14
  end
@@ -2,36 +2,23 @@
2
2
 
3
3
  module MoexIss
4
4
  module Market
5
- class Stocks
6
- include Enumerable
7
-
8
- attr_reader :response
9
-
10
- def initialize(response)
11
- @response = response
12
- @stocks_map = {}
13
-
14
- create_instances_stock
5
+ class Stocks < Collection
6
+ def initialize(response, instance_class: MoexIss::Market::Stock)
7
+ super
15
8
  end
16
9
 
17
10
  def create_instances_stock
18
11
  @response.each do |data|
19
- method = data["securities"]["SECID"].downcase.to_sym
12
+ method = method_name(data)
20
13
 
21
14
  setup_method(method, data)
22
15
  end
23
16
  end
24
17
 
25
- def each
26
- @stocks_map.values.each { |stock| yield stock }
27
- end
28
-
29
18
  private
30
19
 
31
- def setup_method(method, data)
32
- @stocks_map[method] = Stock.new(data)
33
-
34
- self.class.send(:define_method, method) { @stocks_map[method] }
20
+ def method_name(data)
21
+ data["securities"]["SECID"].downcase.to_sym
35
22
  end
36
23
  end
37
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoexIss # :nodoc:
4
- VERSION = "1.1.0"
4
+ VERSION = "1.11.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moex_iss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vyacheslav Konovalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-30 00:00:00.000000000 Z
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,6 +96,9 @@ files:
96
96
  - lib/moex_iss/connection.rb
97
97
  - lib/moex_iss/error.rb
98
98
  - lib/moex_iss/hendler.rb
99
+ - lib/moex_iss/market/collection.rb
100
+ - lib/moex_iss/market/currencies.rb
101
+ - lib/moex_iss/market/currency.rb
99
102
  - lib/moex_iss/market/history/stock.rb
100
103
  - lib/moex_iss/market/history/stocks.rb
101
104
  - lib/moex_iss/market/stock.rb
@@ -126,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
129
  - !ruby/object:Gem::Version
127
130
  version: '0'
128
131
  requirements: []
129
- rubygems_version: 3.5.3
132
+ rubygems_version: 3.1.6
130
133
  signing_key:
131
134
  specification_version: 4
132
135
  summary: Client for MOEX ISS API