Class: ThePlaidApi::InvestmentTransaction

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/the_plaid_api/models/investment_transaction.rb

Overview

A transaction within an investment account.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(investment_transaction_id:, account_id:, security_id:, date:, name:, quantity:, amount:, price:, fees:, type:, subtype:, iso_currency_code:, unofficial_currency_code:, cancel_transaction_id: SKIP, transaction_datetime: SKIP, additional_properties: nil) ⇒ InvestmentTransaction

Returns a new instance of InvestmentTransaction.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 146

def initialize(investment_transaction_id:, account_id:, security_id:, date:,
               name:, quantity:, amount:, price:, fees:, type:, subtype:,
               iso_currency_code:, unofficial_currency_code:,
               cancel_transaction_id: SKIP, transaction_datetime: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @investment_transaction_id = investment_transaction_id
  @cancel_transaction_id = cancel_transaction_id unless cancel_transaction_id == SKIP
  @account_id = 
  @security_id = security_id
  @date = date
  @transaction_datetime = transaction_datetime unless transaction_datetime == SKIP
  @name = name
  @quantity = quantity
  @amount = amount
  @price = price
  @fees = fees
  @type = type
  @subtype = subtype
  @iso_currency_code = iso_currency_code
  @unofficial_currency_code = unofficial_currency_code
  @additional_properties = additional_properties
end

Instance Attribute Details

#account_idString

The ‘account_id` of the account against which this transaction posted.

Returns:

  • (String)


26
27
28
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 26

def 
  @account_id
end

#amountFloat

The complete value of the transaction. Positive values when cash is debited, e.g. purchases of stock; negative values when cash is credited, e.g. sales of stock. Treatment remains the same for cash-only movements unassociated with securities.

Returns:

  • (Float)


58
59
60
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 58

def amount
  @amount
end

#cancel_transaction_idString

A legacy field formerly used internally by Plaid to identify certain canceled transactions.

Returns:

  • (String)


22
23
24
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 22

def cancel_transaction_id
  @cancel_transaction_id
end

#dateDate

The [ISO 8601](wikipedia.org/wiki/ISO_8601) posting date for the transaction. This is typically the settlement date.

Returns:

  • (Date)


35
36
37
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 35

def date
  @date
end

#feesFloat

The combined value of all fees applied to this transaction

Returns:

  • (Float)


66
67
68
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 66

def fees
  @fees
end

#investment_transaction_idString

The ID of the Investment transaction, unique across all Plaid transactions. Like all Plaid identifiers, the ‘investment_transaction_id` is case sensitive.

Returns:

  • (String)


17
18
19
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 17

def investment_transaction_id
  @investment_transaction_id
end

#iso_currency_codeString

The ISO-4217 currency code of the transaction. Always ‘null` if `unofficial_currency_code` is non-`null`.

Returns:

  • (String)


93
94
95
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 93

def iso_currency_code
  @iso_currency_code
end

#nameString

The institution’s description of the transaction.

Returns:

  • (String)


46
47
48
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 46

def name
  @name
end

#priceFloat

The price of the security at which this transaction occurred.

Returns:

  • (Float)


62
63
64
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 62

def price
  @price
end

#quantityFloat

The number of units of the security involved in this transaction. Positive for buy transactions; negative for sell transactions.

Returns:

  • (Float)


51
52
53
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 51

def quantity
  @quantity
end

#security_idString

The ‘security_id` to which this transaction is related.

Returns:

  • (String)


30
31
32
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 30

def security_id
  @security_id
end

#subtypeInvestmentTransactionSubtype

For descriptions of possible transaction types and subtypes, see the [Investment transaction types schema](plaid.com/docs/api/accounts/#investment-transaction-types- schema).



88
89
90
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 88

def subtype
  @subtype
end

#transaction_datetimeDateTime

Timestamp in [ISO 8601](wikipedia.org/wiki/ISO_8601) format (‘YYYY-MM-DDTHH:mm:ssZ`) representing when the order type was initiated. This field is returned for select financial institutions and reflects the value provided by the institution.

Returns:

  • (DateTime)


42
43
44
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 42

def transaction_datetime
  @transaction_datetime
end

#typeInvestmentTransactionType

Value is one of the following: ‘buy`: Buying an investment `sell`: Selling an investment `cancel`: A cancellation of a pending transaction `cash`: Activity that modifies a cash position `fee`: A fee on the account `transfer`: Activity which modifies a position, but not through buy/sell activity e.g. options exercise, portfolio transfer For descriptions of possible transaction types and subtypes, see the [Investment transaction types schema](plaid.com/docs/api/accounts/#investment-transaction-types- schema).



81
82
83
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 81

def type
  @type
end

#unofficial_currency_codeString

The unofficial currency code associated with the holding. Always ‘null` if `iso_currency_code` is non-`null`. Unofficial currency codes are used for currencies that do not have official ISO currency codes, such as cryptocurrencies and the currencies of certain countries. See the [currency code schema](plaid.com/docs/api/accounts#currency-code-schema) for a full listing of supported `iso_currency_code`s.

Returns:

  • (String)


103
104
105
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 103

def unofficial_currency_code
  @unofficial_currency_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 173

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  investment_transaction_id =
    hash.key?('investment_transaction_id') ? hash['investment_transaction_id'] : nil
   = hash.key?('account_id') ? hash['account_id'] : nil
  security_id = hash.key?('security_id') ? hash['security_id'] : nil
  date = hash.key?('date') ? hash['date'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil
  price = hash.key?('price') ? hash['price'] : nil
  fees = hash.key?('fees') ? hash['fees'] : nil
  type = hash.key?('type') ? hash['type'] : nil
  subtype = hash.key?('subtype') ? hash['subtype'] : nil
  iso_currency_code =
    hash.key?('iso_currency_code') ? hash['iso_currency_code'] : nil
  unofficial_currency_code =
    hash.key?('unofficial_currency_code') ? hash['unofficial_currency_code'] : nil
  cancel_transaction_id =
    hash.key?('cancel_transaction_id') ? hash['cancel_transaction_id'] : SKIP
  transaction_datetime = if hash.key?('transaction_datetime')
                           (DateTimeHelper.from_rfc3339(hash['transaction_datetime']) if hash['transaction_datetime'])
                         else
                           SKIP
                         end

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  InvestmentTransaction.new(investment_transaction_id: investment_transaction_id,
                            account_id: ,
                            security_id: security_id,
                            date: date,
                            name: name,
                            quantity: quantity,
                            amount: amount,
                            price: price,
                            fees: fees,
                            type: type,
                            subtype: subtype,
                            iso_currency_code: iso_currency_code,
                            unofficial_currency_code: unofficial_currency_code,
                            cancel_transaction_id: cancel_transaction_id,
                            transaction_datetime: transaction_datetime,
                            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 106

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['investment_transaction_id'] = 'investment_transaction_id'
  @_hash['cancel_transaction_id'] = 'cancel_transaction_id'
  @_hash['account_id'] = 'account_id'
  @_hash['security_id'] = 'security_id'
  @_hash['date'] = 'date'
  @_hash['transaction_datetime'] = 'transaction_datetime'
  @_hash['name'] = 'name'
  @_hash['quantity'] = 'quantity'
  @_hash['amount'] = 'amount'
  @_hash['price'] = 'price'
  @_hash['fees'] = 'fees'
  @_hash['type'] = 'type'
  @_hash['subtype'] = 'subtype'
  @_hash['iso_currency_code'] = 'iso_currency_code'
  @_hash['unofficial_currency_code'] = 'unofficial_currency_code'
  @_hash
end

.nullablesObject

An array for nullable fields



135
136
137
138
139
140
141
142
143
144
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 135

def self.nullables
  %w[
    cancel_transaction_id
    security_id
    transaction_datetime
    fees
    iso_currency_code
    unofficial_currency_code
  ]
end

.optionalsObject

An array for optional fields



127
128
129
130
131
132
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 127

def self.optionals
  %w[
    cancel_transaction_id
    transaction_datetime
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



244
245
246
247
248
249
250
251
252
253
254
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 244

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} investment_transaction_id: #{@investment_transaction_id.inspect},"\
  " cancel_transaction_id: #{@cancel_transaction_id.inspect}, account_id:"\
  " #{@account_id.inspect}, security_id: #{@security_id.inspect}, date: #{@date.inspect},"\
  " transaction_datetime: #{@transaction_datetime.inspect}, name: #{@name.inspect}, quantity:"\
  " #{@quantity.inspect}, amount: #{@amount.inspect}, price: #{@price.inspect}, fees:"\
  " #{@fees.inspect}, type: #{@type.inspect}, subtype: #{@subtype.inspect}, iso_currency_code:"\
  " #{@iso_currency_code.inspect}, unofficial_currency_code:"\
  " #{@unofficial_currency_code.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_transaction_datetimeObject



227
228
229
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 227

def to_custom_transaction_datetime
  DateTimeHelper.to_rfc3339(transaction_datetime)
end

#to_sObject

Provides a human-readable string representation of the object.



232
233
234
235
236
237
238
239
240
241
# File 'lib/the_plaid_api/models/investment_transaction.rb', line 232

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} investment_transaction_id: #{@investment_transaction_id},"\
  " cancel_transaction_id: #{@cancel_transaction_id}, account_id: #{@account_id}, security_id:"\
  " #{@security_id}, date: #{@date}, transaction_datetime: #{@transaction_datetime}, name:"\
  " #{@name}, quantity: #{@quantity}, amount: #{@amount}, price: #{@price}, fees: #{@fees},"\
  " type: #{@type}, subtype: #{@subtype}, iso_currency_code: #{@iso_currency_code},"\
  " unofficial_currency_code: #{@unofficial_currency_code}, additional_properties:"\
  " #{@additional_properties}>"
end