As the subject says, I have some live trading code, in Python. I had been using it successfully for well over a week before my issue began. Suddenly, yesterday morning, when my code began running, it would open trades and close them almost as soon as they had been opened [as opposed to waiting until a certain amount of time (ExitThreshold)] had been reached. Here is the errant excerpt of code:
p = trades.OpenTrades(accountID= accountID); pv = client.request(p)
for i in range(0, len(pv["trades"])):
openTime = datetime.datetime.strptime(pv["trades"][i]["openTime"][:19], '%Y-%m-%dT%H:%M:%S')
if (datetime.datetime.utcnow() - openTime).seconds >= ExitThreshold:
closeID = pv["trades"][i]["id"]
r = trades.TradeClose(accountID, tradeID= closeID, data= TradeCloseRequest(units= "ALL").data); rv = client.request(r)
I have done some dubugging, stepped into the execution and repeatedly confirmed that the if condition is False. Nonetheless, the trade is closed regardless. As I had said, this code was previously performing as per expectations for well over a week and there have been no changes to it. So why this sudden change in behaviour???