Unofficial API wrapper for the Schwab HTTP API
Project description
What is schwab-py?
schwab-py is an unofficial wrapper around the Charles Schwab Consumer APIs. It strives to be as thin and unopinionated as possible, offering an elegant programmatic interface over each endpoint. Notable functionality includes:
Login and authentication
Quotes, fundamentals, and historical pricing data
Options chains
Streaming quotes and order book depth data
Trades and trade management
Account info
I used to use tda-api, how do I migrate?
Now that TDAmeritrade is no more, the old tda-api library will no longer work. Check out our transition guide for instructions on getting started.
How do I use schwab-py?
For a full description of schwab-py’s functionality, check out the documentation. Meawhile, here’s a quick getting started guide:
Before you do anything, create an account and an application on the Charles Schwab developer site. You’ll receive an API key and app secret, which you can pass to this wrapper. You’ll also want to take note of your callback URI, as the login flow requires it. You app must be approved by Schwab before you can use it (this can take several days). You can find more detailed instructions here.
Next, install schwab-py:
pip install schwab-py
You’re good to go! To demonstrate, here’s how you can authenticate and fetch daily historical price data for the past twenty years:
from schwab import auth, client
import json
api_key = 'YOUR_API_KEY'
app_secret = 'YOUR_APP_SECRET'
callback_url = 'https://127.0.0.1:8182/'
token_path = '/path/to/token.json'
c = auth.easy_client(api_key, app_secret, callback_url, token_path)
r = c.get_price_history_every_day('AAPL')
r.raise_for_status()
print(json.dumps(r.json(), indent=4))
Why should I use schwab-py?
schwab-py was designed to provide a few important pieces of functionality:
Safe Authentication: Schwab’s API supports OAuth authentication, but too many people online end up rolling their own implementation of the OAuth callback flow. This is both unnecessarily complex and dangerous. schwab-py handles token fetch and refreshing for you.
Minimal API Wrapping: Unlike some other API wrappers, which build in lots of logic and validation, schwab-py takes raw values and returns raw responses, allowing you to interpret the complex API responses as you see fit. Anything you can do with raw HTTP requests you can do with schwab-py, only more easily.
Why should I not use schwab-py?
As excellent as Schwab’s API is, there are a few popular features it does not offer:
While Charles Schwab owns thinkorswim (AKA TOS), this API is unaffiliated with it. You can access and trade against the same accounts as TOS, but some of TOS’s functionality is not supported by schwab-py
Paper trading is not supported
Historical options pricing data is not available.
What else?
We have a Discord server! You can join to get help using schwab-py or just to chat with interesting people.
Bug reports, suggestions, and patches are always welcome! Submit issues here and pull requests here.
schwab-py is released under the MIT license.
Disclaimer: schwab-py is an unofficial API wrapper. It is in no way endorsed by or affiliated with Charles Schwab or any associated organization. Make sure to read and understand the terms of service of the underlying API before using this package. This authors accept no responsibility for any damage that might stem from use of this package. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file schwab_py-1.4.0.tar.gz
.
File metadata
- Download URL: schwab_py-1.4.0.tar.gz
- Upload date:
- Size: 92.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adbfd79439f488a22e1f9f0247854e9e2c0424f4c15d6f8e3fd92355c095ea15 |
|
MD5 | c3cc5d0d8da25f030085b5bfebcfc444 |
|
BLAKE2b-256 | a8a7196ab8a8e83c83894f8f4afefc5c3b48fc66d4cea78d5dfffe3b506127a1 |
File details
Details for the file schwab_py-1.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: schwab_py-1.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 99.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 049854252703095f42a0c322278460b4dd1234645293adb9e7944622dccff08a |
|
MD5 | 1b9f1a9554b50f149f522670cc687fc3 |
|
BLAKE2b-256 | 15db53075a89d15fc98467439b8d508f61de685ee424b56c47354d9399e1013b |