Skip to main content

A python wrapper for the Ameritrade API.

Project description

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.

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

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

ameritrade-python-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

ameritrade_python-0.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file ameritrade-python-0.1.1.tar.gz.

File metadata

  • Download URL: ameritrade-python-0.1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.3 Windows/10

File hashes

Hashes for ameritrade-python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e1d989bc5b9e8da33d57bf4655883a7c5307670e3ab974a75240122632783f32
MD5 8eb3636f592a8c61180ecc27d7697ead
BLAKE2b-256 be9eb7b9749fc77640e69decc380b85c91c429927d67dfe30eb8449167b61e0b

See more details on using hashes here.

File details

Details for the file ameritrade_python-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ameritrade_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1187a1820457f9461936849a08d69e1abe567b2f705d7e76e35df33855ab3bc
MD5 409f077dff1e9c9a6c938a4be78ccbfc
BLAKE2b-256 4c1e2a0dd7e14da31927578be71e3e40a698c9b27cc37e533a2d212d6ee1bad2

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