Class: Tastytrade::Models::LiveOrder

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

Overview

Represents a live order (open or recently closed) from the API

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

#account_numberObject (readonly)

Returns the value of attribute account_number.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def 
  @account_number
end

#cancellableObject (readonly)

Returns the value of attribute cancellable.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def cancellable
  @cancellable
end

#cancelled_atObject (readonly)

Returns the value of attribute cancelled_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def cancelled_at
  @cancelled_at
end

#confirmation_statusObject (readonly)

Returns the value of attribute confirmation_status.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def confirmation_status
  @confirmation_status
end

#contingent_statusObject (readonly)

Returns the value of attribute contingent_status.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def contingent_status
  @contingent_status
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def created_at
  @created_at
end

#editableObject (readonly)

Returns the value of attribute editable.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def editable
  @editable
end

#editedObject (readonly)

Returns the value of attribute edited.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def edited
  @edited
end

#expired_atObject (readonly)

Returns the value of attribute expired_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def expired_at
  @expired_at
end

#filled_atObject (readonly)

Returns the value of attribute filled_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def filled_at
  @filled_at
end

#gtc_dateObject (readonly)

Returns the value of attribute gtc_date.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def gtc_date
  @gtc_date
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def id
  @id
end

#legsObject (readonly)

Returns the value of attribute legs.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def legs
  @legs
end

#live_atObject (readonly)

Returns the value of attribute live_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def live_at
  @live_at
end

#order_ruleObject (readonly)

Returns the value of attribute order_rule.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def order_rule
  @order_rule
end

#order_typeObject (readonly)

Returns the value of attribute order_type.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def order_type
  @order_type
end

#preflight_check_resultObject (readonly)

Returns the value of attribute preflight_check_result.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def preflight_check_result
  @preflight_check_result
end

#priceObject (readonly)

Returns the value of attribute price.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def price
  @price
end

#price_effectObject (readonly)

Returns the value of attribute price_effect.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def price_effect
  @price_effect
end

#received_atObject (readonly)

Returns the value of attribute received_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def received_at
  @received_at
end

#reject_reasonObject (readonly)

Returns the value of attribute reject_reason.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def reject_reason
  @reject_reason
end

#rejected_atObject (readonly)

Returns the value of attribute rejected_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def rejected_at
  @rejected_at
end

#routed_atObject (readonly)

Returns the value of attribute routed_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def routed_at
  @routed_at
end

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def size
  @size
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def status
  @status
end

#stop_triggerObject (readonly)

Returns the value of attribute stop_trigger.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def stop_trigger
  @stop_trigger
end

#terminal_atObject (readonly)

Returns the value of attribute terminal_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def terminal_at
  @terminal_at
end

#time_in_forceObject (readonly)

Returns the value of attribute time_in_force.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def time_in_force
  @time_in_force
end

#underlying_instrument_typeObject (readonly)

Returns the value of attribute underlying_instrument_type.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def underlying_instrument_type
  @underlying_instrument_type
end

#underlying_symbolObject (readonly)

Returns the value of attribute underlying_symbol.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def underlying_symbol
  @underlying_symbol
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def updated_at
  @updated_at
end

#user_tagObject (readonly)

Returns the value of attribute user_tag.



10
11
12
# File 'lib/tastytrade/models/live_order.rb', line 10

def user_tag
  @user_tag
end

Instance Method Details

#cancellable?Boolean

Check if order can be cancelled

Returns:

  • (Boolean)


20
21
22
# File 'lib/tastytrade/models/live_order.rb', line 20

def cancellable?
  @cancellable && status == "Live"
end

#cancelled?Boolean

Check if order has been cancelled

Returns:

  • (Boolean)


45
46
47
# File 'lib/tastytrade/models/live_order.rb', line 45

def cancelled?
  status == "Cancelled"
end

#editable?Boolean

Check if order can be replaced/edited

Returns:

  • (Boolean)


25
26
27
# File 'lib/tastytrade/models/live_order.rb', line 25

def editable?
  @editable && status == "Live"
end

#filled?Boolean

Check if order has been filled

Returns:

  • (Boolean)


40
41
42
# File 'lib/tastytrade/models/live_order.rb', line 40

def filled?
  status == "Filled"
end

#filled_quantityObject

Get filled quantity across all legs



56
57
58
59
# File 'lib/tastytrade/models/live_order.rb', line 56

def filled_quantity
  return 0 unless @legs
  @legs.sum { |leg| leg.filled_quantity || 0 }
end

#remaining_quantityObject

Get remaining quantity across all legs



50
51
52
53
# File 'lib/tastytrade/models/live_order.rb', line 50

def remaining_quantity
  return 0 unless @legs
  @legs.sum { |leg| leg.remaining_quantity || 0 }
end

#terminal?Boolean

Check if order is in a terminal state

Returns:

  • (Boolean)


30
31
32
# File 'lib/tastytrade/models/live_order.rb', line 30

def terminal?
  %w[Filled Cancelled Rejected Expired].include?(status)
end

#to_hObject

Convert to hash for JSON serialization



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tastytrade/models/live_order.rb', line 62

def to_h
  {
    id: @id,
    account_number: @account_number,
    status: @status,
    cancellable: @cancellable,
    editable: @editable,
    edited: @edited,
    time_in_force: @time_in_force,
    order_type: @order_type,
    size: @size,
    price: @price&.to_s("F"),
    price_effect: @price_effect,
    underlying_symbol: @underlying_symbol,
    underlying_instrument_type: @underlying_instrument_type,
    stop_trigger: @stop_trigger&.to_s("F"),
    gtc_date: @gtc_date&.to_s,
    created_at: @created_at&.iso8601,
    updated_at: @updated_at&.iso8601,
    received_at: @received_at&.iso8601,
    routed_at: @routed_at&.iso8601,
    filled_at: @filled_at&.iso8601,
    cancelled_at: @cancelled_at&.iso8601,
    expired_at: @expired_at&.iso8601,
    rejected_at: @rejected_at&.iso8601,
    live_at: @live_at&.iso8601,
    terminal_at: @terminal_at&.iso8601,
    contingent_status: @contingent_status,
    confirmation_status: @confirmation_status,
    reject_reason: @reject_reason,
    user_tag: @user_tag,
    preflight_check_result: @preflight_check_result,
    order_rule: @order_rule,
    legs: @legs&.map(&:to_h),
    remaining_quantity: remaining_quantity,
    filled_quantity: filled_quantity
  }.compact
end

#working?Boolean

Check if order is working (live in market)

Returns:

  • (Boolean)


35
36
37
# File 'lib/tastytrade/models/live_order.rb', line 35

def working?
  status == "Live"
end