Charles Schwab API
Documentation for the Schwab API
The Schwab client provides access to Schwab's API for accounts, trading, and market data operations. This client allows you to initialize a connection with Schwab, perform account-related actions, manage orders, and retrieve market data such as quotes, price history, and option chains.
Make sure you have a Schwab and Schwab developer account:
Set up your Schwab developer account here.
Create a new Schwab individual developer app with callback URL "https://127.0.0.1" (case sensitive)
Wait until the status is "Ready for use", note that "Approved - Pending" will not work.
Enable TOS (Thinkorswim) for your Schwab account, it is needed for orders and other API calls.
Schwab Client Import Statement
Usage Overview
To use the Schwab API client, you must initialize the client by loading environment variables that contain your Schwab API credentials (app_key
, app_secret
, callback_url
). Once initialized, you can perform various actions related to accounts, orders, and market data.
Class: SchwabInitializer
SchwabInitializer
The SchwabInitializer
class sets up the Schwab API client, loading the required credentials from environment variables.
Method: get_client
get_client
The get_client
method returns the initialized Schwab API client to be used for further API calls.
Returns:
An initialized Schwab API client with the required credentials.
Method: schwab
schwab
The schwab
function is a utility method to instantiate and return the Schwab API client using the SchwabInitializer
.
Example Usage:
Example Usage
Hereβs an example of how to use the Schwab client to fetch account details and quotes:
Last updated