No project description provided
Project description
(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 [TODO]
- Place stock and option trades [TODO]
- Retrieve trade history [TODO]
- 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
from cschwabpy.SchwabAsyncClient import SchwabAsyncClient
app_client_key = "---your-app-client-key-here-"
app_secret = "app-secret"
schwab_client = SchwabAsyncClient(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 = await schwab_client.get_option_expirations_async(underlying_symbol = ticker)
# download SPX option chains
from_date = 2024-07-01
to_date = 2024-07-01
opt_chain_result = await schwab_client.download_option_chain_async(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))
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
cschwabpy-0.0.6.tar.gz
(11.2 kB
view hashes)
Built Distribution
cschwabpy-0.0.6-py3-none-any.whl
(12.3 kB
view hashes)
Close
Hashes for cschwabpy-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 566ecd157a63763afa9105f5fc90fdf864a7a0fd8452f9e2a03c986a2b4af207 |
|
MD5 | f6799cc18d14119e1b91d72ba0b3940d |
|
BLAKE2b-256 | 34d10897bd1f36db4a93a8bb1a8f75d7c7bde7c864ac35a15390f2f5cce26c6c |