Class: SchwabRb::DataObjects::OrderLeg

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(leg_id:, order_leg_type:, quantity:, instrument:, instruction:, position_effect:) ⇒ OrderLeg

Returns a new instance of OrderLeg.



23
24
25
26
27
28
29
30
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 23

def initialize(leg_id:, order_leg_type:, quantity:, instrument:, instruction:, position_effect:)
  @leg_id = leg_id
  @order_leg_type = order_leg_type
  @quantity = quantity
  @instrument = instrument
  @instruction = instruction
  @position_effect = position_effect
end

Instance Attribute Details

#instructionObject (readonly)

Returns the value of attribute instruction.



8
9
10
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 8

def instruction
  @instruction
end

#instrumentObject (readonly)

Returns the value of attribute instrument.



8
9
10
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 8

def instrument
  @instrument
end

#leg_idObject (readonly)

Returns the value of attribute leg_id.



8
9
10
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 8

def leg_id
  @leg_id
end

#order_leg_typeObject (readonly)

Returns the value of attribute order_leg_type.



8
9
10
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 8

def order_leg_type
  @order_leg_type
end

#position_effectObject (readonly)

Returns the value of attribute position_effect.



8
9
10
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 8

def position_effect
  @position_effect
end

#quantityObject (readonly)

Returns the value of attribute quantity.



8
9
10
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 8

def quantity
  @quantity
end

Class Method Details

.build(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 11

def build(data)
  new(
    leg_id: data[:legId],
    order_leg_type: data[:orderLegType],
    quantity: data[:quantity],
    instrument: Instrument.build(data[:instrument]),
    instruction: data.fetch(:instruction, nil),
    position_effect: data[:positionEffect]
  )
end

Instance Method Details

#call?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 36

def call?
  put_call == "CALL"
end

#close?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 40

def close?
  position_effect == "CLOSING"
end

#descriptionObject



60
61
62
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 60

def description
  instrument.description
end

#instrument_idObject



32
33
34
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 32

def instrument_id
  instrument.instrument_id
end

#open?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 44

def open?
  position_effect == "OPENING"
end

#put?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 48

def put?
  put_call == "PUT"
end

#put_callObject



52
53
54
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 52

def put_call
  instrument.put_call
end

#symbolObject



56
57
58
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 56

def symbol
  instrument.symbol
end

#to_hObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/schwab_rb/data_objects/order_leg.rb', line 64

def to_h
  {
    legId: @leg_id,
    orderLegType: @order_leg_type,
    quantity: @quantity,
    instrument: @instrument.to_h,
    instruction: @instruction,
    positionEffect: @position_effect
  }
end