Package: qtrade
QtradeThis is a very basic Python 3.8+ wrapper for theQuestrade API, a Canadian low cost broker.InstallationThis package is available viaPyPIand can be installed via the commandpip install qtradeUsageFor an overview of the package API, please take a look at thedocs. The main class of the package is calledQuestradeand houses most of the functionality provided by the package. Below are a few examples for possible use cases.Token managementThe central class can be initialized viafromqtradeimportQuestradeqtrade=Questrade(access_code='<access_code>')where<access_code>is the token that one gets from the Questrade API portal. It is calledaccess_codesince 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 formaccess_token:<access_token>api_server:<api_url>expires_in:1234refresh_token:<refresh_token>token_type:BearerIf the token is expired, one can useqtrade.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 functionalityThere currently exists some basic functionality to get stock information viaaapl,amzn=qtrade.ticker_information(['AAPL','AMZN'])and current stock quotes can be obtained viaaapl,amzn=qtrade.get_quote(['AAPL','AMZN'])In addition, one can get historical stock quotes viaaapl_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 theQuestrade API description.Account informationIn addition, the Questrade API gives access to account information about the accounts connected to
the token. The accounts IDs can be accessed viaaccount_ids=qtrade.get_account_id()By using the correct account ID, one can get the positions of the accounts viapositions=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 viaactivities=qtrade.get_account_activities(123456,'2018-08-01','2018-08-16')ContributorsContributions are always appreciated! For example:open an issue for a missing feature or a buggive feedback about existing functionalitymake suggestions for improvementssubmit a PR with a new feature (though reaching out would be appreciated)etc.There is a test suite that can be run viapython -m pytest. This project usespre-commitandblack,flake8andisortwhich takes care of automatic code formatting and linting. When setting up the development
environment, runpre-commit installto set up the hook. This will run all the linting automatically when
committing code changes.DisclaimerI am in no way affiliated with Questrade and using this API wrapper is licensed via the MIT license.