Class: IGMarkets::Market

Inherits:
Model
  • Object
show all
Defined in:
lib/ig_markets/market.rb

Overview

Contains details on a market, which is a combination of an #instrument, a set of #dealing_rules, and a current #snapshot of the instrument’s market. Returned by DealingPlatform::MarketMethods#find and DealingPlatform::MarketMethods#[].

Defined Under Namespace

Classes: DealingRules, Snapshot

Instance Attribute Summary

Attributes inherited from Model

#attributes

Instance Method Summary collapse

Methods inherited from Model

#==, allowed_values, attribute, attribute_type, attribute_value_allowed?, defined_attribute_names, deprecated_attribute, #initialize, #initialize_copy, #inspect, #to_h, valid_attribute?

Constructor Details

This class inherits a constructor from IGMarkets::Model

Instance Method Details

#dealing_rulesDealingRules

The dealing_rules attribute.

Returns:



42
# File 'lib/ig_markets/market.rb', line 42

attribute :dealing_rules, DealingRules

#historical_prices(options) ⇒ HistoricalPriceResult

Returns historical prices for this market at a given resolution, either the most recent prices by specifying the ‘:number` option, or those from a date range by specifying the `:from` and `:to` options.

Required.

Parameters:

  • options (Hash)

    The options hash.

Options Hash (options):

  • :resolution (:minute, :minute_2, :minute_3, :minute_5, :minute_10, :minute_15, :minute_30, :hour, :hour_2, :hour_3, :hour_4, :day, :week, :month)

    The resolution of the prices to return.

  • :number (Integer)

    The number of historical prices to return. If this is specified then the ‘:from` and `:to` options must not be specified.

  • :from (Time)

    The start of the period to return prices for.

  • :to (Time)

    The end of the period to return prices for.

Returns:



64
65
66
67
68
69
70
71
72
# File 'lib/ig_markets/market.rb', line 64

def historical_prices(options)
  validate_historical_prices_options options

  options[:max] = options.delete(:number) if options.key? :number
  options[:from] = options[:from].utc.strftime '%FT%T' if options.key? :from
  options[:to] = options[:to].utc.strftime '%FT%T' if options.key? :to

  @dealing_platform.instantiate_models HistoricalPriceResult, historical_prices_request(options)
end

#instrumentInstrument

The instrument attribute.

Returns:



43
# File 'lib/ig_markets/market.rb', line 43

attribute :instrument, Instrument

#reloadObject

Reloads this market’s attributes by re-querying the IG Markets API.



47
48
49
# File 'lib/ig_markets/market.rb', line 47

def reload
  self.attributes = @dealing_platform.markets[instrument.epic].attributes
end

#snapshotSnapshot

The snapshot attribute.

Returns:



44
# File 'lib/ig_markets/market.rb', line 44

attribute :snapshot, Snapshot