Noob在这里提问,但我正在尝试使用Questrade API下订单。到目前为止,这是我的python脚本:
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)
这是来自Questrade网页的示例请求:
http://www.questrade.com/api/documentation/rest-operations/order-calls/accounts-id-orders
这是我得到的错误:TypeError:request()得到一个意外的关键字参数'quantity' 任何帮助将受到高度赞赏。 Thankss!
答案 0 :(得分:0)
您的请求的所有参数(accountNumber
,symbolId
,quantity
,...)都是Questrade API的参数,而不是post的请求方法。您需要以json格式在请求正文中设置它们: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)
答案 1 :(得分:0)
我创建了一个简单的python包装器来访问questrade API。 https://github.com/antoineviscardi/questradeapi
使用它,您将得到如下内容:
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)