schwab_rb 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/doc/PLACE_ORDER_SAMPLES.md +1 -1
- data/examples/place_oco_order.rb +3 -1
- data/lib/schwab_rb/data_objects/order_preview.rb +1 -3
- data/lib/schwab_rb/orders/order_factory.rb +14 -0
- data/lib/schwab_rb/orders/vertical_roll_order.rb +71 -0
- data/lib/schwab_rb/version.rb +1 -1
- data/lib/schwab_rb.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 396ddbc6a232422d3d3cbf2a90291bdd78ddc17ae11a17d6311335a16408ac8c
|
|
4
|
+
data.tar.gz: c6f0058bcf5119eb19e9a3371f2ad03fbf865cd143d0154786d20d1090c2f921
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1199b983604e1c438b702cfb058c792fe5d19d0757d577b4ad1dbe4368fb06b3d908c48dc71621fe668478431ed5b101378208d8e5ff396ac787d81729feea35
|
|
7
|
+
data.tar.gz: 6ddb71396f336d1c013dafdd2580faad5e0a951ae60980be834ae6771b2591674c990e728adacc3a23beb952fdfece774620435bd303783bf88de39bd9bc8499
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.5.0] - 2025-11-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Vertical Roll Orders: Support for vertical roll orders that close an existing vertical spread and open a new one in a single order
|
|
7
|
+
- `VerticalRollOrder` class with 4-leg order structure for rolling positions
|
|
8
|
+
- Comprehensive tests for vertical roll orders including credit rolls, debit rolls, and stop limit orders
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fixed typo in `OrderFactory` (SchwabRbL → SchwabRb)
|
|
12
|
+
|
|
3
13
|
## [0.4.0] - 2025-10-19
|
|
4
14
|
|
|
5
15
|
### Added
|
data/doc/PLACE_ORDER_SAMPLES.md
CHANGED
|
@@ -162,7 +162,7 @@ Buy 10 shares of XYZ at a Limit price of $34.97 good for the Day. If filled, imm
|
|
|
162
162
|
|
|
163
163
|
## Conditional Order: One Cancels Another
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
Sell 2 shares of XYZ at a Limit price of $45.97 and Sell 2 shares of XYZ with a Stop Limit order where the stop price is $37.03 and limit is $37.00. Both orders are sent at the same time. If one order fills, the other order is immediately cancelled. Both orders are good for the Day. Also known as an OCO order.
|
|
166
166
|
|
|
167
167
|
```json
|
|
168
168
|
{
|
data/examples/place_oco_order.rb
CHANGED
|
@@ -15,6 +15,8 @@ Dotenv.load
|
|
|
15
15
|
#
|
|
16
16
|
|
|
17
17
|
# SchwabRb::Configuration.configure do |config|
|
|
18
|
+
# config.schwab_home = "/path/to/your/schwab_rb_home"
|
|
19
|
+
# config.log_level = "DEBUG"
|
|
18
20
|
# end
|
|
19
21
|
|
|
20
22
|
CURRENT_ACCT = "TRADING_BROKERAGE_ACCOUNT"
|
|
@@ -70,6 +72,6 @@ built_order = oco_order.build
|
|
|
70
72
|
|
|
71
73
|
binding.pry
|
|
72
74
|
|
|
73
|
-
response = client.place_order(built_order, account_name: CURRENT_ACCT)
|
|
75
|
+
# response = client.place_order(built_order, account_name: CURRENT_ACCT)
|
|
74
76
|
|
|
75
77
|
binding.pry
|
|
@@ -63,10 +63,9 @@ module SchwabRb
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
class OrderStrategy
|
|
66
|
-
attr_reader :
|
|
66
|
+
attr_reader :status, :price, :quantity, :order_type, :type, :strategy_id, :order_legs
|
|
67
67
|
|
|
68
68
|
def initialize(attrs)
|
|
69
|
-
@account_number = attrs[:accountNumber]
|
|
70
69
|
@status = attrs[:status]
|
|
71
70
|
@price = attrs[:price]
|
|
72
71
|
@quantity = attrs[:quantity]
|
|
@@ -78,7 +77,6 @@ module SchwabRb
|
|
|
78
77
|
|
|
79
78
|
def to_h
|
|
80
79
|
{
|
|
81
|
-
accountNumber: @account_number,
|
|
82
80
|
status: @status,
|
|
83
81
|
price: @price,
|
|
84
82
|
quantity: @quantity,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "iron_condor_order"
|
|
4
4
|
require_relative "vertical_order"
|
|
5
|
+
require_relative "vertical_roll_order"
|
|
5
6
|
require_relative "single_order"
|
|
6
7
|
require_relative "oco_order"
|
|
7
8
|
require_relative "order"
|
|
@@ -37,6 +38,19 @@ module SchwabRb
|
|
|
37
38
|
order_instruction: options[:order_instruction] || :open,
|
|
38
39
|
quantity: options[:quantity] || 1
|
|
39
40
|
)
|
|
41
|
+
when SchwabRb::Order::ComplexOrderStrategyTypes::VERTICAL_ROLL
|
|
42
|
+
VerticalRollOrder.build(
|
|
43
|
+
close_short_leg_symbol: options[:close_short_leg_symbol],
|
|
44
|
+
close_long_leg_symbol: options[:close_long_leg_symbol],
|
|
45
|
+
open_short_leg_symbol: options[:open_short_leg_symbol],
|
|
46
|
+
open_long_leg_symbol: options[:open_long_leg_symbol],
|
|
47
|
+
price: options[:price],
|
|
48
|
+
stop_price: options[:stop_price],
|
|
49
|
+
order_type: options[:order_type],
|
|
50
|
+
duration: options[:duration] || SchwabRb::Orders::Duration::DAY,
|
|
51
|
+
credit_debit: options[:credit_debit] || :credit,
|
|
52
|
+
quantity: options[:quantity] || 1
|
|
53
|
+
)
|
|
40
54
|
when SchwabRb::Order::OrderStrategyTypes::SINGLE
|
|
41
55
|
SingleOrder.build(
|
|
42
56
|
symbol: options[:symbol],
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "schwab_rb"
|
|
4
|
+
|
|
5
|
+
module SchwabRb
|
|
6
|
+
module Orders
|
|
7
|
+
class VerticalRollOrder
|
|
8
|
+
class << self
|
|
9
|
+
def build(
|
|
10
|
+
close_short_leg_symbol:,
|
|
11
|
+
close_long_leg_symbol:,
|
|
12
|
+
open_short_leg_symbol:,
|
|
13
|
+
open_long_leg_symbol:,
|
|
14
|
+
price:,
|
|
15
|
+
stop_price: nil,
|
|
16
|
+
order_type: nil,
|
|
17
|
+
duration: SchwabRb::Orders::Duration::DAY,
|
|
18
|
+
credit_debit: :credit,
|
|
19
|
+
quantity: 1
|
|
20
|
+
)
|
|
21
|
+
schwab_order_builder.new.tap do |builder|
|
|
22
|
+
builder.set_order_strategy_type(SchwabRb::Order::OrderStrategyTypes::SINGLE)
|
|
23
|
+
builder.set_session(SchwabRb::Orders::Session::NORMAL)
|
|
24
|
+
builder.set_duration(duration)
|
|
25
|
+
builder.set_order_type(order_type || determine_order_type(credit_debit))
|
|
26
|
+
builder.set_complex_order_strategy_type(SchwabRb::Order::ComplexOrderStrategyTypes::VERTICAL_ROLL)
|
|
27
|
+
builder.set_quantity(quantity)
|
|
28
|
+
builder.set_price(price)
|
|
29
|
+
builder.set_stop_price(stop_price) if stop_price && order_type == SchwabRb::Order::Types::STOP_LIMIT
|
|
30
|
+
|
|
31
|
+
# Close the existing spread (opposite instructions)
|
|
32
|
+
builder.add_option_leg(
|
|
33
|
+
SchwabRb::Orders::OptionInstructions::BUY_TO_CLOSE,
|
|
34
|
+
close_short_leg_symbol,
|
|
35
|
+
quantity
|
|
36
|
+
)
|
|
37
|
+
builder.add_option_leg(
|
|
38
|
+
SchwabRb::Orders::OptionInstructions::SELL_TO_CLOSE,
|
|
39
|
+
close_long_leg_symbol,
|
|
40
|
+
quantity
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Open the new spread
|
|
44
|
+
builder.add_option_leg(
|
|
45
|
+
SchwabRb::Orders::OptionInstructions::SELL_TO_OPEN,
|
|
46
|
+
open_short_leg_symbol,
|
|
47
|
+
quantity
|
|
48
|
+
)
|
|
49
|
+
builder.add_option_leg(
|
|
50
|
+
SchwabRb::Orders::OptionInstructions::BUY_TO_OPEN,
|
|
51
|
+
open_long_leg_symbol,
|
|
52
|
+
quantity
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def determine_order_type(credit_debit)
|
|
58
|
+
if credit_debit == :credit
|
|
59
|
+
SchwabRb::Order::Types::NET_CREDIT
|
|
60
|
+
else
|
|
61
|
+
SchwabRb::Order::Types::NET_DEBIT
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def schwab_order_builder
|
|
66
|
+
SchwabRb::Orders::Builder
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/schwab_rb/version.rb
CHANGED
data/lib/schwab_rb.rb
CHANGED
|
@@ -47,6 +47,7 @@ require_relative "schwab_rb/data_objects/market_movers"
|
|
|
47
47
|
require_relative "schwab_rb/orders/order_factory"
|
|
48
48
|
require_relative "schwab_rb/orders/iron_condor_order"
|
|
49
49
|
require_relative "schwab_rb/orders/vertical_order"
|
|
50
|
+
require_relative "schwab_rb/orders/vertical_roll_order"
|
|
50
51
|
require_relative "schwab_rb/orders/single_order"
|
|
51
52
|
require_relative "schwab_rb/orders/oco_order"
|
|
52
53
|
|
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.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joseph Platta
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-
|
|
10
|
+
date: 2025-11-04 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: async
|
|
@@ -266,6 +266,7 @@ files:
|
|
|
266
266
|
- lib/schwab_rb/orders/stop_type.rb
|
|
267
267
|
- lib/schwab_rb/orders/tax_lot_method.rb
|
|
268
268
|
- lib/schwab_rb/orders/vertical_order.rb
|
|
269
|
+
- lib/schwab_rb/orders/vertical_roll_order.rb
|
|
269
270
|
- lib/schwab_rb/price_history.rb
|
|
270
271
|
- lib/schwab_rb/quote.rb
|
|
271
272
|
- lib/schwab_rb/transaction.rb
|