Skip to main content

No project description provided

Project description

(Unofficial) Charles Schwab Stock and Option Trade API Client

License

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

Project details


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.1.4.3.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

cschwabpy-0.1.4.3-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file cschwabpy-0.1.4.3.tar.gz.

File metadata

  • Download URL: cschwabpy-0.1.4.3.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for cschwabpy-0.1.4.3.tar.gz
Algorithm Hash digest
SHA256 f1edf025afd02c765606c5b5664447d51cc4aac112c20c6001bdac8a38be8a91
MD5 60cc2072493c2e429476045ed068cefc
BLAKE2b-256 becd6e90edd9ff9d1752771ea05292dd7f50e2f8c23b942d26f2f5a67a6d545b

See more details on using hashes here.

File details

Details for the file cschwabpy-0.1.4.3-py3-none-any.whl.

File metadata

  • Download URL: cschwabpy-0.1.4.3-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for cschwabpy-0.1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0a0577ace6140e58cc5c92bdc01efa8183ef808011d388ffe647f5fa3774784a
MD5 9e4f18d49b2f78fa4b2d3e973f4e8aaa
BLAKE2b-256 149aba3919f863900b9c582765143805b0686ceb7f3b773263b5cf0a4646bb82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page