Class: IGMarkets::AccountTransaction

Inherits:
Model
  • Object
show all
Defined in:
lib/ig_markets/account_transaction.rb

Overview

Contains details on a single transaction that occurred on an IG Markets account. Returned by DealingPlatform::AccountMethods#transactions_in_date_range and DealingPlatform::AccountMethods#recent_transactions.

Instance Attribute Summary

Attributes inherited from Model

#attributes

Instance Method Summary collapse

Methods inherited from Model

#==, allowed_values, attribute, defined_attribute_names, from, #initialize, #inspect

Constructor Details

This class inherits a constructor from IGMarkets::Model

Instance Method Details

#cash_transactionBoolean

The cash_transaction attribute.

Returns:



6
# File 'lib/ig_markets/account_transaction.rb', line 6

attribute :cash_transaction, Boolean

#close_levelObject

The close_level attribute.

Returns:



7
# File 'lib/ig_markets/account_transaction.rb', line 7

attribute :close_level

#currencyObject

The currency attribute.

Returns:



8
# File 'lib/ig_markets/account_transaction.rb', line 8

attribute :currency

#dateDate

The date attribute.

Returns:

  • (Date)


9
# File 'lib/ig_markets/account_transaction.rb', line 9

attribute :date, Date, format: '%d/%m/%y'

#formatted_transaction_typeString

Returns this transaction’s #transaction_type as a human-readable string.

Returns:

  • (String)


39
40
41
42
43
44
45
46
47
# File 'lib/ig_markets/account_transaction.rb', line 39

def formatted_transaction_type
  {
    deal: 'Deal',
    depo: 'Deposit',
    dividend: 'Dividend',
    exchange: 'Exchange',
    with: 'Withdrawal'
  }.fetch transaction_type
end

#instrument_nameObject

The instrument_name attribute.

Returns:



10
# File 'lib/ig_markets/account_transaction.rb', line 10

attribute :instrument_name

#interest?Boolean

Returns whether or not this transaction was an interest payment. Interest payments can be either deposits or withdrawals depending on the underlying instrument and currencies involved. Interest payments are identified by the presence of the word interest in #instrument_name.

Returns:



23
24
25
# File 'lib/ig_markets/account_transaction.rb', line 23

def interest?
  [:depo, :with].include?(transaction_type) && !(instrument_name.downcase =~ /(^|[^a-z])interest([^a-z]|$)/).nil?
end

#open_levelString

The open_level attribute.

Returns:

  • (String)


11
# File 'lib/ig_markets/account_transaction.rb', line 11

attribute :open_level, String, nil_if: '-'

#periodString

The period attribute.

Returns:

  • (String)


12
# File 'lib/ig_markets/account_transaction.rb', line 12

attribute :period, String, nil_if: '-'

#profit_and_lossObject

The profit_and_loss attribute.

Returns:



13
# File 'lib/ig_markets/account_transaction.rb', line 13

attribute :profit_and_loss

#profit_and_loss_amountFloat

Returns this transaction’s #profit_and_loss as a Float, denominated in this transaction’s #currency.

Returns:

  • (Float)


30
31
32
33
34
# File 'lib/ig_markets/account_transaction.rb', line 30

def profit_and_loss_amount
  raise 'profit_and_loss does not start with the expected currency' unless profit_and_loss.start_with? currency

  profit_and_loss[currency.length..-1].delete(',').to_f
end

#referenceObject

The reference attribute.

Returns:



14
# File 'lib/ig_markets/account_transaction.rb', line 14

attribute :reference

#sizeString

The size attribute.

Returns:

  • (String)


15
# File 'lib/ig_markets/account_transaction.rb', line 15

attribute :size, String, nil_if: '-'

#transaction_typeSymbol

The transaction_type attribute.

Returns:

  • (Symbol)


16
# File 'lib/ig_markets/account_transaction.rb', line 16

attribute :transaction_type, Symbol, allowed_values: [:deal, :depo, :dividend, :exchange, :with]