0
votes

Noob questions here but I am trying to place an order using Questrade API. This is my python script so far:

import requests

uri = "https://api01.iq.questrade.com/v1/accounts/<id>/orders"

headers = {'Authorization': 'Bearer <my_bearer>'}

r = requests.post(uri, headers=headers, accountNumber=31455565, symbolId=8049, quantity=10, icebergQuantity=1, limitPrice=10, isAllOrNone=True, isAnonymous=False, timeInForce="GoodTillCanceled", primaryRoute="Auto", secondaryRoute="Auto", orderType="Limit", action="Buy")

response = r.json()

print (response)

This is a sample request from Questrade's webpage:

http://www.questrade.com/api/documentation/rest-operations/order-calls/accounts-id-orders

This is the error I'm getting: TypeError: request() got an unexpected keyword argument 'quantity' Any help will be highly appreciated. Thankss!

2
@FrancoisMockers has edited out the auth details in your question. But they are still visible in the edit history. Since the question is already answered, don't delete it. But consider changing your auth details immediately - Ajay Brahmakshatriya

2 Answers

0
votes

All the parameters of your request (accountNumber, symbolId, quantity, ...) are parameters for Questrade API, not for the post method of request. You need to set them in the body of the request, in json format: http://docs.python-requests.org/en/master/user/quickstart/#more-complicated-post-requests

import requests

uri = "https://api01.iq.questrade.com/v1/accounts/<id>/orders"
headers = {'Authorization': 'Bearer <my_bearer>'}

payload = {'accountNumber': 31455565, 'symbolId': 8049, 'quantity': 10, 'icebergQuantity': 1, 'limitPrice': 10, 'isAllOrNone': True, 'isAnonymous': False, 'timeInForce': "GoodTillCanceled", 'primaryRoute': "Auto", 'secondaryRoute': "Auto", 'orderType': "Limit", 'action': "Buy"}
r = requests.post(uri, headers=headers, json=payload)

response = r.json()

print (response)
0
votes

I created a simple python wrapper to access the questrade API. https://github.com/antoineviscardi/questradeapi

Using it you would get something like this:

import questradeapi as qapi

sess = qapi.Session(<your_bearer>)
sess.post_order(31455565, 8049, 10, 1, 10, None, True, False, "Limit", 
"GoodTillCanceled", "Buy", "Auto", "Auto)