I am new to ibapi and using liberary "https://pypi.org/project/ibapi/". I want to download all the details of orders inside red box in image.
Code is
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()
kindly help me to find out the mistake or share some completely different approach if you have.
The arguments of the openOrder function are incorrect so its likely not overriding the EWrapper function and ever receiving a callback. It should be:
(If
openOrder(self)
in your example were ever called it would throw an error becauseorder.contract
is undefined)Other problems:
You would probably be interested in the Python API course in the Trader's Academy on the IBKR website.