Class: SchwabRb::Orders::VerticalOrder
- Inherits:
-
Object
- Object
- SchwabRb::Orders::VerticalOrder
- Defined in:
- lib/schwab_rb/orders/vertical_order.rb
Class Method Summary collapse
- .build(short_leg_symbol:, long_leg_symbol:, price:, stop_price: nil, order_type: nil, duration: SchwabRb::Orders::Duration::DAY, credit_debit: :credit, order_instruction: :open, quantity: 1) ⇒ Object
- .determine_order_type(credit_debit) ⇒ Object
- .long_leg_instruction(order_instruction) ⇒ Object
- .schwab_order_builder ⇒ Object
- .short_leg_instruction(order_instruction) ⇒ Object
Class Method Details
.build(short_leg_symbol:, long_leg_symbol:, price:, stop_price: nil, order_type: nil, duration: SchwabRb::Orders::Duration::DAY, credit_debit: :credit, order_instruction: :open, 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 |
# File 'lib/schwab_rb/orders/vertical_order.rb', line 9 def build( short_leg_symbol:, long_leg_symbol:, price:, stop_price: nil, order_type: nil, duration: SchwabRb::Orders::Duration::DAY, credit_debit: :credit, order_instruction: :open, 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) builder.set_quantity(quantity) builder.set_price(price) builder.set_stop_price(stop_price) if stop_price && order_type == SchwabRb::Order::Types::STOP_LIMIT builder.add_option_leg( short_leg_instruction(order_instruction), short_leg_symbol, quantity ) builder.add_option_leg( long_leg_instruction(order_instruction), long_leg_symbol, quantity ) end end |
.determine_order_type(credit_debit) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/schwab_rb/orders/vertical_order.rb', line 40 def determine_order_type(credit_debit) if credit_debit == :credit SchwabRb::Order::Types::NET_CREDIT else SchwabRb::Order::Types::NET_DEBIT end end |
.long_leg_instruction(order_instruction) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/schwab_rb/orders/vertical_order.rb', line 58 def long_leg_instruction(order_instruction) if order_instruction == :open SchwabRb::Orders::OptionInstructions::BUY_TO_OPEN elsif order_instruction == :close SchwabRb::Orders::OptionInstructions::SELL_TO_CLOSE else raise "Unsupported order instruction: #{order_instruction}" end end |
.schwab_order_builder ⇒ Object
68 69 70 |
# File 'lib/schwab_rb/orders/vertical_order.rb', line 68 def schwab_order_builder SchwabRb::Orders::Builder end |
.short_leg_instruction(order_instruction) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/schwab_rb/orders/vertical_order.rb', line 48 def short_leg_instruction(order_instruction) if order_instruction == :open SchwabRb::Orders::OptionInstructions::SELL_TO_OPEN elsif order_instruction == :close SchwabRb::Orders::OptionInstructions::BUY_TO_CLOSE else raise "Unsupported order instruction: #{order_instruction}" end end |