rustyschwab
An unofficial Rust SDK for the Charles Schwab Trader and Market Data APIs, not affiliated with or endorsed by Charles Schwab & Co., Inc.: OAuth with encrypted or keychain token storage, a REST client with retries, a shared rate budget and a circuit breaker, the streamer protocol, a durable order journal, and a paper-trading venue.
Wire types live in rustyschwab-types and are
re-exported as rustyschwab::types. The repository
README covers the MCP server,
operations and the full documentation set.
[]
= { = "0.2", = ["callback-server"] }
= { = "1", = ["full"] }
callback-server adds the local HTTPS listener that captures the OAuth
redirect. It serves the certificate in OAuthConfig::callback_cert_file
and callback_key_file (for example one from mkcert 127.0.0.1, which the
browser trusts), or a self-signed one the browser warns about.
AuthManager::authorize_with hands you the consent URL before it waits.
Without the feature, AuthManager::authorize returns the URL and you pass
the redirect to exchange_code yourself.
Configure and authorize
SchwabConfig::from_env reads the SCHWAB_* variables listed in the
repository's .env.example (SCHWAB_APP_KEY, SCHWAB_APP_SECRET,
SCHWAB_OAUTH_CALLBACK_URL, SCHWAB_TOKENS_FILE, SCHWAB_TOKEN_STORE, …)
and validates them.
use *;
# async
Read market data and accounts
use *;
use ;
# async
Place an order
Orders are built from exact decimals and validated before anything leaves
the process. A submission is sent once and never retried: an ambiguous
outcome is Error::SubmissionUnknown, and the account's next submission
waits until the journal reconciles it against the broker.
use SchwabClient;
use Decimal;
use ;
# async
Stream quotes
The streamer identity (customer ID, channel, function ID) comes from the
user-preferences response. Consumers must handle StreamMessage::State:
when ready is false or the generation changes, derived state is stale.
use ;
use StreamConfig;
use ;
# async
Features
| Feature | Default | Adds |
|---|---|---|
rustls |
yes | rustls TLS for HTTP and WebSocket |
native-tls |
no | the platform TLS stack instead |
callback-server |
no | local HTTPS OAuth callback capture |
schemars |
no | JSON Schema derives on the request types |
telemetry |
yes | rustyschwab::telemetry: ready-made tracing-subscriber setups |
otel |
no | telemetry::init_otel: OTLP/HTTP export of spans and, through the metrics facade, metrics, configured by the standard OTEL_* environment |
full |
no | rustls, callback-server, schemars, telemetry |
License
MIT or Apache-2.0, at your option.