Class: MoexRuby::Client
- Inherits:
-
Object
- Object
- MoexRuby::Client
- Extended by:
- Forwardable
- Includes:
- Engines, History, Markets, Securities
- Defined in:
- lib/moex_ruby/client.rb,
lib/moex_ruby/client/engines.rb,
lib/moex_ruby/client/history.rb,
lib/moex_ruby/client/markets.rb,
lib/moex_ruby/client/securities.rb
Defined Under Namespace
Modules: Engines, History, Markets, Securities
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(connection: nil, **config_options, &block) ⇒ Client
constructor
A new instance of Client.
- #paginate(path, params = {}, max_pages = 1000) ⇒ Object
Methods included from Markets
#issuer, #issuers, #market_data, #open_interest, #open_interest_on_date, #order_book, #top_securities, #trades, #trading_session, #turnovers
Methods included from Engines
#board, #board_securities, #board_security, #boards, #engine, #engines, #market, #markets, #stock_bonds, #stock_shares
Methods included from History
#bond_history, #candles, #currency_history, #paginate_candles, #paginate_history, #security_history, #trading_days
Methods included from Securities
#index, #indices, #search_securities, #securities, #securities_aggregates, #security
Constructor Details
#initialize(connection: nil, **config_options, &block) ⇒ Client
26 27 28 29 |
# File 'lib/moex_ruby/client.rb', line 26 def initialize(connection: nil, **, &block) @config = build_configuration(, &block) @connection = connection || build_default_connection end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
22 23 24 |
# File 'lib/moex_ruby/client.rb', line 22 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
22 23 24 |
# File 'lib/moex_ruby/client.rb', line 22 def connection @connection end |
Instance Method Details
#get(path, params = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/moex_ruby/client.rb', line 31 def get(path, params = {}) return perform_request(path, params) unless @config.auto_paginate auto_paginate_get(path, params) end |
#paginate(path, params = {}, max_pages = 1000) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/moex_ruby/client.rb', line 37 def paginate(path, params = {}, max_pages = 1000) return enum_for(:paginate, path, params, max_pages) unless block_given? start = 0 page = 0 loop do page += 1 if page > max_pages MoexRuby.logger&.warn("Pagination reached max_pages limit (#{max_pages})") break end MoexRuby.logger&.debug("Fetching page #{page} with start=#{start}") data = perform_request(path, params.merge(start: start)) size = PaginationHelper.extract_size(data) if size.zero? MoexRuby.logger&.debug("Empty page received, pagination complete") break end yield data start = start + size end end |