the connection never drops, I have tried pretty much everything or so I think:
import xmltodict
from ibapi.client import *
from ibapi.wrapper import *
import time
import threading
class IBapi(EWrapper, EClient):
def __init__(self):
EWrapper.__init__(self)
EClient.__init__(self, self)
self.fundamental_data = {}
def fundamentalData(self, reqId: int, data: str):
self.fundamental_data[reqId] = data
print(data)
def fundamentalDataEnd(self, reqId: int):
self.disconnect()
def run_client(self):
contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
self.reqFundamentalData(1, contract, "CalendarReport", [])
self.run()
app = IBapi()
app.connect("127.0.0.1", 7496, 0)
time.sleep(2)
app.run_client()
# Convert the fundamental data to a Python dictionary
data_dict = xmltodict.parse(app.fundamental_data[1])
# Write the dictionary to an XML file
with open("fundamental_data.xml", "w") as f:
xmltodict.unparse(data_dict, output=f)
Save me from this horrible ibkr api !
Thanks.
I tried blocking and async methods but both result in the same way with the connection hanging.
okay I found the answer by browsing the client.py lib; call the follwing function after the method fundamentalData: