reqAllOpenOrders() not able to download data of my account

614 Views Asked by At

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.

enter image description here

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.

1

There are 1 best solutions below

0
On

The arguments of the openOrder function are incorrect so its likely not overriding the EWrapper function and ever receiving a callback. It should be:

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

(If openOrder(self) in your example were ever called it would throw an error because order.contract is undefined)

Other problems:

  • There should be a pause between connecting and calling any other functions in EClient (its best to wait for the nextValidID callback)
  • The run() loop is infinite so the disconnect() in your program will never be called.

You would probably be interested in the Python API course in the Trader's Academy on the IBKR website.