Class: SchwabRb::Orders::VerticalRollOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/orders/vertical_roll_order.rb

Class Method Summary collapse

Class Method Details

.build(close_short_leg_symbol:, close_long_leg_symbol:, open_short_leg_symbol:, open_long_leg_symbol:, price:, stop_price: nil, order_type: nil, duration: SchwabRb::Orders::Duration::DAY, credit_debit: :credit, quantity: 1) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/schwab_rb/orders/vertical_roll_order.rb', line 9

def build(
  close_short_leg_symbol:,
  close_long_leg_symbol:,
  open_short_leg_symbol:,
  open_long_leg_symbol:,
  price:,
  stop_price: nil,
  order_type: nil,
  duration: SchwabRb::Orders::Duration::DAY,
  credit_debit: :credit,
  quantity: 1
)
  schwab_order_builder.new.tap do |builder|
    builder.set_order_strategy_type(SchwabRb::Order::OrderStrategyTypes::SINGLE)
    builder.set_session(SchwabRb::Orders::Session::NORMAL)
    builder.set_duration(duration)
    builder.set_order_type(order_type || determine_order_type(credit_debit))
    builder.set_complex_order_strategy_type(SchwabRb::Order::ComplexOrderStrategyTypes::VERTICAL_ROLL)
    builder.set_quantity(quantity)
    builder.set_price(price)
    builder.set_stop_price(stop_price) if stop_price && order_type == SchwabRb::Order::Types::STOP_LIMIT

    # Close the existing spread (opposite instructions)
    builder.add_option_leg(
      SchwabRb::Orders::OptionInstructions::BUY_TO_CLOSE,
      close_short_leg_symbol,
      quantity
    )
    builder.add_option_leg(
      SchwabRb::Orders::OptionInstructions::SELL_TO_CLOSE,
      close_long_leg_symbol,
      quantity
    )

    # Open the new spread
    builder.add_option_leg(
      SchwabRb::Orders::OptionInstructions::SELL_TO_OPEN,
      open_short_leg_symbol,
      quantity
    )
    builder.add_option_leg(
      SchwabRb::Orders::OptionInstructions::BUY_TO_OPEN,
      open_long_leg_symbol,
      quantity
    )
  end
end

.determine_order_type(credit_debit) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/schwab_rb/orders/vertical_roll_order.rb', line 57

def determine_order_type(credit_debit)
  if credit_debit == :credit
    SchwabRb::Order::Types::NET_CREDIT
  else
    SchwabRb::Order::Types::NET_DEBIT
  end
end

.schwab_order_builderObject



65
66
67
# File 'lib/schwab_rb/orders/vertical_roll_order.rb', line 65

def schwab_order_builder
  SchwabRb::Orders::Builder
end