Feb-24-2021, 06:10 PM
(This post was last modified: Feb-24-2021, 06:11 PM by stylingpat.)
Ok, you know how reqPnL works, it is constantly getting updated with new pnl ticks.
The above code does not work, it constantly loops square_off(app) every time the unrealizedPnL ticks again, under 200.
Can you adjust the code for me, so that the square_off function only runs once. Thank you
def pnl(self, reqId, dailyPnL, unrealizedPnL, realizedPnL): super().pnl(reqId, dailyPnL, unrealizedPnL, realizedPnL) self.pnl_summary = {"ReqId":reqId, "DailyPnL": dailyPnL, "UnrealizedPnL": unrealizedPnL, "RealizedPnL": realizedPnL} print("unrealized PnL = ", self.pnl_summary["UnrealizedPnL"]) app.trigger = False if app.pnl_summary["UnrealizedPnL"] < 200 and app.trigger == False: app.trigger = True print("Testing") square_off(app)If my unrealizedPnL drops below 200, I want square_off(app) function to only run once, not every single time the unrealizedpnl ticks back again (every second) below 200.
The above code does not work, it constantly loops square_off(app) every time the unrealizedPnL ticks again, under 200.
Can you adjust the code for me, so that the square_off function only runs once. Thank you
