So I have a variable x that is being updated to a new value through a websocket within a while loop.
I have an IF statement where
if x >= 150 :
#execute orders here
Now the problem I have is sometimes the x value will spike above 150 for a fraction of a second, perhaps not even 0.01 seconds in which case I do not want to the orders to execute, and disregard this.
I was thinking of solving this by executing if x >= 150 and remains so for 0.1 seconds.
But I am not sure how to execute this. Perhaps I could create a time variable y, when x first goes above 150 and than measure the time difference against the datetime.now. The problem with that is the variable y will keeping changing to the current time as x will be constantly getting updated by the websocket connection.
Any ideas how to do this? Please keep in mind that execution speed is critical to this code making me any money, and also it is a websocket so that x value will be getting updated constantly.