Skip to main content

All tests passing

Qtrade

This is a very basic Python 3.9+ wrapper for the Questrade API, a Canadian low cost broker.

Installation

This package is available via PyPI and can be installed via the command

pip install qtrade

Usage

For an overview of the package API, please take a look at the docs. The main class of the package is called Questrade and houses most of the functionality provided by the package. Below are a few examples for possible use cases.

Token management

The central class can be initialized via

from qtrade import Questrade

qtrade = Questrade(access_code='<access_code>')

where <access_code> is the token that one gets from the Questrade API portal. It is called access_code since this initial token is used to get the full token data that will include

{'access_token': <access_token>,
 'api_server': '<api_url>',
 'expires_in': 1234,
 'refresh_token': <refresh_token>,
 'token_type': 'Bearer'}

The first call initializes the class and the second call gets the full token.

Another way to initialize the class is to use a token yaml-file via:

qtrade = Questrade(token_yaml='<yaml_path>')

where the yaml-file would have the general form

access_token: <access_token>
api_server: <api_url>
expires_in: 1234
refresh_token: <refresh_token>
token_type: Bearer

If the token is expired, one can use

qtrade.refresh_access_token(from_yaml=True)

to refresh the access token using the saved refresh token.

Once the tokens are set correctly, I have currently added methods to get ticker quotes, the current status of all positions in any Questrade account that is associated with the tokens, any account activities such as trades and dividend payments as well as historical data for tickers that are supported by Questrade.

Basic functionality

There currently exists some basic functionality to get stock information via

aapl, amzn = qtrade.ticker_information(['AAPL', 'AMZN'])

and current stock quotes can be obtained via

aapl, amzn = qtrade.get_quote(['AAPL', 'AMZN'])

In addition, one can get historical stock quotes via

aapl_history = qtrade.get_historical_data('AAPL', '2018-08-01', '2018-08-21','OneHour')

Here, the last input parameter is the interval between quotes. Another option could be 'OneDay'. For more options, see the Questrade API description.

Account information

In addition, the Questrade API gives access to account information about the accounts connected to the token. The accounts IDs can be accessed via

account_ids = qtrade.get_account_id()

By using the correct account ID, one can get the positions of the accounts via

positions = qtrade.get_account_positions(account_id=123456)

Finally, there exists a method to get all account activities (trades, dividends received, etc.) of an account in a certain time frame via

activities = qtrade.get_account_activities(123456, '2018-08-01', '2018-08-16')

Contributors

Contributions are always appreciated! For example:

  • open an issue for a missing feature or a bug
  • give feedback about existing functionality
  • make suggestions for improvements
  • submit a PR with a new feature (though reaching out would be appreciated)
  • etc.

There is a test suite that can be run via python -m pytest. This project uses pre-commit and ruff which takes care of automatic code formatting and linting. When setting up the development environment, run pre-commit install to set up the hook. This will run all the linting automatically when committing code changes.

Disclaimer

I am in no way affiliated with Questrade and using this API wrapper is licensed via the MIT license.

Metadata

Release files for qtrade 0.6.1

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

Source distribution (sdist)

Source distribution for qtrade 0.6.1
File Size Uploaded
qtrade-0.6.1.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qtrade 0.6.1
File Interpreter ABI Platform
qtrade-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.5 kB

Release files / qtrade-0.6.1.tar.gz

Download URL qtrade-0.6.1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3e342b36b781b352b183fda1ac4b964b59115d7577a283a02670c4e9ab2be567
BLAKE2b-256 checksum
How to use checksums
5cb90aacd456610fcdc9bf5e94922cf9dfc7bb1679c638382aafad8c6577fc3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / qtrade-0.6.1-py3-none-any.whl

Download URL qtrade-0.6.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14d4bb7076aa58989d26d730df95470cb38e6ec9cc9bbb1aa0eda88db6aa9115
BLAKE2b-256 checksum
How to use checksums
aaa5cd7ca98c25f07cd83519c065f7002385b85de965cf5714df2cffc654585f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.1

2 release files

0.1

2 release files

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