This is an unofficial python program to access the Schwab api.
Discord, PyPI, Youtube, Github.
pip install schwabdev requests websockets
You may need to use pip3
instead of pip
- Setup 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.
- Install packages
- Install schwabdev and requirements
pip install schwabdev requests websockets
- You may need to use
pip3
instead ofpip
- Install schwabdev and requirements
- Examples on how to use the client are in the
examples/
folder (add your keys in the .env file)- The first time you run you will have to sign in to your Schwab account using the generated link in the terminal. After signing in, agree to the terms, and select account(s). Then you will have to copy the link in the address bar and paste it into the terminal.
- Questions? - join the Discord group.
import schwabdev #import the package
client = schwabdev.Client('Your app key', 'Your app secret') #create a client
print(client.account_linked().json()) #make api calls
- Authenticate and access the api
- Auto "access token" updates.
- Functions for all api functions (examples in
examples/api_demo.py
) - Stream real-time data with a customizable response handler (examples in
examples/stream_demo.py
)
- Automatic refresh token updates. (Waiting for Schwab implementation)
The schwabdev folder contains code for main operations:
api.py
contains functions relating to api calls, requests, and automatic token checker threads.stream.py
contains functions for streaming data from websockets.
- Authentication and Requests Github code has significantly changed since this video
- Streaming Real-time Data
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.