Class: SchwabRb::DataObjects::Transaction
- Inherits:
-
Object
- Object
- SchwabRb::DataObjects::Transaction
- Defined in:
- lib/schwab_rb/data_objects/transaction.rb
Instance Attribute Summary collapse
-
#activity_id ⇒ Object
readonly
Returns the value of attribute activity_id.
-
#net_amount ⇒ Object
readonly
Returns the value of attribute net_amount.
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#position_id ⇒ Object
readonly
Returns the value of attribute position_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#sub_account ⇒ Object
readonly
Returns the value of attribute sub_account.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#trade_date ⇒ Object
readonly
Returns the value of attribute trade_date.
-
#transfer_items ⇒ Object
readonly
Returns the value of attribute transfer_items.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #asset_instrument_id ⇒ Object
- #asset_symbol ⇒ Object
- #commissions ⇒ Object
- #credit_debits ⇒ Object
- #fees ⇒ Object
-
#initialize(activity_id:, time:, type:, status:, sub_account:, trade_date:, position_id:, order_id:, net_amount:, transfer_items: []) ⇒ Transaction
constructor
A new instance of Transaction.
- #symbols ⇒ Object
- #to_h ⇒ Object
- #trade? ⇒ Boolean
Constructor Details
#initialize(activity_id:, time:, type:, status:, sub_account:, trade_date:, position_id:, order_id:, net_amount:, transfer_items: []) ⇒ Transaction
Returns a new instance of Transaction.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 103 def initialize(activity_id:, time:, type:, status:, sub_account:, trade_date:, position_id:, order_id:, net_amount:, transfer_items: []) @activity_id = activity_id @time = time @type = type @status = status @sub_account = sub_account @trade_date = trade_date @position_id = position_id @order_id = order_id @net_amount = net_amount @transfer_items = transfer_items end |
Instance Attribute Details
#activity_id ⇒ Object (readonly)
Returns the value of attribute activity_id.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def activity_id @activity_id end |
#net_amount ⇒ Object (readonly)
Returns the value of attribute net_amount.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def net_amount @net_amount end |
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def order_id @order_id end |
#position_id ⇒ Object (readonly)
Returns the value of attribute position_id.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def position_id @position_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def status @status end |
#sub_account ⇒ Object (readonly)
Returns the value of attribute sub_account.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def sub_account @sub_account end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def time @time end |
#trade_date ⇒ Object (readonly)
Returns the value of attribute trade_date.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def trade_date @trade_date end |
#transfer_items ⇒ Object (readonly)
Returns the value of attribute transfer_items.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def transfer_items @transfer_items end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
117 118 119 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 117 def type @type end |
Class Method Details
.build(data) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 87 def build(data) Transaction.new( activity_id: data.fetch(:activityId), time: data.fetch(:time), type: data.fetch(:type), status: data.fetch(:status), sub_account: data.fetch(:subAccount), trade_date: data.fetch(:tradeDate), position_id: data.fetch(:positionId, nil), order_id: data.fetch(:orderId, nil), net_amount: data.fetch(:netAmount, nil), transfer_items: data.fetch(:transferItems).map { |ti| TransferItem.build(ti) } ) end |
Instance Method Details
#asset_instrument_id ⇒ Object
144 145 146 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 144 def asset_instrument_id transfer_items.find { |ti| ti.asset? }.instrument_id end |
#asset_symbol ⇒ Object
140 141 142 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 140 def asset_symbol transfer_items.find { |ti| ti.asset? }.symbol end |
#commissions ⇒ Object
132 133 134 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 132 def commissions transfer_items.select(&:commission?).map { |ti| ti.cost } end |
#credit_debits ⇒ Object
124 125 126 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 124 def credit_debits transfer_items.select(&:credit_debit?).map { |ti| ti.cost } end |
#fees ⇒ Object
128 129 130 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 128 def fees transfer_items.select(&:fee?).map { |ti| ti.cost } end |
#symbols ⇒ Object
136 137 138 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 136 def symbols transfer_items.map { |ti| ti.symbol } end |
#to_h ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 148 def to_h { activity_id: @activity_id, time: @time, type: @type, status: @status, sub_account: @sub_account, trade_date: @trade_date, position_id: @position_id, order_id: @order_id, net_amount: @net_amount, transfer_items: @transfer_items.map(&:to_h) } end |
#trade? ⇒ Boolean
120 121 122 |
# File 'lib/schwab_rb/data_objects/transaction.rb', line 120 def trade? type == "TRADE" end |