schwab_rb 0.3.11 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,8 +27,6 @@ module SchwabRb
27
27
  end
28
28
 
29
29
  module Types
30
- # Execute the order immediately at the best-available price.
31
- # More Info <https://www.investopedia.com/terms/m/marketorder.asp>
32
30
  MARKET = "MARKET"
33
31
  LIMIT = "LIMIT"
34
32
  STOP = "STOP"
@@ -45,6 +43,18 @@ module SchwabRb
45
43
  LIMIT_ON_CLOSE = "LIMIT_ON_CLOSE"
46
44
  end
47
45
 
46
+ module OrderStrategyTypes
47
+ SINGLE = "SINGLE"
48
+ CANCEL = "CANCEL"
49
+ RECALL = "RECALL"
50
+ PAIR = "PAIR"
51
+ FLATTEN = "FLATTEN"
52
+ TWO_DAY_SWAP = "TWO_DAY_SWAP"
53
+ BLAST_ALL = "BLAST_ALL"
54
+ OCO = "OCO"
55
+ TRIGGER = "TRIGGER"
56
+ end
57
+
48
58
  module ComplexOrderStrategyTypes
49
59
  # Explicit order strategies for executing multi-leg options orders.
50
60
 
@@ -75,5 +85,38 @@ module SchwabRb
75
85
  # A custom multi-leg order strategy.
76
86
  CUSTOM = "CUSTOM"
77
87
  end
88
+
89
+ ALL_ORDER_STRATEGY_TYPES = [
90
+ OrderStrategyTypes::SINGLE,
91
+ OrderStrategyTypes::CANCEL,
92
+ OrderStrategyTypes::RECALL,
93
+ OrderStrategyTypes::PAIR,
94
+ OrderStrategyTypes::FLATTEN,
95
+ OrderStrategyTypes::TWO_DAY_SWAP,
96
+ OrderStrategyTypes::BLAST_ALL,
97
+ OrderStrategyTypes::OCO,
98
+ OrderStrategyTypes::TRIGGER,
99
+ ComplexOrderStrategyTypes::NONE,
100
+ ComplexOrderStrategyTypes::COVERED,
101
+ ComplexOrderStrategyTypes::VERTICAL,
102
+ ComplexOrderStrategyTypes::BACK_RATIO,
103
+ ComplexOrderStrategyTypes::CALENDAR,
104
+ ComplexOrderStrategyTypes::DIAGONAL,
105
+ ComplexOrderStrategyTypes::STRADDLE,
106
+ ComplexOrderStrategyTypes::STRANGLE,
107
+ ComplexOrderStrategyTypes::COLLAR_SYNTHETIC,
108
+ ComplexOrderStrategyTypes::BUTTERFLY,
109
+ ComplexOrderStrategyTypes::CONDOR,
110
+ ComplexOrderStrategyTypes::IRON_CONDOR,
111
+ ComplexOrderStrategyTypes::VERTICAL_ROLL,
112
+ ComplexOrderStrategyTypes::COLLAR_WITH_STOCK,
113
+ ComplexOrderStrategyTypes::DOUBLE_DIAGONAL,
114
+ ComplexOrderStrategyTypes::UNBALANCED_BUTTERFLY,
115
+ ComplexOrderStrategyTypes::UNBALANCED_CONDOR,
116
+ ComplexOrderStrategyTypes::UNBALANCED_IRON_CONDOR,
117
+ ComplexOrderStrategyTypes::UNBALANCED_VERTICAL_ROLL,
118
+ ComplexOrderStrategyTypes::MUTUAL_FUND_SWAP,
119
+ ComplexOrderStrategyTypes::CUSTOM
120
+ ].freeze
78
121
  end
79
122
  end
@@ -1,46 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'iron_condor_order'
4
- require_relative 'vertical_order'
5
- require_relative 'single_order'
3
+ require_relative "iron_condor_order"
4
+ require_relative "vertical_order"
5
+ require_relative "single_order"
6
+ require_relative "oco_order"
7
+ require_relative "order"
6
8
 
