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
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 28

def activities(options)
  activities_request build_url_parameters(options).merge(detailed: true)
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:



41
42
43
44
45
46
47
48
49
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 41

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

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

  tranaactions_request build_url_parameters(options)
end