brokerage-api
A Rust library for integrating with various brokerage APIs, starting with a comprehensive implementation for Schwab. This library aims to provide a robust and easy-to-use interface for accessing market data, managing authentication, and eventually supporting trading operations.
Current Status
This library is currently under development. The primary focus is on the Schwab Market Data Production API, which is partially implemented. Contributions are welcome!
Features
- Schwab API Integration:
- Authentication and token management (OAuth 2.0).
- Market data access:
- Real-time quotes for symbols.
- Options chain retrieval.
- Historical price data.
- Market movers.
- Market hours information.
- Instrument search by symbol, description, and CUSIP.
Installation
Add the following to your Cargo.toml file:
[]
= "0.1.5" # Or the latest version
= { = "1", = ["full"] } # Required for async operations
= { = "0.11", = ["json"] } # For HTTP requests
= "1.0" # For error handling
Usage
Schwab API Authentication
To use the Schwab API, you must first authorize the application to obtain access and refresh tokens. These tokens are stored locally in a tokens.json file.
use Arc;
use SchwabAuth;
async
Authorization Steps:
- Run the
authorizefunction. - The application will print an authorization URL to your console. Copy this URL and paste it into your web browser.
- Log in with your Schwab portfolio credentials and grant authorization to the application.
- You will be redirected to a blank page (e.g.,
https://127.0.0.1). Copy the FULL URL from your browser's address bar. - Paste this URL back into your terminal when prompted and press Enter.
- The application will exchange the authorization code for access and refresh tokens, saving them to
tokens.json.
Schwab API Market Data Usage
Once authorized, you can use the SchwabApi client to access various market data endpoints.
Get Quotes for Multiple Symbols
use Arc;
use ;
async
Get Options Chains
use Arc;
use ;
async
Get Price History
use Arc;
use ;
use ;
async
Contributing
We welcome contributions to this library! If you're interested in:
- Implementing more Schwab API endpoints.
- Adding support for other brokerage APIs.
- Improving existing features or documentation.
- Fixing bugs.
Please feel free to open an issue or submit a pull request.