Skip to main content

ameritrade-python

This is a simple and lightweight async api wrapper for Ameritrade's API.

The official docs for the Ameritrade API can be found here.

The first time authentication will require utilizing the callback URL/redirect URI to obtain your tokens. This package will generate an auth url to enter into a web browser, you can then paste the resulting url from the redirect url in order to obtain a pair of tokens.

from os import environ
from ameritrade import auth

test_redirect_uri = environ.get("callback_url")
consumer_key = environ.get("consumer_key")

test_auth = auth.Auth(redirect_uri=test_redirect_uri, consumer_key=consumer_key)

def main():
    """Sets the access and refresh tokens by following terminal prompts."""
    await test_auth.manual_auth()

Simple usage using an existing refresh token:

import asyncio
from os import environ
from ameritrade import auth, stock

test_redirect_uri = environ.get("callback_url")
consumer_key = environ.get("consumer_key")
refresh_token = environ.get("refresh_token")

test_auth = auth.Auth(redirect_uri=test_redirect_uri, consumer_key=consumer_key, refresh_token=refresh_token)

async def main():
    """Gets new tokens, then gets a single stock quote for 'KO'/coca-cola."""
    await test_auth.refresh_token_auth()  # Gets fresh tokens

    test_stock = stock.Stock(auth_class=test_auth, symbol="ko")  # creates stock object for KO
    await test_stock.get_quote()  # Makes the quote request
    print(test_stock.quote)


loop = asyncio.get_event_loop()  # Creates the event loop
loop.run_until_complete(main())  # Runs the event loop

Environment

I suggest utilizing a .env file to store private/sensitive information.
If you are not providing a refresh token, it is recommended that you use auth.Auth.manual_auth() in order to use Ameritrade's front end auth tools, you can follow the on-screen instructions for this.

You may choose to save your refresh token in a secure location/format, if using a previous refresh token, you only need to provide these to your auth class:

  • consumer_key
  • refresh_token

Developemnt

Install dependencies with poetry poetry install.

Building Locally

poetry build

Metadata

Release files for ameritrade-python 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ameritrade-python 0.1.2
File Size Uploaded Provenance Actions
ameritrade-python-0.1.2.tar.gz 6.9 kB Without provenance Details for ameritrade-python-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ameritrade-python 0.1.2
File Interpreter ABI Platform Actions
ameritrade_python-0.1.2-py3-none-any.whl Python 3 none any Details for ameritrade_python-0.1.2-py3-none-any.whl

Total release size: 15.3 kB

Release files / ameritrade-python-0.1.2.tar.gz

Download URL ameritrade-python-0.1.2.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
443982962877cab2bd690d6a35aee7dc7fe07df57a40ee8bf436a5287169ae81
BLAKE2b-256 checksum
How to use checksums
de146ece75a6510e171152ed3f060651efa88f563880436ee6ae1abef8a28b3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.3 Windows/10

Release files / ameritrade_python-0.1.2-py3-none-any.whl

Download URL ameritrade_python-0.1.2-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d37e628ebd2b03f59f6fbf2fb44b0512c4dcefed6aeb9251da5043550265621
BLAKE2b-256 checksum
How to use checksums
6022c8550662a606d7e8ad0eef5b7c91b83948e9a53411eeee9ba26c9dd5bb8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.3 Windows/10

Security for ameritrade-python 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page