def __init__(self, queue, book, link):
     self._queue = queue
     self.book = book
     self._link = link
     queue.bestPrice += _(self)._onBestChanged
     self.bestPrice = BestPrice(self)
     self.lastTrade = LastTrade()
     queue.lastTrade += _(self)._onTraded
     self.reset()
class Queue(types.IOrderQueue):
    def __init__(self, queue, book, link):
        self._queue = queue
        self.book = book
        self._link = link
        queue.bestPrice += _(self)._onBestChanged
        self.bestPrice = BestPrice(self)
        self.lastTrade = LastTrade()
        queue.lastTrade += _(self)._onTraded
        self.reset()

    def reset(self):
        self._best = self._queue.best
        self._lastT = 0

    @property
    def side(self):
        return self._queue.side

    @property
    def lastPrice(self):
        return self._best.price if self._best is not None else None

    def _update(self, best):
        self._best = best
        self.bestPrice.fire(self)

    def _onTraded(self, value):
        self._link.send(_(self.lastTrade, value).set)

    def _onBestChanged(self, queue):
        best = queue.best
        self._link.send(_(self, best)._update)

    @property
    def best(self):
        return self._best

    @property
    def empty(self):
        return self._best is None