Class: SchwabRb::DataObjects::TransferItem

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/data_objects/transaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instrument:, amount:, cost:, fee_type:, position_effect:) ⇒ TransferItem



22
23
24
25
26
27
28
# File 'lib/schwab_rb/data_objects/transaction.rb', line 22

def initialize(instrument:, amount:, cost:, fee_type:, position_effect:)
  @instrument = instrument
  @amount = amount
  @cost = cost
  @fee_type = fee_type
  @position_effect = position_effect
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



20
21
22
# File 'lib/schwab_rb/data_objects/transaction.rb', line 20

def amount
  @amount
end

#costObject (readonly)

Returns the value of attribute cost.



20
21
22
# File 'lib/schwab_rb/data_objects/transaction.rb', line 20

def cost
  @cost
end

#fee_typeObject (readonly)

Returns the value of attribute fee_type.



20
21
22
# File 'lib/schwab_rb/data_objects/transaction.rb', line 20

def fee_type
  @fee_type
end

#instrumentObject (readonly)

Returns the value of attribute instrument.



20
21
22
# File 'lib/schwab_rb/data_objects/transaction.rb', line 20

def instrument
  @instrument
end

#position_effectObject (readonly)

Returns the value of attribute position_effect.



20
21
22
# File 'lib/schwab_rb/data_objects/transaction.rb', line 20

def position_effect
  @position_effect
end

Class Method Details

.build(data) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/schwab_rb/data_objects/transaction.rb', line 9

def build(data)
  TransferItem.new(
    instrument: Instrument.build(data.fetch(:instrument)),
    amount: data.fetch(:amount),
    cost: data.fetch(:cost),
    fee_type: data.fetch(:feeType, nil),
    position_effect: data.fetch(:positionEffect, nil)
  )
end

Instance Method Details

#asset?Boolean



54
55
56
# File 'lib/schwab_rb/data_objects/transaction.rb', line 54

def asset?
  option? || equity?
end

#commission?Boolean



70
71
72
# File 'lib/schwab_rb/data_objects/transaction.rb', line 70

def commission?
  fee_type == "COMMISSION"
end

#credit_debit?Boolean



62
63
64
# File 'lib/schwab_rb/data_objects/transaction.rb', line 62

def credit_debit?
  fee_type.nil?
end

#descriptionObject



42
43
44
# File 'lib/schwab_rb/data_objects/transaction.rb', line 42

def description
  asset? ? instrument.description : ""
end

#equity?Boolean



50
51
52
# File 'lib/schwab_rb/data_objects/transaction.rb', line 50

def equity?
  instrument.equity?
end

#fee?Boolean



66
67
68
# File 'lib/schwab_rb/data_objects/transaction.rb', line 66

def fee?
  %w[OPT_REG_FEE TAF_FEE SEC_FEE INDEX_OPTION_FEE].include?(fee_type)
end

#instrument_idObject



30
31
32
# File 'lib/schwab_rb/data_objects/transaction.rb', line 30

def instrument_id
  instrument.instrument_id
end

#option?Boolean



46
47
48
# File 'lib/schwab_rb/data_objects/transaction.rb', line 46

def option?
  instrument.option?
end

#put_callObject



58
59
60
# File 'lib/schwab_rb/data_objects/transaction.rb', line 58

def put_call
  instrument.put_call
end

#symbolObject



34
35
36
# File 'lib/schwab_rb/data_objects/transaction.rb', line 34

def symbol
  instrument.symbol
end

#to_hObject



74
75
76
77
78
79
80
81
82
# File 'lib/schwab_rb/data_objects/transaction.rb', line 74

def to_h
  {
    instrument: instrument.to_h,
    amount: amount,
    cost: cost,
    fee_type: fee_type,
    position_effect: position_effect
  }
end

#underlying_symbolObject



38
39
40
# File 'lib/schwab_rb/data_objects/transaction.rb', line 38

def underlying_symbol
  option? ? instrument.underlying_symbol : ""
end