ibapi / TWS api looping unexpectedly

29 Views Asked by At

The question is simple, but I couldn't find the answer for it.

In the following code, I used the TWS api to get the summary of my account.

What I expected to happen is to see the information printed once, and the app staying connected

What actually happened is that the summary of my account keeps being printed once in a while (1 or 2 minutes).

I do not see any reason for it to do it, as I also checked and confirmed that "nextValidId" is only called once, and the request is coming from inside this function.

This means that for some reason accountSummary keeps being called when I do not request for it.

from time import sleep
import ibapi
from ibapi.client import *
from ibapi.wrapper import *


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

    def nextValidId(self,orderId:int):

        print("nextValidId",orderId)

        contract = Contract()
        contract.symbol = "AAPL"
        contract.secType = "STK"
        contract.exchange = "SMART"
        contract.currency = "USD"

        self.reqAccountSummary(1,"All",  "NetLiquidation")

    def accountSummary(self, reqId: int, account: str, tag: str, value: str, currency: str):
        super().accountSummary(reqId, account, tag, value, currency)
        print("AccountSummary. ReqId:", reqId, "Account:", account,"Tag: ", tag, "Value:", value, "Currency:", currency)
        #self.nextValidId(1)


BotApp = BotApp()
BotApp.connect(host="192.168.1.233", port=4002, clientId=166)
BotApp.run()
0

There are 0 best solutions below