schwab 0.2.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.
@@ -0,0 +1,140 @@
1
+ # Tasks for Accounts & Trading API Methods (Dependency-Ordered)
2
+
3
+ ## Dependency Analysis
4
+
5
+ ### Existing Components (Already Implemented)
6
+ - ✅ `lib/schwab/client.rb` - HTTP client with auth
7
+ - ✅ `lib/schwab/connection.rb` - Faraday connection builder
8
+ - ✅ `lib/schwab/configuration.rb` - Configuration management
9
+ - ✅ `lib/schwab/error.rb` - Error classes
10
+ - ✅ `lib/schwab/market_data.rb` - Pattern to follow for modules
11
+ - ✅ Authentication middleware with token refresh
12
+ - ✅ Rate limiting middleware
13
+
14
+ ### Dependency Chain
15
+ 1. **Resource Wrappers** → Blocks: All modules (if using resource format)
16
+ 2. **Configuration Update** → Blocks: Resource wrappers
17
+ 3. **Account Management** → Blocks: Order preview (needs account data)
18
+ 4. **Order Validation** → Blocks: Trading operations (validation before submit)
19
+ 5. **Order Preview** → Blocks: Trading operations (preview before submit)
20
+ 6. **Trading Operations** → Blocks: Options Strategy Builder
21
+ 7. **Options Strategy** → Depends on: Trading operations
22
+
23
+ ## Relevant Files
24
+
25
+ - `lib/schwab/accounts.rb` - New module for account-related API methods
26
+ - `lib/schwab/trading.rb` - New module for trading/order API methods
27
+ - `lib/schwab/options_strategy.rb` - New module for options strategy builder
28
+ - `lib/schwab/resources/base.rb` - Base resource class for object wrappers
29
+ - `lib/schwab/resources/account.rb` - Account resource object wrapper
30
+ - `lib/schwab/resources/order.rb` - Order resource object wrapper
31
+ - `lib/schwab/resources/position.rb` - Position resource object wrapper
32
+ - `lib/schwab/resources/transaction.rb` - Transaction resource object wrapper
33
+ - `lib/schwab/resources/strategy.rb` - Options strategy resource wrapper
34
+ ~~`lib/schwab/order_validator.rb` - Client-side order validation (REMOVED)~~
35
+ ~~`lib/schwab/order_preview.rb` - Order preview functionality (REMOVED - using existing API endpoint)~~
36
+ - `lib/schwab.rb` - Main module (needs updating to include new modules)
37
+ - `lib/schwab/configuration.rb` - Configuration (add response_format option)
38
+ - `spec/schwab/accounts_spec.rb` - Tests for account methods
39
+ - `spec/schwab/trading_spec.rb` - Tests for trading methods
40
+ - `spec/schwab/options_strategy_spec.rb` - Tests for options strategy builder
41
+ - `spec/schwab/resources/*_spec.rb` - Tests for resource objects
42
+
43
+ ## Notes
44
+
45
+ - Follow existing patterns from market_data.rb for module structure
46
+ - Use existing Client and Connection classes for API communication
47
+ - Leverage existing error handling and rate limiting middleware
48
+ - Ensure all methods support both module-level and instance-level calls
49
+ - Add comprehensive YARD documentation for all public methods
50
+ - Write tests alongside implementation for each component
51
+ - Use VCR for recording API interactions in tests
52
+
53
+ ## Tasks (Reordered by Dependencies)
54
+
55
+ - [x] 1. Update Configuration for Response Format Support
56
+ - [x] 1.1 Update `lib/schwab/configuration.rb` to add `response_format` option (:hash or :resource)
57
+ - [x] 1.2 Add default value `:hash` for backward compatibility
58
+ - [x] 1.3 Add validation for response_format values
59
+ - [x] 1.4 Write tests for configuration changes
60
+ - [x] 1.5 Update configuration documentation
61
+
62
+ - [x] 2. Implement Resource Object Wrappers (Foundation)
63
+ - [x] 2.1 Create `lib/schwab/resources/base.rb` with Sawyer::Resource-like functionality
64
+ - [x] 2.2 Implement method_missing for hash-like access and method calls
65
+ - [x] 2.3 Implement type coercion for dates, times, and numeric values
66
+ - [x] 2.4 Add lazy loading for nested resources
67
+ - [x] 2.5 Create `lib/schwab/resources/account.rb` with account-specific methods
68
+ - [x] 2.6 Create `lib/schwab/resources/position.rb` with position calculations
69
+ - [x] 2.7 Create `lib/schwab/resources/transaction.rb` with transaction type helpers
70
+ - [x] 2.8 Create `lib/schwab/resources/order.rb` with order status helpers
71
+ - [x] 2.9 Create `lib/schwab/resources/strategy.rb` for strategy object representation
72
+ - [x] 2.10 Update response handling in client to use configured format
73
+ - [x] 2.11 Write tests for each resource class in `spec/schwab/resources/`
74
+ - [x] 2.12 Document resource object usage patterns
75
+
76
+ - [x] 3. Create Account Management Module and Methods
77
+ - [x] 3.1 Create `lib/schwab/accounts.rb` module following pattern from `market_data.rb`
78
+ - [x] 3.2 Implement `get_accounts(fields: nil, client: nil)` method with proper API endpoint mapping
79
+ - [x] 3.3 Implement `get_account(account_id, fields: nil, client: nil)` for single account retrieval
80
+ - [x] 3.4 Implement `get_positions(account_id, client: nil)` to fetch account positions
81
+ - [x] 3.5 Implement `get_account_balances(account_id, client: nil)` for detailed balance info
82
+ - [x] 3.6 Implement `get_transactions(account_id, from_date:, to_date:, types: nil, client: nil)` with pagination support
83
+ - [x] 3.7 Implement `get_account_preferences(account_id, client: nil)` for account settings
84
+ - [x] 3.8 Add module-level methods to `lib/schwab.rb` for accounts functionality
85
+ - [x] 3.9 Write comprehensive tests in `spec/schwab/accounts_spec.rb` with VCR cassettes
86
+ - [x] 3.10 Add YARD documentation for all public account methods
87
+
88
+ - [x] 4. ~~Add Order Validation and Preview Features~~ (REMOVED - will implement later)
89
+ - [x] 4.1 ~~Create `lib/schwab/order_validator.rb` with validation logic~~ (REMOVED)
90
+ - [x] 4.2 ~~Implement symbol validation against known symbols (use market data API)~~ (REMOVED)
91
+ - [x] 4.3 ~~Implement quantity validation (positive integers, lot sizes)~~ (REMOVED)
92
+ - [x] 4.4 ~~Implement price validation for limit/stop orders~~ (REMOVED)
93
+ - [x] 4.5 ~~Implement order type validation (required fields per type)~~ (REMOVED)
94
+ - [x] 4.6 ~~Create `lib/schwab/order_preview.rb` for preview functionality~~ (REMOVED - preview_order already exists in Accounts module)
95
+ - [x] 4.7 ~~Implement `preview_order(account_id, order:, client: nil)` method~~ (ALREADY EXISTS in Accounts module)
96
+ - [x] 4.8 ~~Calculate estimated costs, commissions, and fees~~ (HANDLED by API endpoint)
97
+ - [x] 4.9 ~~Calculate margin requirements and buying power effect~~ (HANDLED by API endpoint)
98
+ - [x] 4.10 ~~Write comprehensive validation tests in `spec/schwab/order_validator_spec.rb`~~ (REMOVED)
99
+ - [x] 4.11 ~~Write preview tests in `spec/schwab/order_preview_spec.rb`~~ (NOT NEEDED - preview_order already tested in accounts_spec.rb)
100
+ - [x] 4.12 ~~Document validation rules and preview response format~~ (REMOVED)
101
+
102
+ - [ ] 5. Create Trading Operations Module and Methods
103
+ - [ ] 5.1 Create `lib/schwab/trading.rb` module with order management methods
104
+ - [ ] 5.2 Implement `place_order(account_id, order:, client: nil)` with order submission logic
105
+ - [ ] 5.3 Integrate validation into `place_order` with optional bypass
106
+ - [ ] 5.4 Implement `cancel_order(account_id, order_id, client: nil)` for order cancellation
107
+ - [ ] 5.5 Implement `replace_order(account_id, order_id, order:, client: nil)` for order modification
108
+ - [ ] 5.6 Implement `get_order(account_id, order_id, client: nil)` for single order status
109
+ - [ ] 5.7 Implement `get_orders(account_id, status: nil, from_date: nil, to_date: nil, client: nil)` with filtering
110
+ - [ ] 5.8 Implement `get_order_history(account_id, from_date:, to_date:, client: nil)` with pagination
111
+ - [ ] 5.9 Add support for all order types (market, limit, stop, stop-limit, trailing stop)
112
+ - [ ] 5.10 Implement complex order support (brackets, OCO, conditional)
113
+ - [ ] 5.11 Add module-level methods to `lib/schwab.rb` for trading functionality
114
+ - [ ] 5.12 Write comprehensive tests in `spec/schwab/trading_spec.rb` with stubbed responses
115
+ - [ ] 5.13 Add YARD documentation for all trading methods
116
+
117
+ - [ ] 6. Build Options Strategy Builder
118
+ - [ ] 6.1 Create `lib/schwab/options_strategy.rb` with base strategy class
119
+ - [ ] 6.2 Implement `vertical_spread` class method for bull/bear call/put spreads
120
+ - [ ] 6.3 Implement `iron_condor` class method with four-leg validation
121
+ - [ ] 6.4 Implement `butterfly` class method for three-strike strategies
122
+ - [ ] 6.5 Implement `calendar_spread` class method for time spreads
123
+ - [ ] 6.6 Implement `straddle` and `strangle` class methods
124
+ - [ ] 6.7 Implement `iron_butterfly` class method
125
+ - [ ] 6.8 Implement `diagonal_spread` class method
126
+ - [ ] 6.9 Implement `collar` class method for protective strategies
127
+ - [ ] 6.10 Implement `custom` builder with `add_leg` chaining method
128
+ - [ ] 6.11 Add `as_single_order` method for order configuration (price type, limit)
129
+ - [ ] 6.12 Implement strategy validation for strike relationships and expirations
130
+ - [ ] 6.13 Add preview support to strategy builder (uses order_preview.rb)
131
+ - [ ] 6.14 Write tests in `spec/schwab/options_strategy_spec.rb` for all strategies
132
+ - [ ] 6.15 Add YARD documentation with examples for each strategy type
133
+
134
+ ## Implementation Order Summary
135
+
136
+ 1. **Configuration & Infrastructure** (Tasks 1-2): Set up response format support and resource wrappers
137
+ 2. **Account Management** (Task 3): Implement account methods (no blockers)
138
+ 3. **Validation & Preview** (Task 4): Build standalone validation/preview (used by trading)
139
+ 4. **Trading Operations** (Task 5): Core trading functionality (uses validation)
140
+ 5. **Options Strategies** (Task 6): Advanced features (depends on trading)
@@ -0,0 +1,106 @@
1
+ # Tasks for Accounts & Trading API Methods
2
+
3
+ ## Relevant Files
4
+
5
+ - `lib/schwab/accounts.rb` - New module for account-related API methods
6
+ - `lib/schwab/trading.rb` - New module for trading/order API methods
7
+ - `lib/schwab/options_strategy.rb` - New module for options strategy builder
8
+ - `lib/schwab/resources/base.rb` - Base resource class for object wrappers
9
+ - `lib/schwab/resources/account.rb` - Account resource object wrapper
10
+ - `lib/schwab/resources/order.rb` - Order resource object wrapper
11
+ - `lib/schwab/resources/position.rb` - Position resource object wrapper
12
+ - `lib/schwab/resources/transaction.rb` - Transaction resource object wrapper
13
+ - `lib/schwab/resources/strategy.rb` - Options strategy resource wrapper
14
+ - `lib/schwab/order_validator.rb` - Client-side order validation
15
+ - `lib/schwab/order_preview.rb` - Order preview functionality
16
+ - `lib/schwab.rb` - Main module (needs updating to include new modules)
17
+ - `lib/schwab/configuration.rb` - Configuration (add response_format option)
18
+ - `spec/schwab/accounts_spec.rb` - Tests for account methods
19
+ - `spec/schwab/trading_spec.rb` - Tests for trading methods
20
+ - `spec/schwab/options_strategy_spec.rb` - Tests for options strategy builder
21
+ - `spec/schwab/resources/*_spec.rb` - Tests for resource objects
22
+
23
+ ## Notes
24
+
25
+ - Follow existing patterns from market_data.rb for module structure
26
+ - Use existing Client and Connection classes for API communication
27
+ - Leverage existing error handling and rate limiting middleware
28
+ - Ensure all methods support both module-level and instance-level calls
29
+ - Add comprehensive YARD documentation for all public methods
30
+ - Write tests alongside implementation for each component
31
+ - Use VCR for recording API interactions in tests
32
+
33
+ ## Tasks
34
+
35
+ - [ ] 1. Create Account Management Module and Methods
36
+ - [ ] 1.1 Create `lib/schwab/accounts.rb` module following pattern from `market_data.rb`
37
+ - [ ] 1.2 Implement `get_accounts(fields: nil, client: nil)` method with proper API endpoint mapping
38
+ - [ ] 1.3 Implement `get_account(account_id, fields: nil, client: nil)` for single account retrieval
39
+ - [ ] 1.4 Implement `get_positions(account_id, client: nil)` to fetch account positions
40
+ - [ ] 1.5 Implement `get_account_balances(account_id, client: nil)` for detailed balance info
41
+ - [ ] 1.6 Implement `get_transactions(account_id, from_date:, to_date:, types: nil, client: nil)` with pagination support
42
+ - [ ] 1.7 Implement `get_account_preferences(account_id, client: nil)` for account settings
43
+ - [ ] 1.8 Add module-level methods to `lib/schwab.rb` for accounts functionality
44
+ - [ ] 1.9 Write comprehensive tests in `spec/schwab/accounts_spec.rb` with VCR cassettes
45
+ - [ ] 1.10 Add YARD documentation for all public account methods
46
+
47
+ - [ ] 2. Create Trading Operations Module and Methods
48
+ - [ ] 2.1 Create `lib/schwab/trading.rb` module with order management methods
49
+ - [ ] 2.2 Implement `place_order(account_id, order:, client: nil)` with order submission logic
50
+ - [ ] 2.3 Implement `cancel_order(account_id, order_id, client: nil)` for order cancellation
51
+ - [ ] 2.4 Implement `replace_order(account_id, order_id, order:, client: nil)` for order modification
52
+ - [ ] 2.5 Implement `get_order(account_id, order_id, client: nil)` for single order status
53
+ - [ ] 2.6 Implement `get_orders(account_id, status: nil, from_date: nil, to_date: nil, client: nil)` with filtering
54
+ - [ ] 2.7 Implement `get_order_history(account_id, from_date:, to_date:, client: nil)` with pagination
55
+ - [ ] 2.8 Add support for all order types (market, limit, stop, stop-limit, trailing stop)
56
+ - [ ] 2.9 Implement complex order support (brackets, OCO, conditional)
57
+ - [ ] 2.10 Add module-level methods to `lib/schwab.rb` for trading functionality
58
+ - [ ] 2.11 Write comprehensive tests in `spec/schwab/trading_spec.rb` with stubbed responses
59
+ - [ ] 2.12 Add YARD documentation for all trading methods
60
+
61
+ - [ ] 3. Build Options Strategy Builder
62
+ - [ ] 3.1 Create `lib/schwab/options_strategy.rb` with base strategy class
63
+ - [ ] 3.2 Implement `vertical_spread` class method for bull/bear call/put spreads
64
+ - [ ] 3.3 Implement `iron_condor` class method with four-leg validation
65
+ - [ ] 3.4 Implement `butterfly` class method for three-strike strategies
66
+ - [ ] 3.5 Implement `calendar_spread` class method for time spreads
67
+ - [ ] 3.6 Implement `straddle` and `strangle` class methods
68
+ - [ ] 3.7 Implement `iron_butterfly` class method
69
+ - [ ] 3.8 Implement `diagonal_spread` class method
70
+ - [ ] 3.9 Implement `collar` class method for protective strategies
71
+ - [ ] 3.10 Implement `custom` builder with `add_leg` chaining method
72
+ - [ ] 3.11 Add `as_single_order` method for order configuration (price type, limit)
73
+ - [ ] 3.12 Implement strategy validation for strike relationships and expirations
74
+ - [ ] 3.13 Create `lib/schwab/resources/strategy.rb` for strategy object representation
75
+ - [ ] 3.14 Write tests in `spec/schwab/options_strategy_spec.rb` for all strategies
76
+ - [ ] 3.15 Add YARD documentation with examples for each strategy type
77
+
78
+ - [ ] 4. Implement Resource Object Wrappers
79
+ - [ ] 4.1 Create `lib/schwab/resources/base.rb` with Sawyer::Resource-like functionality
80
+ - [ ] 4.2 Implement method_missing for hash-like access and method calls
81
+ - [ ] 4.3 Create `lib/schwab/resources/account.rb` with account-specific methods
82
+ - [ ] 4.4 Create `lib/schwab/resources/order.rb` with order status helpers
83
+ - [ ] 4.5 Create `lib/schwab/resources/position.rb` with position calculations
84
+ - [ ] 4.6 Create `lib/schwab/resources/transaction.rb` with transaction type helpers
85
+ - [ ] 4.7 Add lazy loading for nested resources
86
+ - [ ] 4.8 Implement type coercion for dates, times, and numeric values
87
+ - [ ] 4.9 Update `lib/schwab/configuration.rb` to add `response_format` option (:hash or :resource)
88
+ - [ ] 4.10 Update response handling in client to use configured format
89
+ - [ ] 4.11 Write tests for each resource class in `spec/schwab/resources/`
90
+ - [ ] 4.12 Document resource object usage patterns
91
+
92
+ - [ ] 5. Add Order Validation and Preview Features
93
+ - [ ] 5.1 Create `lib/schwab/order_validator.rb` with validation logic
94
+ - [ ] 5.2 Implement symbol validation against known symbols
95
+ - [ ] 5.3 Implement quantity validation (positive integers, lot sizes)
96
+ - [ ] 5.4 Implement price validation for limit/stop orders
97
+ - [ ] 5.5 Implement order type validation (required fields per type)
98
+ - [ ] 5.6 Create `lib/schwab/order_preview.rb` for preview functionality
99
+ - [ ] 5.7 Implement `preview_order(account_id, order:, client: nil)` method
100
+ - [ ] 5.8 Calculate estimated costs, commissions, and fees
101
+ - [ ] 5.9 Calculate margin requirements and buying power effect
102
+ - [ ] 5.10 Add preview support to strategy builder
103
+ - [ ] 5.11 Integrate validation into `place_order` with optional bypass
104
+ - [ ] 5.12 Write comprehensive validation tests in `spec/schwab/order_validator_spec.rb`
105
+ - [ ] 5.13 Write preview tests in `spec/schwab/order_preview_spec.rb`
106
+ - [ ] 5.14 Document validation rules and preview response format
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schwab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Hamamura
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: multi_json
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.15'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.15'
40
+ - !ruby/object:Gem::Dependency
41
+ name: oauth2
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: sawyer
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.9'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.9'
68
+ - !ruby/object:Gem::Dependency
69
+ name: brakeman
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '6.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '6.0'
82
+ description: A Ruby client library for the Charles Schwab API, providing easy access
83
+ to trading, market data, and portfolio management endpoints.
84
+ email:
85
+ - 58859899+ryanhamamura@users.noreply.github.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".brakeman.yml"
91
+ - ".claude/commands/release-pr.md"
92
+ - ".env.example"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - CHANGELOG.md
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - docs/resource_objects.md
100
+ - lib/schwab.rb
101
+ - lib/schwab/account_number_resolver.rb
102
+ - lib/schwab/accounts.rb
103
+ - lib/schwab/client.rb
104
+ - lib/schwab/configuration.rb
105
+ - lib/schwab/connection.rb
106
+ - lib/schwab/error.rb
107
+ - lib/schwab/market_data.rb
108
+ - lib/schwab/middleware/authentication.rb
109
+ - lib/schwab/middleware/rate_limit.rb
110
+ - lib/schwab/oauth.rb
111
+ - lib/schwab/resources/account.rb
112
+ - lib/schwab/resources/base.rb
113
+ - lib/schwab/resources/order.rb
114
+ - lib/schwab/resources/position.rb
115
+ - lib/schwab/resources/strategy.rb
116
+ - lib/schwab/resources/transaction.rb
117
+ - lib/schwab/version.rb
118
+ - sig/schwab.rbs
119
+ - tasks/prd-accounts-trading-api.md
120
+ - tasks/tasks-prd-accounts-trading-api-reordered.md
121
+ - tasks/tasks-prd-accounts-trading-api.md
122
+ homepage: https://github.com/ryanhamamura/schwab
123
+ licenses:
124
+ - MIT
125
+ metadata:
126
+ homepage_uri: https://github.com/ryanhamamura/schwab
127
+ source_code_uri: https://github.com/ryanhamamura/schwab
128
+ changelog_uri: https://github.com/ryanhamamura/schwab/blob/main/CHANGELOG.md
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 3.1.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.6.9
144
+ specification_version: 4
145
+ summary: Ruby SDK for Charles Schwab API
146
+ test_files: []