Module: Moex

Defined in:
lib/moex.rb,
lib/moex/resources.rb,
lib/moex/resources/price.rb,
lib/moex/resources/security.rb

Overview

Moscow Exchange ISS

Defined Under Namespace

Modules: Resources

Constant Summary collapse

ClientError =

Raised when the ISS response is unsuccessful or invalid, or in case of any connection errors

Faraday::ClientError

Class Method Summary collapse

Class Method Details

.prices(date: nil) ⇒ Array<Resources::Price>

List security prices

Parameters:

  • date (String, nil) (defaults to: nil)

    the date, format YYYY-MM-DD

Returns:

Raises:

  • (Moex::ClientError)

    if the ISS response is unsuccessful or invalid, or in case of any connection errors



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/moex.rb', line 93

def self.prices(date: nil)
  Enumerator.new do |yielder|
    start = 0
    price_table = load_prices(date: date, start: start)

    loop do
      break if price_table.empty?

      price_table.each do |row|
        yielder << Resources::Price.new(
          row.fetch(:tradedate),
          row.fetch(:secid),
          row.fetch(:close)
        )
      end

      price_table = load_prices(date: date, start: start += price_table.size)
    end
  end
end

.securities(params) ⇒ Array<Resources::Security>

List securities

Parameters:

  • params (Hash)

Options Hash (params):

  • security_group (String)

    security group

  • collection (String)

    security collection

Returns:

Raises:

  • (Moex::ClientError)

    if the ISS response is unsuccessful or invalid, or in case of any connection errors

See Also:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/moex.rb', line 32

def self.securities(params)
  Enumerator.new do |yielder|
    start = 0
    security_table = load_securities(params, start: start)

    loop do
      break if empty_table?(security_table)

      security_table.each do |row|
        yielder << Resources::Security.new(
          row.fetch(:isin),
          row.fetch(:secid),
          row.fetch(:shortname)
        )
      end

      start += security_table.size
      security_table = load_securities(params, start: start)
    end
  end
end