Class: IGMarkets::Transaction
- Defined in:
- lib/ig_markets/transaction.rb
Overview
Contains details on a single transaction that occurred on an IG Markets account. Returned by DealingPlatform::AccountMethods#transactions.
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
-
#cash_transaction ⇒ Boolean
The cash_transaction attribute.
-
#close_level ⇒ String
The close_level attribute.
-
#currency ⇒ Object
The currency attribute.
-
#date_utc ⇒ Time
The date_utc attribute.
-
#instrument_name ⇒ Object
The instrument_name attribute.
-
#interest? ⇒ Boolean
Returns whether or not this transaction was an interest payment.
-
#open_date_utc ⇒ Time
The open_date_utc attribute.
-
#open_level ⇒ String
The open_level attribute.
-
#period ⇒ Time
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, attribute_type, attribute_value_allowed?, defined_attribute_names, deprecated_attribute, #initialize, #initialize_copy, #inspect, #to_h, valid_attribute?
Constructor Details
This class inherits a constructor from IGMarkets::Model
Instance Method Details
#cash_transaction ⇒ Boolean
The cash_transaction attribute.
5 |
# File 'lib/ig_markets/transaction.rb', line 5 attribute :cash_transaction, Boolean |
#close_level ⇒ String
The close_level attribute.
6 |
# File 'lib/ig_markets/transaction.rb', line 6 attribute :close_level, String, nil_if: %w[- 0] |
#currency ⇒ Object
The currency attribute.
7 |
# File 'lib/ig_markets/transaction.rb', line 7 attribute :currency |
#date_utc ⇒ Time
The date_utc attribute.
8 |
# File 'lib/ig_markets/transaction.rb', line 8 attribute :date_utc, Time, format: '%FT%T' |
#instrument_name ⇒ Object
The instrument_name attribute.
9 |
# File 'lib/ig_markets/transaction.rb', line 9 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.
25 26 27 |
# File 'lib/ig_markets/transaction.rb', line 25 def interest? %i[depo with].include?(transaction_type) && !(instrument_name.downcase =~ /(^|[^a-z])interest([^a-z]|$)/).nil? end |
#open_date_utc ⇒ Time
The open_date_utc attribute.
10 |
# File 'lib/ig_markets/transaction.rb', line 10 attribute :open_date_utc, Time, format: '%FT%T' |
#open_level ⇒ String
The open_level attribute.
11 |
# File 'lib/ig_markets/transaction.rb', line 11 attribute :open_level, String, nil_if: %w[- 0] |
#period ⇒ Time
The period attribute.
12 |
# File 'lib/ig_markets/transaction.rb', line 12 attribute :period, Time, nil_if: %w[- DFB], format: ['%FT%T', '%d-%b-%y', '%b-%y'] |
#profit_and_loss ⇒ Object
The profit_and_loss attribute.
13 |
# File 'lib/ig_markets/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.
32 33 34 35 36 |
# File 'lib/ig_markets/transaction.rb', line 32 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..].delete(',').to_f end |
#reference ⇒ Object
The reference attribute.
14 |
# File 'lib/ig_markets/transaction.rb', line 14 attribute :reference |
#size ⇒ String
The size attribute.
15 |
# File 'lib/ig_markets/transaction.rb', line 15 attribute :size, String, nil_if: '-' |
#transaction_type ⇒ Symbol
The transaction_type attribute.
16 |
# File 'lib/ig_markets/transaction.rb', line 16 attribute :transaction_type, Symbol, allowed_values: %i[chart deal depo dividend exchange trade with] |