def getOrdersToBeCancelled(): allActiveOrders = cryptsyClient.getAllActiveOrders() ordersToBeCancelled = [] for openOrder in allActiveOrders: openMarketNormalized = fromCryptsyServerTime(datetime.strptime(openOrder[2], '%Y-%m-%d %H:%M:%S')) if openOrder[3] == 'Buy' and (openMarketNormalized + timedelta(minutes=5)) < datetime.utcnow(): ordersToBeCancelled.append(openOrder[1]) elif openOrder[3] == 'Sell' and (openMarketNormalized + timedelta(minutes=10)) < datetime.utcnow(): ordersToBeCancelled.append(openOrder[1]) return ordersToBeCancelled
def test_fromCryptsyServerTime(self): now = datetime.now() cryptsy_time = fromCryptsyServerTime(now) self.assertEqual(cryptsy_time, now + timedelta(hours=CRYPTSY_HOURS_DIFFERENCE))