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 = dealing_platform
end

Instance Method Details

#activities_in_date_range(from_date, to_date) ⇒ Array<Activity>

Returns all account activities that occurred in the specified date range.

Parameters:

  • from_date (Date)

    The start date of the desired date range.

  • to_date (Date)

    The end date of the desired date range.

Returns:



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

def activities_in_date_range(from_date, to_date)
  from_date = format_date from_date
  to_date = format_date to_date

  result = @dealing_platform.session.get("history/activity/#{from_date}/#{to_date}").fetch :activities

  @dealing_platform.instantiate_models Activity, result
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

#recent_activities(days) ⇒ Array<Activity>

Returns all account activities that occurred in the most recent specified number of days.

Parameters:

  • days (Fixnum, Float)

    The number of days to return recent activities for.

Returns:



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

def recent_activities(days)
  result = @dealing_platform.session.get("history/activity/#{milliseconds(days)}").fetch :activities

  @dealing_platform.instantiate_models Activity, result
end

#recent_transactions(days, transaction_type = :all) ⇒ Array<Transaction>

Returns all transactions that occurred in the last specified number of days.

Parameters:

  • days (Fixnum, Float)

    The number of days to return recent transactions for.

  • transaction_type (:all, :all_deal, :deposit, :withdrawal) (defaults to: :all)

    The type of transactions to return.

Returns:



72
73
74
75
76
77
78
79
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 72

def recent_transactions(days, transaction_type = :all)
  validate_transaction_type transaction_type

  url = "history/transactions/#{transaction_type.to_s.upcase}/#{milliseconds(days)}"
  result = @dealing_platform.session.get(url).fetch :transactions

  @dealing_platform.instantiate_models Transaction, result
end

#transactions_in_date_range(from_date, to_date, transaction_type = :all) ⇒ Array<Transaction>

Returns all transactions that occurred in the specified date range.

Parameters:

  • from_date (Date)

    The start date of the desired date range.

  • to_date (Date)

    The end date of the desired date range.

  • transaction_type (:all, :all_deal, :deposit, :withdrawal) (defaults to: :all)

    The type of transactions to return.

Returns:



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ig_markets/dealing_platform/account_methods.rb', line 54

def transactions_in_date_range(from_date, to_date, transaction_type = :all)
  validate_transaction_type transaction_type

  from_date = format_date from_date
  to_date = format_date to_date

  url = "history/transactions/#{transaction_type.to_s.upcase}/#{from_date}/#{to_date}"
  result = @dealing_platform.session.get(url).fetch :transactions

  @dealing_platform.instantiate_models Transaction, result
end