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 client sentiment for the specified market.

Parameters:

  • market_id (String)

    The ID of the market to return client sentiment for.

Returns:



37
38
39
# File 'lib/ig_markets/dealing_platform/client_sentiment_methods.rb', line 37

def [](market_id)
  find(market_id).first
end

#find(*market_ids) ⇒ Array<ClientSentiment>

Returns client sentiments for the specified markets.

Parameters:

  • market_ids (Array<String>)

    The IDs of the markets to return client sentiments for.

Returns:



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

def find(*market_ids)
  result = @dealing_platform.session.get "clientsentiment?marketIds=#{market_ids.join ','}"

  models = @dealing_platform.instantiate_models ClientSentiment, result.fetch(:client_sentiments)

  # Invalid market IDs are returned with both percentages set to zero
  models.each do |client_sentiment|
    if client_sentiment.long_position_percentage == 0.0 && client_sentiment.short_position_percentage == 0.0
      raise ArgumentError, "unknown market '#{client_sentiment.market_id}'"
    end
  end

  models
end