7
9
  module SchwabRb
8
10
  module Orders
9
11
  class OrderFactory
10
12
  class << self
11
13
  def build(**options)
12
- case options[:strategy_type] || 'none'
13
- when 'ironcondor'
14
+ case options[:strategy_type] || "none"
15
+ when SchwabRb::Order::ComplexOrderStrategyTypes::IRON_CONDOR
14
16
  IronCondorOrder.build(
15
17
  put_short_symbol: options[:put_short_symbol],
16
18
  put_long_symbol: options[:put_long_symbol],
17
19
  call_short_symbol: options[:call_short_symbol],
18
20
  call_long_symbol: options[:call_long_symbol],
19
21
  price: options[:price],
20
- account_number: options[:account_number],
22
+ stop_price: options[:stop_price],
23
+ duration: options[:duration] || SchwabRb::Orders::Duration::DAY,
21
24
  credit_debit: options[:credit_debit] || :credit,
22
25
  order_instruction: options[:order_instruction] || :open,
23
26
  quantity: options[:quantity] || 1
24
27
  )
25
- when 'vertical' # call or put spreads
28
+ when SchwabRb::Order::ComplexOrderStrategyTypes::VERTICAL # call or put spreads
26
29
  VerticalOrder.build(
27
30
  short_leg_symbol: options[:short_leg_symbol],
28
31
  long_leg_symbol: options[:long_leg_symbol],
29
32
  price: options[:price],
30
- account_number: options[:account_number],
33
+ stop_price: options[:stop_price],
34
+ order_type: options[:order_type],
35
+ duration: options[:duration] || SchwabRb::Orders::Duration::DAY,
31
36
  credit_debit: options[:credit_debit] || :credit,
32
37
  order_instruction: options[:order_instruction] || :open,
33
38
  quantity: options[:quantity] || 1
34
39
  )
35
- when 'single'
40
+ when SchwabRb::Order::OrderStrategyTypes::SINGLE
36
41
  SingleOrder.build(
37
42
  symbol: options[:symbol],
38
43
  price: options[:price],
39
- account_number: options[:account_number],
44
+ stop_price: options[:stop_price],
45
+ order_type: options[:order_type],
46
+ duration: options[:duration] || SchwabRb::Orders::Duration::DAY,
40
47
  credit_debit: options[:credit_debit] || :credit,
41
48
  order_instruction: options[:order_instruction] || :open,
42
49
  quantity: options[:quantity] || 1
43
50
  )
51
+ when SchwabRb::Order::OrderStrategyTypes::OCO
52
+ OcoOrder.build(
53
+ child_order_specs: options[:child_order_specs]
54
+ )
44
55
  else
45
56
  raise "Unsupported trade strategy: #{options[:strategy_type] || 'none'}"
46
57
  end
@@ -1,20 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'schwab_rb'
3
+ require "schwab_rb"
4
4
 
5
5
  module SchwabRb
6
6
  module Orders
7
7
  class SingleOrder
8
8
  class << self
9
- def build(symbol:, price:, account_number:, credit_debit: :credit, order_instruction: :open, quantity: 1)
9
+ def build(
10
+ symbol:,
11
+ price:,
12
+ stop_price: nil,
13
+ order_type: nil,
14
+ duration: SchwabRb::Orders::Duration::DAY,
15
+ credit_debit: :credit,
16
+ order_instruction: :open,
17
+ quantity: 1
18
+ )
10
19
  schwab_order_builder.new.tap do |builder|
11
- builder.set_account_number(account_number)
12
- builder.set_order_strategy_type('SINGLE')
20
+ builder.set_order_strategy_type(SchwabRb::Order::OrderStrategyTypes::SINGLE)
13
21
  builder.set_session(SchwabRb::Orders::Session::NORMAL)
