Class: IGMarkets::DealingPlatform::MarketMethods
- Inherits:
-
Object
- Object
- IGMarkets::DealingPlatform::MarketMethods
- Defined in:
- lib/ig_markets/dealing_platform/market_methods.rb
Overview
Provides methods for working with markets. Returned by #markets.
Instance Method Summary collapse
-
#[](epic) ⇒ Market
Returns market details for the market with the specified EPIC, or ‘nil` if there is no market with that EPIC.
-
#find(*epics) ⇒ Array<Market>
Returns details for the markets with the passed EPICs.
-
#hierarchy(node_id = nil) ⇒ MarketHierarchyResult
Returns details on the market hierarchy directly under the specified node.
-
#initialize(dealing_platform) ⇒ MarketMethods
constructor
Initializes this helper class with the specified dealing platform.
-
#search(search_term) ⇒ Array<MarketOverview>
Searches markets using a search term and returns an array of results.
Constructor Details
#initialize(dealing_platform) ⇒ MarketMethods
Initializes this helper class with the specified dealing platform.
8 9 10 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 8 def initialize(dealing_platform) @dealing_platform = WeakRef.new dealing_platform end |
Instance Method Details
#[](epic) ⇒ Market
Returns market details for the market with the specified EPIC, or ‘nil` if there is no market with that EPIC. Internally a call to #find is made.
65 66 67 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 65 def [](epic) find(epic).first end |
#find(*epics) ⇒ Array<Market>
Returns details for the markets with the passed EPICs.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 31 def find(*epics) epics = epics.flatten return [] if epics.empty? epics.each do |epic| raise ArgumentError, "invalid EPIC: #{epic}" unless Regex::EPIC.match?(epic.to_s) end # The API imposes a maximum of 50 EPICs per request markets = epics.each_slice(50).map do |epics_slice| @dealing_platform.session.get("markets?epics=#{epics_slice.join(',')}", API_V2).fetch :market_details end @dealing_platform.instantiate_models Market, markets.flatten end |
#hierarchy(node_id = nil) ⇒ MarketHierarchyResult
Returns details on the market hierarchy directly under the specified node.
18 19 20 21 22 23 24 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 18 def hierarchy(node_id = nil) url = ['marketnavigation', node_id].compact.join '/' result = @dealing_platform.session.get url @dealing_platform.instantiate_models MarketHierarchyResult, result end |
#search(search_term) ⇒ Array<MarketOverview>
Searches markets using a search term and returns an array of results.
53 54 55 56 57 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 53 def search(search_term) result = @dealing_platform.session.get("markets?searchTerm=#{search_term}").fetch :markets @dealing_platform.instantiate_models MarketOverview, result end |