Class: IGMarkets::DealingPlatform::ClientSentimentMethods

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

Overview

Provides methods for working with client sentiment. Returned by #client_sentiment.

Instance Method Summary collapse

Constructor Details

#initialize(dealing_platform) ⇒ ClientSentimentMethods

Initializes this helper class with the specified dealing platform.

Parameters:


8
9
10
# File 'lib/ig_markets/dealing_platform/client_sentiment_methods.rb', line 8

def initialize(dealing_platform)
  @dealing_platform = WeakRef.new dealing_platform
end

Instance Method Details

#[](market_id) ⇒ ClientSentiment

Returns the client sentiment for a market.

Parameters:

  • market_id (String)

    The ID of the market to return client sentiment for.

Returns:


17
18
19
20
21
22
23
24
25
# File 'lib/ig_markets/dealing_platform/client_sentiment_methods.rb', line 17

def [](market_id)
  result = @dealing_platform.session.get "clientsentiment/#{market_id}"

  @dealing_platform.instantiate_models(ClientSentiment, result).tap do |client_sentiment|
    if client_sentiment.long_position_percentage == 0.0 && client_sentiment.short_position_percentage == 0.0
      raise ArgumentError, "unknown market '#{market_id}'"
    end
  end
end