schwab_rb 0.8.1 → 0.8.2
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/.codex/skills/schwab-rb-cli/SKILL.md +10 -4
- data/.codex/skills/schwab-rb-cli/references/cli_examples.md +20 -0
- data/README.md +2 -2
- data/examples/fetch_account_numbers.rb +16 -19
- data/examples/fetch_user_preferences.rb +16 -19
- data/examples/place_oco_order.rb +13 -6
- data/lib/schwab_rb/configuration.rb +7 -1
- data/lib/schwab_rb/utils/logger.rb +1 -1
- data/lib/schwab_rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f843b2f06b701abac043f861a8337225e3f4e625bd894fbaf23b71b014cebe48
|
|
4
|
+
data.tar.gz: 60d8af1b0f3f79f3b73797bb21b6fbe05ce6e13ba9cb28ae46d48e7f75ef7a07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc656b71d0bc3a10d79d34be8f1a316fe864862e9ef3b1d7d448800938bf2196ecc8c6ba88e7c780431f04ab8d040b4a4a211e8df45b0d34eaafa85bc57a0e63
|
|
7
|
+
data.tar.gz: 0a2b5bb6385d9bad29eca36c8684b431f80c4456e99d9a38a994c956331dfcd236d61008d3ea4396fea40c1ad7e4b3675006cefd851484ad4d3d44545f79202d
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: schwab-rb-cli
|
|
3
|
-
description: Use the installed schwab_rb CLI for authentication and price history downloads. Activate when a user wants to run the schwab_rb command, log in to Schwab, fetch market data, troubleshoot CLI installation or environment variables, or save
|
|
3
|
+
description: Use the installed schwab_rb CLI for authentication, option-chain samples, and price history downloads. Activate when a user wants to run the schwab_rb command, log in to Schwab, fetch market data, troubleshoot CLI installation or environment variables, or save CLI output from the command line.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Schwab RB CLI Skill
|
|
@@ -9,8 +9,8 @@ Use this skill when the task should be completed through the installed `schwab_r
|
|
|
9
9
|
|
|
10
10
|
## When to use
|
|
11
11
|
|
|
12
|
-
- The user wants to run `schwab_rb help`, `schwab_rb login`, or `schwab_rb price-history`
|
|
13
|
-
- The user wants to download price history data to JSON or CSV
|
|
12
|
+
- The user wants to run `schwab_rb help`, `schwab_rb login`, `schwab_rb sample`, or `schwab_rb price-history`
|
|
13
|
+
- The user wants to download an option-chain sample or price history data to JSON or CSV
|
|
14
14
|
- The user needs help with CLI installation, `asdf` shims, or missing `SCHWAB_*` environment variables
|
|
15
15
|
- The user wants the agent to verify the CLI works on the local machine
|
|
16
16
|
|
|
@@ -39,7 +39,13 @@ The wrapper only attempts to execute the globally installed `schwab_rb` command
|
|
|
39
39
|
skills/schwab-rb-cli/scripts/run_schwab_rb.sh login
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
5. For
|
|
42
|
+
5. For option-chain samples, run:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
skills/schwab-rb-cli/scripts/run_schwab_rb.sh sample --symbol SPX --expiration-date 2026-04-17
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
6. For price history downloads, run:
|
|
43
49
|
|
|
44
50
|
```bash
|
|
45
51
|
skills/schwab-rb-cli/scripts/run_schwab_rb.sh price-history --symbol AAPL --start-date 2026-03-01
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
```bash
|
|
6
6
|
skills/schwab-rb-cli/scripts/run_schwab_rb.sh help
|
|
7
7
|
skills/schwab-rb-cli/scripts/run_schwab_rb.sh help price-history
|
|
8
|
+
skills/schwab-rb-cli/scripts/run_schwab_rb.sh help sample
|
|
8
9
|
```
|
|
9
10
|
|
|
10
11
|
## Authentication
|
|
@@ -49,6 +50,25 @@ skills/schwab-rb-cli/scripts/run_schwab_rb.sh price-history \
|
|
|
49
50
|
--dir /tmp/schwab_rb_data
|
|
50
51
|
```
|
|
51
52
|
|
|
53
|
+
## Option-chain samples
|
|
54
|
+
|
|
55
|
+
Default CSV output:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
skills/schwab-rb-cli/scripts/run_schwab_rb.sh sample --symbol SPX --expiration-date 2026-04-17
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Filter by root and write JSON to a custom directory:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
skills/schwab-rb-cli/scripts/run_schwab_rb.sh sample \
|
|
65
|
+
--symbol SPX \
|
|
66
|
+
--root SPXW \
|
|
67
|
+
--expiration-date 2026-04-17 \
|
|
68
|
+
--format json \
|
|
69
|
+
--dir /tmp/schwab_rb_options
|
|
70
|
+
```
|
|
71
|
+
|
|
52
72
|
## Installation troubleshooting
|
|
53
73
|
|
|
54
74
|
Install the gem from the repo:
|
data/README.md
CHANGED
|
@@ -83,7 +83,7 @@ Before using the gem, ensure you have the following environment variables set:
|
|
|
83
83
|
- `APP_CALLBACK_URL`: The callback URL for your application.
|
|
84
84
|
- `TOKEN_PATH`: Path to store the authentication token.
|
|
85
85
|
- `SCHWAB_ACCOUNT_NUMBER`: Your Schwab account number.
|
|
86
|
-
- `SCHWAB_LOGFILE`: (Optional) Path to the log file. Defaults to
|
|
86
|
+
- `SCHWAB_LOGFILE`: (Optional) Path to the log file. Defaults to `~/.schwab_rb/schwab_rb.log`.
|
|
87
87
|
- `SCHWAB_LOG_LEVEL`: (Optional) Log level for the logger. Defaults to `WARN`. Possible values: `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`.
|
|
88
88
|
- `SCHWAB_SILENCE_OUTPUT`: (Optional) Set to `true` to disable logging output. Defaults to `false`.
|
|
89
89
|
|
|
@@ -91,7 +91,7 @@ You can also configure logging programmatically:
|
|
|
91
91
|
|
|
92
92
|
```ruby
|
|
93
93
|
SchwabRb.configure do |config|
|
|
94
|
-
config.logger = Logger.new(
|
|
94
|
+
config.logger = Logger.new($stdout)
|
|
95
95
|
config.log_level = 'INFO'
|
|
96
96
|
config.silence_output = false
|
|
97
97
|
end
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
# Script to fetch account numbers data and save as fixture
|
|
5
5
|
# Usage: ruby examples/fetch_account_numbers.rb
|
|
6
6
|
|
|
7
|
-
require_relative
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
7
|
+
require_relative "../lib/schwab_rb"
|
|
8
|
+
require "dotenv"
|
|
9
|
+
require "json"
|
|
10
|
+
require "fileutils"
|
|
11
11
|
|
|
12
12
|
Dotenv.load
|
|
13
13
|
|
|
14
14
|
def create_client
|
|
15
|
-
token_path = ENV[
|
|
15
|
+
token_path = ENV["TOKEN_PATH"] || "schwab_token.json"
|
|
16
16
|
SchwabRb::Auth.init_client_easy(
|
|
17
|
-
ENV
|
|
18
|
-
ENV
|
|
19
|
-
ENV
|
|
17
|
+
ENV.fetch("SCHWAB_API_KEY", nil),
|
|
18
|
+
ENV.fetch("SCHWAB_APP_SECRET", nil),
|
|
19
|
+
ENV.fetch("APP_CALLBACK_URL", nil),
|
|
20
20
|
token_path
|
|
21
21
|
)
|
|
22
22
|
end
|
|
@@ -24,26 +24,23 @@ end
|
|
|
24
24
|
def fetch_account_numbers
|
|
25
25
|
client = create_client
|
|
26
26
|
puts "Fetching account numbers..."
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
response = client.get_account_numbers
|
|
29
29
|
parsed_data = JSON.parse(response.body, symbolize_names: true)
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
# Create fixtures directory if it doesn't exist
|
|
32
|
-
fixtures_dir = File.join(__dir__,
|
|
32
|
+
fixtures_dir = File.join(__dir__, "..", "spec", "fixtures")
|
|
33
33
|
FileUtils.mkdir_p(fixtures_dir)
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
# Save the raw response
|
|
36
|
-
fixture_file = File.join(fixtures_dir,
|
|
36
|
+
fixture_file = File.join(fixtures_dir, "account_numbers.json")
|
|
37
37
|
File.write(fixture_file, JSON.pretty_generate(parsed_data))
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
puts "Account numbers data saved to: #{fixture_file}"
|
|
40
40
|
puts "Sample data: #{parsed_data.first(2)}"
|
|
41
|
-
|
|
42
|
-
rescue => e
|
|
41
|
+
rescue StandardError => e
|
|
43
42
|
puts "Error fetching account numbers: #{e.message}"
|
|
44
43
|
puts e.backtrace.first(3)
|
|
45
44
|
end
|
|
46
45
|
|
|
47
|
-
if __FILE__ == $
|
|
48
|
-
fetch_account_numbers
|
|
49
|
-
end
|
|
46
|
+
fetch_account_numbers if __FILE__ == $PROGRAM_NAME
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
# Script to fetch user preferences data and save as fixture
|
|
5
5
|
# Usage: ruby examples/fetch_user_preferences.rb
|
|
6
6
|
|
|
7
|
-
require_relative
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
7
|
+
require_relative "../lib/schwab_rb"
|
|
8
|
+
require "dotenv"
|
|
9
|
+
require "json"
|
|
10
|
+
require "fileutils"
|
|
11
11
|
|
|
12
12
|
Dotenv.load
|
|
13
13
|
|
|
14
14
|
def create_client
|
|
15
|
-
token_path = ENV[
|
|
15
|
+
token_path = ENV["TOKEN_PATH"] || "schwab_token.json"
|
|
16
16
|
SchwabRb::Auth.init_client_easy(
|
|
17
|
-
ENV
|
|
18
|
-
ENV
|
|
19
|
-
ENV
|
|
17
|
+
ENV.fetch("SCHWAB_API_KEY", nil),
|
|
18
|
+
ENV.fetch("SCHWAB_APP_SECRET", nil),
|
|
19
|
+
ENV.fetch("APP_CALLBACK_URL", nil),
|
|
20
20
|
token_path
|
|
21
21
|
)
|
|
22
22
|
end
|
|
@@ -24,26 +24,23 @@ end
|
|
|
24
24
|
def fetch_user_preferences
|
|
25
25
|
client = create_client
|
|
26
26
|
puts "Fetching user preferences..."
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
response = client.get_user_preferences
|
|
29
29
|
parsed_data = JSON.parse(response.body, symbolize_names: true)
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
# Create fixtures directory if it doesn't exist
|
|
32
|
-
fixtures_dir = File.join(__dir__,
|
|
32
|
+
fixtures_dir = File.join(__dir__, "..", "spec", "fixtures")
|
|
33
33
|
FileUtils.mkdir_p(fixtures_dir)
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
# Save the raw response
|
|
36
|
-
fixture_file = File.join(fixtures_dir,
|
|
36
|
+
fixture_file = File.join(fixtures_dir, "user_preferences.json")
|
|
37
37
|
File.write(fixture_file, JSON.pretty_generate(parsed_data))
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
puts "User preferences data saved to: #{fixture_file}"
|
|
40
40
|
puts "Sample data keys: #{parsed_data.keys.first(5)}"
|
|
41
|
-
|
|
42
|
-
rescue => e
|
|
41
|
+
rescue StandardError => e
|
|
43
42
|
puts "Error fetching user preferences: #{e.message}"
|
|
44
43
|
puts e.backtrace.first(3)
|
|
45
44
|
end
|
|
46
45
|
|
|
47
|
-
if __FILE__ == $
|
|
48
|
-
fetch_user_preferences
|
|
49
|
-
end
|
|
46
|
+
fetch_user_preferences if __FILE__ == $PROGRAM_NAME
|
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"
|
|
@@ -46,25 +48,30 @@ oco_order = SchwabRb::Orders::OrderFactory.build(
|
|
|
46
48
|
short_leg_symbol: "SPXW 251020P06530000",
|
|
47
49
|
long_leg_symbol: "SPXW 251020P06510000",
|
|
48
50
|
order_type: SchwabRb::Order::Types::STOP_LIMIT,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
price: 2.1,
|
|
52
|
+
stop_price: 2.0,
|
|
51
53
|
order_instruction: :close,
|
|
52
54
|
credit_debit: :debit,
|
|
53
|
-
quantity:
|
|
55
|
+
quantity: 2
|
|
54
56
|
},
|
|
55
57
|
{
|
|
56
58
|
strategy_type: SchwabRb::Order::ComplexOrderStrategyTypes::VERTICAL,
|
|
57
59
|
short_leg_symbol: "SPXW 251020C06770000",
|
|
58
60
|
long_leg_symbol: "SPXW 251020C06790000",
|
|
59
61
|
order_type: SchwabRb::Order::Types::STOP_LIMIT,
|
|
60
|
-
price:
|
|
62
|
+
price: 2.1,
|
|
63
|
+
stop_price: 2.0,
|
|
61
64
|
order_instruction: :close,
|
|
62
65
|
credit_debit: :debit,
|
|
63
|
-
quantity:
|
|
66
|
+
quantity: 2
|
|
64
67
|
}
|
|
65
68
|
]
|
|
66
69
|
)
|
|
67
70
|
|
|
68
71
|
built_order = oco_order.build
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
binding.pry
|
|
74
|
+
|
|
75
|
+
# response = client.place_order(built_order, account_name: CURRENT_ACCT)
|
|
76
|
+
|
|
77
|
+
binding.pry
|
|
@@ -25,8 +25,14 @@ module SchwabRb
|
|
|
25
25
|
!has_external_logger? && !@silence_output
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def default_log_file
|
|
29
|
+
File.join(@schwab_home, "schwab_rb.log")
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
def effective_log_file
|
|
29
|
-
@log_file ||
|
|
33
|
+
@log_file ||
|
|
34
|
+
(ENV["LOGFILE"] if ENV["LOGFILE"] && !ENV["LOGFILE"].empty?) ||
|
|
35
|
+
default_log_file
|
|
30
36
|
end
|
|
31
37
|
end
|
|
32
38
|
|
|
@@ -27,7 +27,7 @@ module SchwabRb
|
|
|
27
27
|
return null_logger if config.silence_output
|
|
28
28
|
return null_logger unless config.should_create_logger?
|
|
29
29
|
|
|
30
|
-
log_destination = config.effective_log_file
|
|
30
|
+
log_destination = config.effective_log_file
|
|
31
31
|
|
|
32
32
|
return null_logger if [:null, "/dev/null"].include?(log_destination)
|
|
33
33
|
|
data/lib/schwab_rb/version.rb
CHANGED
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.8.
|
|
4
|
+
version: 0.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joseph Platta
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-04-
|
|
10
|
+
date: 2026-04-10 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: async
|