14
- builder.set_duration(SchwabRb::Orders::Duration::DAY)
15
- builder.set_order_type(order_type(credit_debit))
22
+ builder.set_duration(duration)
23
+ builder.set_order_type(order_type || determine_order_type(credit_debit))
16
24
  builder.set_quantity(quantity)
17
25
  builder.set_price(price)
26
+ builder.set_stop_price(stop_price) if stop_price && order_type == SchwabRb::Order::Types::STOP_LIMIT
18
27
  builder.add_option_leg(
19
28
  leg_instruction(order_instruction, credit_debit),
20
29
  symbol,
@@ -23,7 +32,7 @@ module SchwabRb
23
32
  end
24
33
  end
25
34
 
26
- def order_type(credit_debit)
35
+ def determine_order_type(credit_debit)
27
36
  if credit_debit == :credit
28
37
  SchwabRb::Order::Types::NET_CREDIT
29
38
  else
@@ -1,38 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'schwab_rb'
3
+ require "schwab_rb"
4
4
 
5
5
  module SchwabRb
6
6
  module Orders
7
7
  class VerticalOrder
8
8
  class << self
9
9
  def build(
10
- short_leg_symbol:, long_leg_symbol:, price:,
11
- account_number:, credit_debit: :credit, order_instruction: :open, quantity: 1
10
+ short_leg_symbol:, long_leg_symbol:,
11
+ price:,
12
+ stop_price: nil,
13
+ order_type: nil,
14
+ duration: SchwabRb::Orders::Duration::DAY,
15
+ credit_debit: :credit,
16
+ order_instruction: :open, quantity: 1
12
17
  )
13
18
  schwab_order_builder.new.tap do |builder|
14
- builder.set_account_number(account_number)
15
- builder.set_order_strategy_type('SINGLE')
19
+ builder.set_order_strategy_type(SchwabRb::Order::OrderStrategyTypes::SINGLE)
16
20
  builder.set_session(SchwabRb::Orders::Session::NORMAL)
17
- builder.set_duration(SchwabRb::Orders::Duration::DAY)
18
- builder.set_order_type(order_type(credit_debit))
21
+ builder.set_duration(duration)
22
+ builder.set_order_type(order_type || determine_order_type(credit_debit))
19
23
  builder.set_complex_order_strategy_type(SchwabRb::Order::ComplexOrderStrategyTypes::VERTICAL)
20
24
  builder.set_quantity(quantity)
21
25
  builder.set_price(price)
26
+ builder.set_stop_price(stop_price) if stop_price && order_type == SchwabRb::Order::Types::STOP_LIMIT
22
27
  builder.add_option_leg(
23
- short_leg_instruction(order_instruction, credit_debit),
28
+ short_leg_instruction(order_instruction),
24
29
  short_leg_symbol,
25
30
  quantity
26
31
  )
27
32
  builder.add_option_leg(
28
- long_leg_instruction(order_instruction, credit_debit),
33
+ long_leg_instruction(order_instruction),
29
34
  long_leg_symbol,
30
35
  quantity
31
36
  )
32
37
  end
33
38
  end
34
39
 
35
- def order_type(credit_debit)
40
+ def determine_order_type(credit_debit)
36
41
  if credit_debit == :credit
37
42
  SchwabRb::Order::Types::NET_CREDIT
38
43
  else
@@ -40,31 +45,23 @@ module SchwabRb
40
45
  end
41
46
  end
42
47
 
43
- def short_leg_instruction(order_instruction, credit_debit)
44
- if order_instruction == :open && credit_debit == :credit
48
+ def short_leg_instruction(order_instruction)
49
+ if order_instruction == :open
45
50
  SchwabRb::Orders::OptionInstructions::SELL_TO_OPEN
46
- elsif order_instruction == :open && credit_debit == :debit
47
- SchwabRb::Orders::OptionInstructions::BUY_TO_OPEN
48
- elsif order_instruction == :close && credit_debit == :credit
49
- SchwabRb::Orders::OptionInstructions::SELL_TO_CLOSE
50
- elsif order_instruction == :close && credit_debit == :debit
51
+ elsif order_instruction == :close
51
52
  SchwabRb::Orders::OptionInstructions::BUY_TO_CLOSE
52
53
  else
53
- raise "Unsupported order instruction: #{order_instruction} with credit/debit: #{credit_debit}"
54
+ raise "Unsupported order instruction: #{order_instruction}"
54
55
  end
55
56
  end
56
57
 
57
- def long_leg_instruction(order_instruction, credit_debit)
58
- if order_instruction == :open && credit_debit == :credit
58
+ def long_leg_instruction(order_instruction)
59
+ if order_instruction == :open
59
60
  SchwabRb::Orders::OptionInstructions::BUY_TO_OPEN
60
- elsif order_instruction == :close && credit_debit == :credit
61
+ elsif order_instruction == :close
61
62
  SchwabRb::Orders::OptionInstructions::SELL_TO_CLOSE
62
- elsif order_instruction == :open && credit_debit == :debit
63
- SchwabRb::Orders::OptionInstructions::SELL_TO_OPEN
64
- elsif order_instruction == :close && credit_debit == :debit
65
- SchwabRb::Orders::OptionInstructions::BUY_TO_CLOSE
66
63
  else
67
- raise "Unsupported order instruction: #{order_instruction} with credit/debit: #{credit_debit}"
64
+ raise "Unsupported order instruction: #{order_instruction}"
68
65
  end
69
66
  end
70
67
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SchwabRb
4
- VERSION = "0.3.11"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/schwab_rb.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "schwab_rb/version"
4
4
  require_relative "schwab_rb/configuration"
5
+ require_relative "schwab_rb/account_hash_manager"
5
6
  require_relative "schwab_rb/auth/token_manager"
6
7
  require_relative "schwab_rb/auth/token"
7
8
  require_relative "schwab_rb/auth/init_client_login"
@@ -47,6 +48,7 @@ require_relative "schwab_rb/orders/order_factory"
47
48
  require_relative "schwab_rb/orders/iron_condor_order"
48
49
  require_relative "schwab_rb/orders/vertical_order"
49
50
  require_relative "schwab_rb/orders/single_order"
51
+ require_relative "schwab_rb/orders/oco_order"
50
52
 
51
53
  module SchwabRb
52
54
  class Error < StandardError; end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schwab_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Platta
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-09-08 00:00:00.000000000 Z
10
+ date: 2025-10-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: async
@@ -202,13 +202,18 @@ files:
202
202
  - LICENSE.txt
203
203
  - README.md
204
204
  - Rakefile
205
+ - doc/ACCOUNT_MANAGEMENT.md
206
+ - doc/PLACE_ORDER_SAMPLES.md
207
+ - doc/QUICK_START.md
205
208
  - doc/notes/data_objects_analysis.md
206
209
  - doc/notes/data_objects_refactoring_plan.md
207
210
  - examples/fetch_account_numbers.rb
208
211
  - examples/fetch_price_history.rb
209
212
  - examples/fetch_user_preferences.rb
213
+ - examples/place_oco_order.rb
210
214
  - lib/schwab_rb.rb
211
215
  - lib/schwab_rb/account.rb
216
+ - lib/schwab_rb/account_hash_manager.rb
212
217
  - lib/schwab_rb/auth/auth_context.rb
213
218
  - lib/schwab_rb/auth/init_client_easy.rb
214
219
  - lib/schwab_rb/auth/init_client_login.rb
@@ -247,6 +252,7 @@ files:
247
252
  - lib/schwab_rb/orders/errors.rb
248
253
  - lib/schwab_rb/orders/instruments.rb
249
254
  - lib/schwab_rb/orders/iron_condor_order.rb
255
+ - lib/schwab_rb/orders/oco_order.rb
250
256
  - lib/schwab_rb/orders/option_instructions.rb
251
257
  - lib/schwab_rb/orders/order.rb
252
258
  - lib/schwab_rb/orders/order_factory.rb