简体   繁体   English

在 Python 和 Interactive Brokers 中 IBApi.EClient.placeOrder() 之后出现 320 错误

[英]320 Error after IBApi.EClient.placeOrder() in Python & Interactive Brokers

I am trying to place an order through Interactive Brokers' Python API but receive the error:我试图通过盈透证券的 Python API 下订单,但收到错误消息:

ERROR 1 320 Error reading request: Unable to parse data. ERROR 1 320 读取请求时出错:无法解析数据。 java.lang.NumberFormatException: For input string: "1.7976931348623157e+308" java.lang.NumberFormatException:对于输入字符串:“1.7976931348623157e+308”

Connecting and retrieving data works fine but when submitting an order, one of my parameters seems to be wrong and I simply can't figure out what it is.连接和检索数据工作正常,但在提交订单时,我的一个参数似乎是错误的,我根本无法弄清楚它是什么。 I was closely following IB's documentation , so it really comes as a bit of a surprise to me.我一直在密切关注IB 的文档,所以它真的让我感到有点惊讶。

The error code (320) is not really telling, unfortunately, as IB merelydescribes it as a "Server error".不幸的是,错误代码 (320) 并不能说明问题,因为 IB 只是将其描述为“服务器错误”。

The only related question I found online, links the error to an invalid ID but I checked mine and it should be fine.我在网上找到的唯一相关问题,将错误链接到无效 ID,但我检查了我的,应该没问题。

The code:代码:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import Order

import threading

class IBapi(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)

def run_loop():
    app.run()

app = IBapi()
app.connect('127.0.0.1', 7496, 1)

api_thread = threading.Thread(target = run_loop, daemon = True)
api_thread.start()

ctr = Contract()
ctr.symbol = 'AAPL'
ctr.secType = 'STK'
ctr.exchange = 'SMART'
ctr.currency = 'USD'

ord = Order()
ord.action = 'BUY'
ord.orderType = 'LMT'
ord.totalQuantity = 1
ord.lmtPrice = 150

app.reqIds(-1)
id = app.nextValidOrderId
print(id)
print(isinstance(id, int))

app.placeOrder(id, ctr, ord)

returns:回报:

1
True
ERROR 1 320 Error reading request: Unable to parse data. java.lang.NumberFormatException: For input string: "1.7976931348623157e+308"

My TWS version is 10.20.1d, which is the latest as of now (since this fixed a somewhat related question ).我的 TWS 版本是 10.20.1d,这是目前最新的(因为这解决了一个有点相关的问题)。

Can someone help me with what I am doing wrong, please?有人可以帮我解决我做错的事吗?

Using TWS 10.20.1d and API_Version=10.20.01 I find your code works with only a minor change with nextValidOrderId.使用 TWS 10.20.1d 和 API_Version=10.20.01 我发现您的代码只需对 nextValidOrderId 进行微小更改即可使用。

Suggest checking API version, and upgrading if not latest version.建议查看API版本,如果不是最新版本就升级。

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

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