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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cschwabpy-0.1.4.4-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cschwabpy-0.1.4.4.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cschwabpy-0.1.4.4.tar.gz
Algorithm Hash digest
SHA256 27fdd862b0f7a4a3c328c91dcd072956586f50765cccad270af0a6d17dd7612f
MD5 63669e3caace635738c4a295dea784a4
BLAKE2b-256 807053028dfe534e7ae98877976c72a465e111c6034a68d549ab9d0a6acb4491

See more details on using hashes here.

Provenance

The following attestation bundles were made for cschwabpy-0.1.4.4.tar.gz:

Publisher: pypi-publish.yml on rcholic/cschwab.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: cschwabpy-0.1.4.4-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cschwabpy-0.1.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7d7535bc6a36b2e02e1797f85bc2c32be2531a0d68c7e1ce0b9f15fb3e611170
MD5 6640dca9bb2654529ef87949213818af
BLAKE2b-256 30ebe35254ca98dbb400d97cbc47ae39ea756ccccc341bfba0c513456c6f3eaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for cschwabpy-0.1.4.4-py3-none-any.whl:

Publisher: pypi-publish.yml on rcholic/cschwab.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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