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
nilif 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 = 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.
54 55 56 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 54 def [](epic) find(epic)[0] end |
#find(*epics) ⇒ Array<Market>
Returns details for the markets with the passed EPICs.
29 30 31 32 33 34 35 36 37 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 29 def find(*epics) raise ArgumentError, 'at least one EPIC must be specified' if epics.empty? epics.each do |epic| raise ArgumentError, "invalid EPIC: #{epic}" unless epic.to_s =~ Regex::EPIC end @dealing_platform.gather "markets?epics=#{epics.join(',')}", :market_details, Market, API_V2 end |
#hierarchy(node_id = nil) ⇒ MarketHierarchyResult
Returns details on the market hierarchy directly under the specified node.
18 19 20 21 22 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 18 def hierarchy(node_id = nil) url = ['marketnavigation', node_id].compact.join '/' MarketHierarchyResult.from @dealing_platform.session.get(url, API_V1) end |
#search(search_term) ⇒ Array<MarketOverview>
Searches markets using a search term and returns an array of results.
44 45 46 |
# File 'lib/ig_markets/dealing_platform/market_methods.rb', line 44 def search(search_term) @dealing_platform.gather "markets?searchTerm=#{search_term}", :markets, MarketOverview end |