reqAllOpenOrders()无法下载我帐户的数据



我是ibapi的新手,正在使用liberary"https://pypi.org/project/ibapi/"。我想下载图片中红框内订单的所有详细信息。

在此处输入图像描述

代码为

from ibapi.client import EClient 
from ibapi.wrapper import EWrapper 
from ibapi.contract import Contract 
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self) 
def error(self, reqId, errorCode, errorString):
print("Error: ", reqId, " ", errorCode, " ", errorString)
def contractDetails(self, reqId, contractDetails):
print("contractDetails: ", reqId, " ", contractDetails) 
def openOrder(self):
super().openOrder()
print("OpenOrder. PermId: ", order.permId, "ClientId:", order.clientId, " OrderId:", orderId, "Account:", order.account, "Symbol:", contract.symbol, "SecType:", contract.secType,"Exchange:", contract.exchange, "Action:", order.action, "OrderType:", order.orderType,"TotalQty:", order.totalQuantity, "CashQty:", order.cashQty, "LmtPrice:", order.lmtPrice, "AuxPrice:", order.auxPrice, "Status:", orderState.status)
order.contract = contract
self.permId2ord[order.permId] = order

def main():
app = TestApp() 
app.connect("127.0.0.1", 1111, 0)
app.reqAllOpenOrders()
app.run() 
app.disconnect()

main()

请帮我找出错误,或者分享一些完全不同的方法。

openOrder函数的参数不正确,因此它可能不会覆盖EWrapper函数并接收回调。应该是:

def openOrder(self, orderId, contract, order, orderState): 

(如果您的示例中调用了openOrder(self),则会抛出错误,因为order.contract未定义(

其他问题:

  • 在连接和调用EClient中的任何其他函数之间应该有一个暂停(最好等待下一个ValidID回调(
  • run((循环是无限的,因此程序中的disconnect((永远不会被调用

您可能会对IBKR网站上交易者学院的Python API课程感兴趣。

相关内容

  • 没有找到相关文章

最新更新