Class: SchwabRb::DataObjects::Instrument

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol:, description:, asset_type: nil, cusip: nil, net_change: nil, type: nil, put_call: nil, underlying_symbol: nil, status: nil, instrument_id: nil, closing_price: nil, option_deliverables: []) ⇒ Instrument

Returns a new instance of Instrument.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/schwab_rb/data_objects/instrument.rb', line 117

def initialize(
  symbol:, description:, asset_type: nil, cusip: nil, net_change: nil, type: nil, put_call: nil, underlying_symbol: nil, status: nil, instrument_id: nil, closing_price: nil, option_deliverables: []
)
  @asset_type = asset_type
  @cusip = cusip
  @symbol = symbol
  @description = description
  @net_change = net_change
  @type = type
  @put_call = put_call
  @underlying_symbol = underlying_symbol
  @status = status
  @instrument_id = instrument_id
  @closing_price = closing_price
  @option_deliverables = option_deliverables
end

Instance Attribute Details

#asset_typeObject (readonly)

Returns the value of attribute asset_type.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def asset_type
  @asset_type
end

#closing_priceObject (readonly)

Returns the value of attribute closing_price.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def closing_price
  @closing_price
end

#cusipObject (readonly)

Returns the value of attribute cusip.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def cusip
  @cusip
end

#descriptionObject (readonly)

Returns the value of attribute description.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def description
  @description
end

#instrument_idObject (readonly)

Returns the value of attribute instrument_id.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def instrument_id
  @instrument_id
end

#net_changeObject (readonly)

Returns the value of attribute net_change.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def net_change
  @net_change
end

#option_deliverablesObject (readonly)

Returns the value of attribute option_deliverables.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def option_deliverables
  @option_deliverables
end

#put_callObject (readonly)

Returns the value of attribute put_call.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def put_call
  @put_call
end

#statusObject (readonly)

Returns the value of attribute status.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def status
  @status
end

#symbolObject (readonly)

Returns the value of attribute symbol.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def symbol
  @symbol
end

#typeObject (readonly)

Returns the value of attribute type.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def type
  @type
end

#underlying_symbolObject (readonly)

Returns the value of attribute underlying_symbol.



97
98
99
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97

def underlying_symbol
  @underlying_symbol
end

Class Method Details

.build(data) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/schwab_rb/data_objects/instrument.rb', line 100

def self.build(data)
  new(
    asset_type: data.fetch(:assetType),
    symbol: data.fetch(:symbol, nil),
    description: data.fetch(:description, nil),
    cusip: data.fetch(:cusip, nil),
    net_change: data.fetch(:netChange, nil),
    type: data.fetch(:type, nil),
    put_call: data.fetch(:putCall, nil),
    underlying_symbol: data.fetch(:underlyingSymbol, nil),
    status: data.fetch(:status, nil),
    instrument_id: data.fetch(:instrumentId, nil),
    closing_price: data.fetch(:closingPrice, nil),
    option_deliverables: data.fetch(:optionDeliverables, []).map { |d| OptionDeliverable.build(d) }
  )
end

Instance Method Details

#equity?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/schwab_rb/data_objects/instrument.rb', line 138

def equity?
  asset_type == "EQUITY"
end

#option?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/schwab_rb/data_objects/instrument.rb', line 134

def option?
  asset_type == "OPTION"
end

#to_hObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/schwab_rb/data_objects/instrument.rb', line 142

def to_h
  {
    assetType: @asset_type,
    symbol: @symbol,
    description: @description,
    cusip: @cusip,
    netChange: @net_change,
    type: @type,
    putCall: @put_call,
    underlyingSymbol: @underlying_symbol,
    status: @status,
    instrumentId: @instrument_id,
    closingPrice: @closing_price,
    optionDeliverables: @option_deliverables.map(&:to_h)
  }.compact
end