Class: SchwabRb::DataObjects::Instrument
- Inherits:
-
Object
- Object
- SchwabRb::DataObjects::Instrument
- Defined in:
- lib/schwab_rb/data_objects/instrument.rb
Instance Attribute Summary collapse
-
#asset_type ⇒ Object
readonly
Returns the value of attribute asset_type.
-
#closing_price ⇒ Object
readonly
Returns the value of attribute closing_price.
-
#cusip ⇒ Object
readonly
Returns the value of attribute cusip.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#instrument_id ⇒ Object
readonly
Returns the value of attribute instrument_id.
-
#net_change ⇒ Object
readonly
Returns the value of attribute net_change.
-
#option_deliverables ⇒ Object
readonly
Returns the value of attribute option_deliverables.
-
#put_call ⇒ Object
readonly
Returns the value of attribute put_call.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#underlying_symbol ⇒ Object
readonly
Returns the value of attribute underlying_symbol.
Class Method Summary collapse
Instance Method Summary collapse
- #equity? ⇒ Boolean
-
#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
constructor
A new instance of Instrument.
- #option? ⇒ Boolean
- #to_h ⇒ Object
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 = @status = status @instrument_id = instrument_id @closing_price = closing_price @option_deliverables = option_deliverables end |
Instance Attribute Details
#asset_type ⇒ Object (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_price ⇒ Object (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 |
#cusip ⇒ Object (readonly)
Returns the value of attribute cusip.
97 98 99 |
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97 def cusip @cusip end |
#description ⇒ Object (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_id ⇒ Object (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_change ⇒ Object (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_deliverables ⇒ Object (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_call ⇒ Object (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 |
#status ⇒ Object (readonly)
Returns the value of attribute status.
97 98 99 |
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97 def status @status end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
97 98 99 |
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97 def symbol @symbol end |
#type ⇒ Object (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_symbol ⇒ Object (readonly)
Returns the value of attribute underlying_symbol.
97 98 99 |
# File 'lib/schwab_rb/data_objects/instrument.rb', line 97 def @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
138 139 140 |
# File 'lib/schwab_rb/data_objects/instrument.rb', line 138 def equity? asset_type == "EQUITY" end |
#option? ⇒ Boolean
134 135 136 |
# File 'lib/schwab_rb/data_objects/instrument.rb', line 134 def option? asset_type == "OPTION" end |
#to_h ⇒ Object
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 |