Class: IGMarkets::Transaction

Inherits:
Model
  • Object
show all
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

#attributes

Instance Method Summary collapse

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_transactionBoolean

The cash_transaction attribute.

Returns:


5
# File 'lib/ig_markets/transaction.rb', line 5

attribute :cash_transaction, Boolean

#close_levelString

The close_level attribute.

Returns:

  • (String)

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

attribute :close_level, String, nil_if: %w[- 0]

#currencyObject

The currency attribute.

Returns:

  • []


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

attribute :currency

#date_utcTime

The date_utc attribute.

Returns:

  • (Time)

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

attribute :date_utc, Time, format: '%FT%T'

#instrument_nameObject

The instrument_name attribute.

Returns:

  • []


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.

Returns:


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_utcTime

The open_date_utc attribute.

Returns:

  • (Time)

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

attribute :open_date_utc, Time, format: '%FT%T'

#open_levelString

The open_level attribute.

Returns:

  • (String)

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

attribute :open_level, String, nil_if: %w[- 0]

#periodTime

The period attribute.

Returns:

  • (Time)

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_lossObject

The profit_and_loss attribute.

Returns:

  • []


13
# File 'lib/ig_markets/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)

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..-1].delete(',').to_f
end

#referenceObject

The reference attribute.

Returns:

  • []


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

attribute :reference

#sizeString

The size attribute.

Returns:

  • (String)

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

attribute :size, String, nil_if: '-'

#transaction_typeSymbol

The transaction_type attribute.

Returns:

  • (Symbol)

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

attribute :transaction_type, Symbol, allowed_values: %i[chart deal depo dividend exchange trade with]