¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

problem of getting repeated account PnL


 

Hi,

I have touble to receive the correct accout PnL from TWS, the program used to work just fine a couple month ago. However when I try to run the program again I am getting all same account PnL repeatly, I've tried everything to disconneect/reconnect, cancelPnLoperation and etc. It seems the only way get the account PnL update is to stop the program completely and re-run.
my code is attached in below
Can anyone see the problems here? many thanks in advance!

def
pnl(self, reqId: int, dailyPnL: float, unrealizedPnL: float, realizedPnL: float):
from datetime import datetime
self.pnl_tolerance = 1000
finish_time = datetime(2021,6,23,6,0,0)
while datetime.now() < finish_time:
super().pnl(reqId, dailyPnL, unrealizedPnL, realizedPnL)
print(datetime.now())
print("Daily PnL. ReqId:", reqId, "DailyPnL:", dailyPnL,
"UnrealizedPnL:", unrealizedPnL, "RealizedPnL:", realizedPnL)
printout = "Daily PnL :: " + str(dailyPnL)
super().cancelPnL(reqId)
reqId += 1
time.sleep(3)
if dailyPnL <= self.pnl_tolerance:
self.trigger_hit_no += 1
self.tolerance_hit()
else:
self.trigger_hit_no = 0

Regards,

Tom

Join [email protected] to automatically receive all group messages.