Feb-23-2021, 10:57 PM
It looks like you're using the Interactive Brokers' api. I happen to know, from previously working with it, that the IB client pushes constant streams of data to you. So try to think of what you want to do at that specific point in time.
Maybe like this?
def pnl(self, reqId, dailyPnL, unrealizedPnL, realizedPnL): print("UnrealizedPnL:", round(unrealizedPnL)) if unrealizedPnL < -100: print("Step 1", unrealizedPnL) if unrealizedPnL < -50: print("Step 1.5", unrealizedPnL) else: print("Step 2, Worked", unrealizedPnL)Looks like you're trying to do something as the p&l increases over time. In that case, maybe you should keep track of the values as you see them, and compare them with new values as you see them.
Maybe like this?
def __init__(self): self.unrealized_pnl = [] def pnl(self, reqId, dailyPnL, unrealizedPnL, realizedPnL): if not self.unrealized_pnl: # this is the first time we've received data pass else: min_value = min(self.unrealized_pnl) if min_value < -100: print("Step 1", unrealizedPnL) if unrealizedPnL < -50: print("Step 1.5", unrealizedPnL) self.unrealized_pnl.append(unrealizedPnL)