繁体   English   中英

"如何将订单正确发布到盈透证券 REST API Python?"

[英]How to correctly post an order to the Interactive Brokers REST API Python?

我正在尝试在 REST API 上向交互式经纪人发布订单,我收到了这个“TypeError:内存视图:需要一个类似字节的对象,而不是'str'”

url = f'https://localhost:5000/v1/api/iserver/account/{account_id}/orders'
orders = []
for position in positions:
    cOID = position['ticker'] + str(position['quantity'])
    order = {
                "acctId": account_id,
                #"conid":,
                #"secType":,
                "cOID":cOID,
                "orderType":"MKT",
                "outsideRTH":False,
                #"price":,
                "side":"SELL",
                "ticker":position['ticker'],
                "tif":"DAY",
                #"referrer":,
                "quantity":position['quantity'],
                "useAdaptive":False,
                "isClose":True,
                "isSingleGroup":True
            }
    orders.append(order)
order_body = json.dumps({"orders":orders}, indent=4)
print(order_body)
headers = {'User-Agent': 'Console', 'content-type': 'application/json'}
response = requests.post(url, data={order_body},headers=headers,verify=False)

我不知道为什么。 我的获取请求正在工作,我只喜欢交互式经纪人的一个简单的工作示例……他们确实需要提供一些示例。

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM