def books_from_lines_v1(lines, debug=False, end=None, drop_out_of_order=False):
    currBook = None
    # keep track of which side the book starts on,
    # if that side repeats we've reached a new book
    startSide = None
    nLine = 0
    nBooks = 0

    keep_out_of_order = not drop_out_of_order
    maxTimestamp = None
    book_list = []
    for line in lines:
        if end and nBooks > end:
            break
        nLine += 1
        if line[0:9] == "ORDERBOOK":
            nBooks += 1
            if currBook is not None:
                if keep_out_of_order or currBook.lastUpdateTime == maxTimestamp:
                    book_list.append(currBook)
            timestr = line[10:]
            lastUpdateTime = parse_datetime_opt(timestr)
            if maxTimestamp is None or lastUpdateTime > maxTimestamp:
                maxTimestamp = lastUpdateTime
            currBook = OB(lastUpdateTime=lastUpdateTime)
        else:
            row = line.split(',')
            side = row[obc.SIDE]
            entry = Order(
                timestamp=parse_datetime_opt(row[obc.TIMESTAMP]),
                side=side,
                level=int(row[obc.LEVEL]),
                price=float(row[obc.PRICE]),
                size=long(row[obc.SIZE]),
                #orderdepthcount = int(row[obc.ORDERDEPTHCOUNT])
                #ccy = row[obc.CURRENCY]
            )
            if (side == obc.BID): currBook.add_bid(entry)
            elif (side == obc.OFFER): currBook.add_offer(entry)
    return book_list
    def start_new_orderbook(self, line):
        self.at_start_of_file = False
        # periodically clear the order cache so it doesn't eat all the memory
        if len(self.order_cache) > 5000:
            self.order_cache.clear()

        if self.currBook:
            self.books.append(self.currBook)
        _, _, monotonic_time, exchange_time = line.split(',')
        monotonic_seconds, _, monotonic_nanoseconds = monotonic_time.partition(
            ':')
        epoch_seconds, _, exchange_nanoseconds = exchange_time.partition(':')
        epoch_seconds = long(epoch_seconds)
        exchange_seconds = epoch_seconds % self.SECONDS_PER_DAY
        exchange_day = epoch_seconds / self.SECONDS_PER_DAY
        update_time = exchange_seconds * 1000 + long(exchange_nanoseconds) / (
            10**6)
        monotonic_time = long(monotonic_seconds) * 1000 + long(
            monotonic_nanoseconds) / (10**6)
        self.currBook = OB(day=exchange_day,
                           lastUpdateTime=update_time,
                           lastUpdateMonotonic=monotonic_time,
                           actions=self.actions)
        self.actions = []