Class: Tastytrade::Models::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/tastytrade/models/transaction.rb

Overview

Represents a transaction in a Tastytrade account

Constant Summary collapse

TRANSACTION_TYPES =
%w[
  ACAT Assignment Balance\ Adjustment Cash\ Disbursement Cash\ Merger
  Cash\ Settled\ Assignment Cash\ Settled\ Exercise Credit\ Interest
  Debit\ Interest Deposit Dividend Exercise Expiration Fee Forward\ Split
  Futures\ Settlement Journal\ Entry Mark\ to\ Market Maturity
  Merger\ Acquisition Money\ Movement Name\ Change
  Paid\ Premium\ Lending\ Income Receive\ Deliver Reverse\ Split
  Special\ Dividend Stock\ Dividend Stock\ Loan\ Income Stock\ Merger
  Symbol\ Change Transfer Withdrawal
].freeze
INSTRUMENT_TYPES =
%w[
  Bond Cryptocurrency Equity Equity\ Offering Equity\ Option Future
  Future\ Option Index Unknown Warrant
].freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Class Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Tastytrade::Models::Base

Instance Attribute Details

#account_numberObject (readonly)

Returns the value of attribute account_number.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def 
  @account_number
end

#actionObject (readonly)

Returns the value of attribute action.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def action
  @action
end

#clearing_feesObject (readonly)

Returns the value of attribute clearing_fees.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def clearing_fees
  @clearing_fees
end

#commissionObject (readonly)

Returns the value of attribute commission.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def commission
  @commission
end

#descriptionObject (readonly)

Returns the value of attribute description.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def description
  @description
end

#executed_atObject (readonly)

Returns the value of attribute executed_at.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def executed_at
  @executed_at
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def id
  @id
end

#instrument_typeObject (readonly)

Returns the value of attribute instrument_type.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def instrument_type
  @instrument_type
end

#is_estimated_feeObject (readonly)

Returns the value of attribute is_estimated_fee.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def is_estimated_fee
  @is_estimated_fee
end

#is_verifiedObject (readonly)

Returns the value of attribute is_verified.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def is_verified
  @is_verified
end

#net_valueObject (readonly)

Returns the value of attribute net_value.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def net_value
  @net_value
end

#net_value_effectObject (readonly)

Returns the value of attribute net_value_effect.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def net_value_effect
  @net_value_effect
end

#order_idObject (readonly)

Returns the value of attribute order_id.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def order_id
  @order_id
end

#priceObject (readonly)

Returns the value of attribute price.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def price
  @price
end

#proprietary_index_option_feesObject (readonly)

Returns the value of attribute proprietary_index_option_fees.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def proprietary_index_option_fees
  @proprietary_index_option_fees
end

#quantityObject (readonly)

Returns the value of attribute quantity.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def quantity
  @quantity
end

#regulatory_feesObject (readonly)

Returns the value of attribute regulatory_fees.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def regulatory_fees
  @regulatory_fees
end

#reverses_idObject (readonly)

Returns the value of attribute reverses_id.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def reverses_id
  @reverses_id
end

#symbolObject (readonly)

Returns the value of attribute symbol.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def symbol
  @symbol
end

#transaction_dateObject (readonly)

Returns the value of attribute transaction_date.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def transaction_date
  @transaction_date
end

#transaction_sub_typeObject (readonly)

Returns the value of attribute transaction_sub_type.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def transaction_sub_type
  @transaction_sub_type
end

#transaction_typeObject (readonly)

Returns the value of attribute transaction_type.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def transaction_type
  @transaction_type
end

#underlying_symbolObject (readonly)

Returns the value of attribute underlying_symbol.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def underlying_symbol
  @underlying_symbol
end

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def value
  @value
end

#value_dateObject (readonly)

Returns the value of attribute value_date.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def value_date
  @value_date
end

#value_effectObject (readonly)

Returns the value of attribute value_effect.



11
12
13
# File 'lib/tastytrade/models/transaction.rb', line 11

def value_effect
  @value_effect
end

Class Method Details

.get_all(session, account_number, **options) ⇒ Array<Transaction>

Fetch transaction history for an account

Parameters:

  • session (Tastytrade::Session)

    Active session

  • account_number (String)

    Account number

  • options (Hash)

    Optional filters

Options Hash (**options):

  • :start_date (Date, String)

    Start date for transactions

  • :end_date (Date, String)

    End date for transactions

  • :symbol (String)

    Filter by symbol

  • :underlying_symbol (String)

    Filter by underlying symbol

  • :instrument_type (String)

    Filter by instrument type

  • :transaction_types (Array<String>)

    Filter by transaction types

  • :per_page (Integer)

    Number of results per page (default: 250)

  • :page_offset (Integer)

    Page offset for pagination

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tastytrade/models/transaction.rb', line 47

def self.get_all(session, , **options)
  params = build_params(options)
  transactions = []
  page_offset = options[:page_offset] || 0

  loop do
    current_params = params.dup
    current_params["page-offset"] = page_offset unless page_offset.zero?
    response = session.get("/accounts/#{account_number}/transactions", current_params)

    items = response.dig("data", "items") || []
    break if items.empty?

    transactions.concat(items.map { |item| new(item) })

    # Break if we've reached the requested limit or if pagination is manual
    break if options[:page_offset] || transactions.size >= (options[:per_page] || 250)

    page_offset += 1
  end

  transactions
end