Skip to main content

Questrade API wrapper for Python

Project description

[![Build Status](https://travis-ci.com/jborchma/qtrade.svg?branch=master)](https://travis-ci.com/jborchma/qtrade)

# Qtrade

This is a very basic Python 3 wrapper for the [Questrade API](https://www.questrade.com/api/documentation/getting-started), a Canadian low cost broker.

## Usage


### Token management

The central class can be initialized via

```python
from qtrade import Questrade

qtrade = Questrade(access_code='<access_code>')
qtrade.get_access_token()
```
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
```python
{'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:
```python
qtrade = Questrade(token_yaml='<yaml_path>')
```
where the yaml-file would have the general form
```yaml
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
```python
qtrade.refresh_token()
```
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

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

and current stock quotes can be obtained via

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

In addition, one can get historical stock quotes via

```python
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](http://www.questrade.com/api/documentation/rest-operations/enumerations/enumerations#historical-data-granularity).

### 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

```python
account_ids = qtrade.get_account_id()
```

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

```python
positions = qtrade.get_account_positions(account_id=123456)
```

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

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


## Contributors

There is a test suite that can be run via `python -m pytest`.


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

qtrade-0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qtrade-0.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file qtrade-0.1.tar.gz.

File metadata

  • Download URL: qtrade-0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for qtrade-0.1.tar.gz
Algorithm Hash digest
SHA256 26e2505b6265e8edf95333f024e69d069ab8a04212ed54e4f852db04addd085e
MD5 ef542c1ba3ccb38ba038b0c1b0ab580c
BLAKE2b-256 eb153f85ddf7df390894532dbf7735481c372ebf73f79a94e7218a9ed2c0ba80

See more details on using hashes here.

File details

Details for the file qtrade-0.1-py3-none-any.whl.

File metadata

  • Download URL: qtrade-0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for qtrade-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6aff08b03a67e7b5c06fa4bc798ee09b146891a89ee05ce6da11f1bf0dde7ae2
MD5 37301f7329bc1710163c1a887c061d62
BLAKE2b-256 742718169da50507eaeac5efe1b84bfa1a1c534ede70b5a0ef6b49e9c26053e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page