Skip to main content

Python3 Questrade API Wrapper

Project description

questrade_api

Python3 Questrade API Wrapper

Installation

  • Use pip/pip3:

    pip3 install questrade-api

Getting Started

  1. Familiarise yourself with the Security documentation for the Questrade API.

  2. Generate a manual refresh token for your application.

  3. Init the API Wrapper with the refresh token:

    from questrade_api import Questrade
    q = Questrade(refresh_token='XYz1dBlop33lLLuys4Bd')
    

    Important: A token will be created at ~/.questrade.json and used for future API calls

    • If the token is valid future initiations will not require a refresh token
    from questrade_api import Questrade
    q = Questrade()
    

Using the API

Time

q.time
=> {'time': '2018-11-16T09:22:27.090000-05:00'}

Accounts

q.accounts
=> {'accounts': [{'type': 'Margin', 'number': '123456', 'status': 'Active' ...}]}

Account Positions

Accepts: <account_id>

q.account_positions(123456)
=> {'positions': [{'symbol': 'RY.TO', 'symbolId': 34658, 'openQuantity': ...}]}

Account Balances

Accepts: <account_id>

q.account_balances(123456)
=> {'perCurrencyBalances': [{'currency': 'CAD', 'cash': 1000, 'marketValue': 0, ...}]}

Account Executions

Accepts: <account_id>, startTime=, endTime=

q.account_executions(123456)
=> {'executions': []}
q.account_executions(123456,startTime='2018-08-01T00:00:00-0')
=> {'executions': [{'symbol': 'RY.TO', 'symbolId': 34658, 'quantity': 100, ...}]}

Account Orders

Accepts: <account_id>, startTime=, endTime=, stateFilter=

q.account_orders(123456)
=> {'orders': []}
q.account_orders(123456, startTime='2018-08-01T00:00:00-0')
=> {'orders': [{'id': 444444, 'symbol': 'RY.TO', 'symbolId': 34658, ...}]}

Account Order

Accepts: <account_id>, <order_id>

q.account_order(123456, 444444)
=> {'orders': [{'id': 444444, 'symbol': 'RY.TO', 'symbolId': 34658, 'totalQuantity': 100, ...}]}

Account Activities

Accepts: <account_id>, startTime=, endTime=

q.account_activities(123456)
=> {'activities': []}
q.account_activities(123456, startTime='2018-11-01T00:00:00-0')
=> {'activities': []}

Symbol

Accepts: <symbol_id>

q.symbol(34659)
=> {'symbols': [{'symbol': 'RY.TO 'symbolId': 34658, 'prevDayClosePrice': ...}]}

Symbols

Accepts: ids='<symbol_id_1>,<symbol_id_2>', names='<symbol_1>,<symbol_2>'

q.symbols(ids='34658,9339')
=> {'symbols': [{'symbol': 'RY.TO', 'symbolId': 34658, 'prevDayClosePrice': ..}]}
q.symbols(names='RY.TO,BNS.TO')
=> {'symbols': [{'symbol': 'RY.TO', 'symbolId': 34658, 'prevDayClosePrice': ..}]}

Symbols Search

Accepts: prefix='<symbol_1>', offset=

q.symbols_search(prefix='RY.TO')
=> {'symbols': [{'symbol': 'RY.TO', 'symbolId': 34658, 'description': ...}]}
q.symbols_search(prefix='RY', offset=5)
{'symbols': [{'symbol': 'RY.PRE.TO', 'symbolId': 34700, 'description': ...}]}

Symbol Options

Accepts: <symbol_id>

q.symbol_options(34658)
=> {'optionChain': [{'expiryDate': '2018-11-16T00:00:00.000000-05:00', 'description': ... }]}

Markets

q.markets
=> {'markets': [{'name': 'TSX', 'tradingVenues': ['TSX', 'ALPH', 'CXC', ... }]}

Markets Quote

Accepts: <symbol_id>

q.markets_quote(34658)
=> {'quotes': [{'symbol': 'RY.TO', 'symbolId': 34658, 'tier': ... }]}

Markets Quotes

Accepts: ids='<symbol_id_1>,<symbol_id_2>'

q.markets_quotes(ids='34658,9339')
=> {'quotes': [{'symbol': 'RY.TO', 'symbolId': 34658, 'tier': ... }]}

Markets Options

Accepts: optionIds=, filters=

q.markets_options(optionIds=[
    23615873,
    23615874
])
=> {'optionQuotes': [{'underlying': 'RY.TO', 'underlyingId': 34658, 'symbol': 'RY30Nov18 ..}]}
q.markets_options(filters=[
    {
        "optionType": "Call",
        "underlyingId": 34658,
        "expiryDate": "2018-11-30T00:00:00.000000-05:00",
        "minstrikePrice": 90,
        "maxstrikePrice": 100
    }
])
=> {'optionQuotes': [{'underlying': 'RY.TO', 'underlyingId': 34658, 'symbol': 'RY30Nov18 ..}]}

Markets Strategies

Accepts: variants=

q.markets_strategies(variants=[
    {
        "variantId": 1,
        "strategy": "Custom",
        "legs": [
            {
                    "symbolId": 23545340,
                    "ratio": 10,
                    "action": "Buy"
            },
            {
                "symbolId": 23008592,
                "ratio": 10,
                "action": "Sell"
            }
        ]
    }
])
=> {'strategyQuotes': [{'variantId': 1, 'bidPrice': None, 'askPrice': None, 'underlying': 'RY.TO' ...}]}

Markets Candles

Accepts: <symbol_id>, startTime=, endTime=, interval=

q.markets_candles(34658, interval='FiveMinutes')
=> {'candles': [{'start': '2018-11-16T09:30:00.583000-05:00', 'end': '2018-11-16T ..}]}

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

questrade-api-1.0.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

questrade_api-1.0.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file questrade-api-1.0.3.tar.gz.

File metadata

  • Download URL: questrade-api-1.0.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for questrade-api-1.0.3.tar.gz
Algorithm Hash digest
SHA256 c73d3b0a12b50c61572a09fa2e1ab00d5d5a99fd94af3babd49e97da49913969
MD5 0a9bd720d41b276a0df6ac93c30ed438
BLAKE2b-256 4362e392c06de7cae04444cabe58a45f338ac1bd4349831af18deedcd62b1acc

See more details on using hashes here.

File details

Details for the file questrade_api-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: questrade_api-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for questrade_api-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aeca5c459c42b48923684bbd42c3738aad3023728d7b793a598de8890802b109
MD5 0046dc70021288de5aba5cccfb545541
BLAKE2b-256 f1ffc37f985fa98d2e5c404b549c4f270dfc0a7b59768826d194f7eb0d11b1e7

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