Class: SchwabRb::Orders::SingleOrder
- Inherits:
-
Object
- Object
- SchwabRb::Orders::SingleOrder
- Defined in:
- lib/schwab_rb/orders/single_order.rb
Class Method Summary collapse
- .build(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
- .leg_instruction(order_instruction, credit_debit) ⇒ Object
- .schwab_order_builder ⇒ Object
Class Method Details
.build(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 |
# File 'lib/schwab_rb/orders/single_order.rb', line 9 def build( 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_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( leg_instruction(order_instruction, credit_debit), symbol, quantity ) end end |
.determine_order_type(credit_debit) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/schwab_rb/orders/single_order.rb', line 35 def determine_order_type(credit_debit) if credit_debit == :credit SchwabRb::Order::Types::NET_CREDIT else SchwabRb::Order::Types::NET_DEBIT end end |
.leg_instruction(order_instruction, credit_debit) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/schwab_rb/orders/single_order.rb', line 43 def leg_instruction(order_instruction, credit_debit) if order_instruction == :open && credit_debit == :credit SchwabRb::Orders::OptionInstructions::SELL_TO_OPEN elsif order_instruction == :open && credit_debit == :debit SchwabRb::Orders::OptionInstructions::BUY_TO_OPEN elsif order_instruction == :close && credit_debit == :debit SchwabRb::Orders::OptionInstructions::BUY_TO_CLOSE elsif order_instruction == :close && credit_debit == :credit SchwabRb::Orders::OptionInstructions::SELL_TO_CLOSE else raise "Unsupported order instruction: #{order_instruction} with credit/debit: #{credit_debit}" end end |
.schwab_order_builder ⇒ Object
57 58 59 |
# File 'lib/schwab_rb/orders/single_order.rb', line 57 def schwab_order_builder SchwabRb::Orders::Builder end |