Class: IGMarkets::AccountTransaction
- 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
Instance Method Summary collapse
-
#cash_transaction ⇒ Boolean
The cash_transaction attribute.
-
#close_level ⇒ Object
The close_level attribute.
-
#currency ⇒ Object
The currency attribute.
-
#date ⇒ Date
The date attribute.
-
#formatted_transaction_type ⇒ String
Returns this transaction’s #transaction_type as a human-readable string.
-
#instrument_name ⇒ Object
The instrument_name attribute.
-
#interest? ⇒ Boolean
Returns whether or not this transaction was an interest payment.
-
#open_level ⇒ String
The open_level attribute.
-
#period ⇒ String
The period attribute.
-
#profit_and_loss ⇒ Object
The profit_and_loss attribute.
-
#profit_and_loss_amount ⇒ Float
Returns this transaction’s #profit_and_loss as a
Float, denominated in this transaction’s #currency. -
#reference ⇒ Object
The reference attribute.
-
#size ⇒ String
The size attribute.
-
#transaction_type ⇒ Symbol
The transaction_type attribute.
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_transaction ⇒ Boolean
The cash_transaction attribute.
6 |
# File 'lib/ig_markets/account_transaction.rb', line 6 attribute :cash_transaction, Boolean |
#close_level ⇒ Object
The close_level attribute.
7 |
# File 'lib/ig_markets/account_transaction.rb', line 7 attribute :close_level |
#currency ⇒ Object
The currency attribute.
8 |
# File 'lib/ig_markets/account_transaction.rb', line 8 attribute :currency |
#date ⇒ Date
The date attribute.
9 |
# File 'lib/ig_markets/account_transaction.rb', line 9 attribute :date, Date, format: '%d/%m/%y' |
#formatted_transaction_type ⇒ String
Returns this transaction’s #transaction_type as a human-readable 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_name ⇒ Object
The instrument_name attribute.
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.
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_level ⇒ String
The open_level attribute.
11 |
# File 'lib/ig_markets/account_transaction.rb', line 11 attribute :open_level, String, nil_if: '-' |
#period ⇒ String
The period attribute.
12 |
# File 'lib/ig_markets/account_transaction.rb', line 12 attribute :period, String, nil_if: '-' |
#profit_and_loss ⇒ Object
The profit_and_loss attribute.
13 |
# File 'lib/ig_markets/account_transaction.rb', line 13 attribute :profit_and_loss |
#profit_and_loss_amount ⇒ Float
Returns this transaction’s #profit_and_loss as a Float, denominated in this transaction’s #currency.
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 |
#reference ⇒ Object
The reference attribute.
14 |
# File 'lib/ig_markets/account_transaction.rb', line 14 attribute :reference |
#size ⇒ String
The size attribute.
15 |
# File 'lib/ig_markets/account_transaction.rb', line 15 attribute :size, String, nil_if: '-' |
#transaction_type ⇒ Symbol
The transaction_type attribute.
16 |
# File 'lib/ig_markets/account_transaction.rb', line 16 attribute :transaction_type, Symbol, allowed_values: [:deal, :depo, :dividend, :exchange, :with] |