Class: Tastytrade::Models::LiveOrderLeg

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

Overview

Represents a leg in a live order

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def action
  @action
end

#execution_priceObject (readonly)

Returns the value of attribute execution_price.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def execution_price
  @execution_price
end

#fill_priceObject (readonly)

Returns the value of attribute fill_price.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def fill_price
  @fill_price
end

#fill_quantityObject (readonly)

Returns the value of attribute fill_quantity.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def fill_quantity
  @fill_quantity
end

#fillsObject (readonly)

Returns the value of attribute fills.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def fills
  @fills
end

#instrument_typeObject (readonly)

Returns the value of attribute instrument_type.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def instrument_type
  @instrument_type
end

#position_effectObject (readonly)

Returns the value of attribute position_effect.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def position_effect
  @position_effect
end

#quantityObject (readonly)

Returns the value of attribute quantity.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def quantity
  @quantity
end

#ratio_quantityObject (readonly)

Returns the value of attribute ratio_quantity.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def ratio_quantity
  @ratio_quantity
end

#remaining_quantityObject (readonly)

Returns the value of attribute remaining_quantity.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def remaining_quantity
  @remaining_quantity
end

#symbolObject (readonly)

Returns the value of attribute symbol.



172
173
174
# File 'lib/tastytrade/models/live_order.rb', line 172

def symbol
  @symbol
end

Instance Method Details

#filled?Boolean

Check if leg is completely filled

Returns:

  • (Boolean)


183
184
185
# File 'lib/tastytrade/models/live_order.rb', line 183

def filled?
  @remaining_quantity.to_i == 0
end

#filled_quantityObject

Calculate filled quantity



177
178
179
180
# File 'lib/tastytrade/models/live_order.rb', line 177

def filled_quantity
  return 0 if @quantity.nil? || @remaining_quantity.nil?
  @quantity - @remaining_quantity
end

#partially_filled?Boolean

Check if leg is partially filled

Returns:

  • (Boolean)


188
189
190
# File 'lib/tastytrade/models/live_order.rb', line 188

def partially_filled?
  !filled? && filled_quantity > 0
end

#to_hObject

Convert to hash for JSON serialization



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/tastytrade/models/live_order.rb', line 193

def to_h
  {
    symbol: @symbol,
    instrument_type: @instrument_type,
    action: @action,
    quantity: @quantity,
    remaining_quantity: @remaining_quantity,
    filled_quantity: filled_quantity,
    fill_quantity: @fill_quantity,
    fill_price: @fill_price&.to_s("F"),
    execution_price: @execution_price&.to_s("F"),
    position_effect: @position_effect,
    ratio_quantity: @ratio_quantity,
    fills: @fills&.map(&:to_h)
  }.compact
end