Class: IGMarkets::DealingPlatform::MarketMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_markets/dealing_platform/market_methods.rb

Overview

Provides methods for working with markets. Returned by #markets.

Instance Method Summary collapse

Constructor Details

#initialize(dealing_platform) ⇒ MarketMethods

Initializes this helper class with the specified dealing platform.

Parameters:



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.

Parameters:

  • epic (String)

    The EPIC of the market to return details for.

Returns:



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.

Parameters:

  • epics (Array<String>)

    The EPICs of the markets to return details for.

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • node_id (String) (defaults to: nil)

    The ID of the node to return the market hierarchy for. If nil then details on the root node of the hierarchy will be returned.

Returns:



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.

Parameters:

  • search_term (String)

    The search term to use.

Returns:



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