(Unofficial) Charles Schwab Stock and Option Trade API Client
Overview
This is a Python client library for accessing the Charles Schwab stock and option trade API. It provides a convenient way to interact with the Charles Schwab trading platform programmatically.
Features
- Authenticate with your Charles Schwab account
- Automated refreshing of access token
- Download option chain data
- Get account information
- Place stock and option trades
- Retrieve trade history [Work in Progress]
- Monitor real-time market data [TODO]
Installation
To install the Charles Schwab API client, you can use pip:
pip install CSchwabPy
Usage Example
- Authentication & Get Access Token & Refresh Token
# save these lines in a file named like cschwab.py
# NOTE: should use SchwabClient to get tokens manually after version 0.1.3
from cschwabpy.SchwabClient import SchwabClient
app_client_key = "---your-app-client-key-here-"
app_secret = "app-secret"
schwab_client = SchwabClient(app_client_id=app_client_key, app_secret=app_secret)
schwab_client.get_tokens_manually()
# run in your Terminal, follow the prompt to complete authentication:
> python cschwab.py
# now you should have access token & refresh token downloaded to your device
#----------------
ticker = '$SPX'
# get option expirations:
expiration_list = schwab_client.get_option_expirations(underlying_symbol = ticker)
# download SPX option chains
from_date = 2024-07-01
to_date = 2024-07-01
opt_chain_result = schwab_client.download_option_chain(ticker, from_date, to_date)
# get call-put dataframe pairs by expiration
opt_df_pairs = opt_chain_result.to_dataframe_pairs_by_expiration()
for df in opt_df_pairs:
print(df.expiration)
print(f"call dataframe size: {df.call_df.shape}. expiration: {df.expiration}")
print(f"put dataframe size: {df.put_df.shape}. expiration: {df.expiration}")
print(df.call_df.head(5))
print(df.put_df.head(5))
Build & Release
git tag v0.1.3.9 git push origin tag v0.1.3.9
Metadata
Release files for cschwabpy 0.1.4.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cschwabpy-0.1.4.8.tar.gz | 14.6 kB | With provenance | Details for cschwabpy-0.1.4.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cschwabpy-0.1.4.8-py3-none-any.whl | Python 3 | none | any | Details for cschwabpy-0.1.4.8-py3-none-any.whl |
Total release size: 32.8 kB
Release files / cschwabpy-0.1.4.8.tar.gz
| Download URL | cschwabpy-0.1.4.8.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67b57d75c886ae7915b105d3a92fefcce9be97655c917ec69ae9e8908e1d921d
|
|
BLAKE2b-256 checksum How to use checksums |
ec20bdac0f7f82fd75e89eb4ce1c3a416425fb1e95a369a2d686c95ed08bf1c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 31, 2024.
Transparency logRelease files / cschwabpy-0.1.4.8-py3-none-any.whl
| Download URL | cschwabpy-0.1.4.8-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47056adc52dd12a4d3686a9986aa6305924b73d71a350fa4e4abcec2fc67b45c
|
|
BLAKE2b-256 checksum How to use checksums |
60cd9f8b44a255583af963ea47f0ae144b374842139fa447d415061625daa138
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 31, 2024.
Transparency logSecurity for cschwabpy 0.1.4.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for cschwabpy-0.1.4.8.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 31, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.