def _cancel_expired_pending_orders(self):
        """ expires pending orders """
        # use a copy to prevent errors
        pending = self.orders.pending.copy()
        for symbol in pending:
            orderId = pending[symbol]["orderId"]
            expiration = pending[symbol]["expires"]

            delta = expiration - datetime.now()
            delta = self._milliseconds_delta(delta)

            # cancel order if expired
            if delta < 0:
                self.ibConn.cancelOrder(orderId)
                if orderId in self.orders.pending_ttls:
                    if orderId in self.orders.pending_ttls:
                        del self.orders.pending_ttls[orderId]
                    if symbol in self.orders.pending:
                        if self.orders.pending[symbol]['orderId'] == orderId:
                            del self.orders.pending[symbol]
def _cancel_expired_pending_orders ( self ) : pending = self . orders . pending . copy ( ) for symbol in pending : orderId = pending [ symbol ] [ "orderId" ] expiration = pending [ symbol ] [ "expires" ] delta = expiration - datetime . now ( ) delta = self . _milliseconds_delta ( delta ) if delta < 0 : self . ibConn . cancelOrder ( orderId ) if orderId in self . orders . pending_ttls : if orderId in self . orders . pending_ttls : del self . orders . pending_ttls [ orderId ] if symbol in self . orders . pending : if self . orders . pending [ symbol ] [ 'orderId' ] == orderId : del self . orders . pending [ symbol ]
expires pending orders