Class: IGMarkets::DealingPlatform::AccountMethods

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

Overview

Provides methods for working with the logged in account. Returned by #account.

Instance Method Summary collapse

Constructor Details

#initialize(dealing_platform) ⇒ AccountMethods

Initializes this helper class with the specified dealing platform.

Parameters:


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

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

Instance Method Details

#activities(options) ⇒ Array<Activity>

Returns activities for this account in the specified time range.

Parameters:

  • options (Hash)

    The options hash.

Options Hash (options):

  • :from (Time)

    The start of the period to return activities for. Required.

  • :to (Time)

    The end of the period to return activities for. Defaults to Time.now.

Returns:


28
29
30
31
32
33
34
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 28

def activities(options)
  url_parameters = history_url_parameters options
  url_parameters[:detailed] = true

  history_request_complete url: 'history/activity', url_parameters: url_parameters, api_version: API_V3,
                           collection_name: :activities, model_class: Activity, date_attribute: :date
end

#allArray<Account>

Returns all accounts associated with the current IG Markets login.

Returns:


15
16
17
18
19
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 15

def all
  result = @dealing_platform.session.get('accounts').fetch :accounts

  @dealing_platform.instantiate_models Account, result
end

#transactions(options) ⇒ Array<Transaction>

Returns transactions for this account in the specified time range.

Parameters:

  • options (Hash)

    The options hash.

Options Hash (options):

  • :type (:all, :all_deal, :deposit, :withdrawal)

    The type of transactions to return. Defaults to :all.

  • :from (Time)

    The start of the period to return transactions for. Required.

  • :to (Time)

    The end of the period to return transactions for. Defaults to Time.now.

Returns:


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 45

def transactions(options)
  options[:type] ||= :all

  unless %i[all all_deal deposit withdrawal].include? options[:type]
    raise ArgumentError, "invalid transaction type: #{options[:type]}"
  end

  history_request_complete url: 'history/transactions', url_parameters: history_url_parameters(options),
                           api_version: API_V2, collection_name: :transactions, model_class: Transaction,
                           date_attribute: :date_utc
end