Class MamdaOrderBook


  • public class MamdaOrderBook
    extends java.lang.Object
    MamdaOrderBook is a class that provides order book functionality, including iterators over price levels and entries within price levels. An order book may be read only or writeable. Copying into a read only book is faster than creating a writeable book. Calling methods that attempt to edit the book structure on a read only book will throw a MamdaOrderBookException.
    • Constructor Detail

      • MamdaOrderBook

        public MamdaOrderBook()
        Construct a new order book object. Contains no price levels upon construction. This book will be writeable.
      • MamdaOrderBook

        public MamdaOrderBook​(MamdaOrderBook copy)
        Construct a copy of the supplied orderbook.
        Parameters:
        copy - The book to copy.
      • MamdaOrderBook

        public MamdaOrderBook​(MamdaOrderBook copy,
                              boolean writeable)
        Construct a copy of the supplied orderbook.
        Parameters:
        copy - The book to copy.
        writeable - is this copy writable. false creates a read only copy
    • Method Detail

      • isReadOnly

        public boolean isReadOnly()
        If this book is read only.
        Returns:
        true if this book is read only.
      • clear

        public void clear()
        Clear all levels from the order book. Clears both the bid and ask side levels from the order book.
      • setSymbol

        public void setSymbol​(java.lang.String symbol)
        The order book subscription symbol.
        Parameters:
        symbol - the symbol.
      • getSymbol

        public java.lang.String getSymbol()
        The order book subscription symbol.
        Returns:
        the symbol.
      • setPartId

        public void setPartId​(java.lang.String PartId)
      • getPartId

        public java.lang.String getPartId()
      • hasPartId

        public boolean hasPartId()
      • findOrCreateLevel

        public MamdaOrderBookPriceLevel findOrCreateLevel​(double price,
                                                          char side)
        Create a price level in the orderbook for the given price/size. The price level is initially empty and marked as "not used". The "not used" status changes automatically when entries are added to the price level.
        Parameters:
        price - The price of the price level to find/create.
        side - The side of the book of the price level to find/create.
        Returns:
        The found or newly create price level.
        Throws:
        MamdaOrderBookException - When an error is encountered during book processing.
      • apply

        public void apply​(MamdaOrderBook deltaBook)
        Apply a delta to this (presumably) full book.
        Parameters:
        deltaBook - The delta to apply to the order book.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • copy

        public void copy​(MamdaOrderBook book)
        Make a writeable deep copy of a book.
        Parameters:
        book - The order book to copy.
      • copyReadOnly

        public void copyReadOnly​(MamdaOrderBook book)
        Make a read only deep copy of a book. This method is faster than the copy (MamdaOrderBook book) method.
        Parameters:
        book - The order book to copy.
      • setAsDeltaDeleted

        public void setAsDeltaDeleted​(MamdaOrderBook bookToDelete)
        Set this order book to be a delta that would, when applied, delete all of the fields in the bookToDelete.
        Parameters:
        bookToDelete - The book to be deleted.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • setAsDeltaDifference

        public void setAsDeltaDifference​(MamdaOrderBook lhs,
                                         MamdaOrderBook rhs)
        Set this order book to be a delta that would, when applied, be the difference between to other books.
        Parameters:
        lhs - An order book.
        rhs - An order book.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • getTotalNumLevels

        public long getTotalNumLevels()
        Get the total number of price levels (both sides of order book).
        Returns:
        The total number of level in the order book.
      • getNumBidLevels

        public int getNumBidLevels()
        Get the number of bid levels.
        Returns:
        the number of bid levels.
      • getNumAskLevels

        public int getNumAskLevels()
        Get the number of ask levels.
        Returns:
        the number of ask levels.
      • getBookTime

        public com.wombat.mama.MamaDateTime getBookTime()
        Return the book time.
        Returns:
        return the book time.
      • setBookTime

        public void setBookTime​(com.wombat.mama.MamaDateTime value)
        Set The SourceDerivative for this book.
        Parameters:
        value - The SourceDerivative.
      • setSourceDerivative

        public void setSourceDerivative​(com.wombat.mama.MamaSourceDerivative value)
        Set The SourceDerivative for this book.
        Parameters:
        value - The SourceDerivative.
      • getSourceDerivative

        public com.wombat.mama.MamaSourceDerivative getSourceDerivative()
        Return the SourceDerivative for this book.
        Returns:
        the SourceDerivative.
      • getSource

        public com.wombat.mama.MamaSource getSource()
        Get the MamaSource for this order book.
        Returns:
        The source.
      • setQuality

        public void setQuality​(short quality)
        Set the mamaQuality for this order book.
        Parameters:
        quality - The new quality.
      • getQuality

        public short getQuality()
        Get the mamaQuality for this order book.
        Returns:
        The quality.
      • setClosure

        public void setClosure​(java.lang.Object closure)
        Set the order book closure handle.
        Parameters:
        closure - The closure.
      • getClosure

        public java.lang.Object getClosure()
        Get the order book closure handle.
        Returns:
        The orderbook closure.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • addEntry

        public void addEntry​(MamdaOrderBookEntry entry,
                             double price,
                             char side,
                             com.wombat.mama.MamaDateTime eventTime,
                             MamdaOrderBookBasicDelta delta)
        Add an entry to the order book and (if "delta" is not NULL) record information about the delta related to this action.
        Parameters:
        entry - the entry
        price - the price
        side - the side (bid or ask)
        eventTime - the event time.
        delta - the delta.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • addEntry

        public MamdaOrderBookEntry addEntry​(java.lang.String entryId,
                                            long entrySize,
                                            double price,
                                            char side,
                                            com.wombat.mama.MamaDateTime eventTime,
                                            com.wombat.mama.MamaSourceDerivative source,
                                            MamdaOrderBookBasicDelta delta)
        Add an entry to the order book and (if "delta" is not NULL) record information about the delta related to this action. The new entry is returned.
        Parameters:
        price - the price
        side - the side (bid or ask)
        eventTime - the event time.
        delta - the delta.
        entryId - The id.
        entrySize - the size
        source - the MamaSourceDerivative.
        Returns:
        the new entry.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • addLevel

        public void addLevel​(MamdaOrderBookPriceLevel level)
        Add a price level to the orderbook.
        Parameters:
        level - The price level to add to the orderbook.
      • updateLevel

        public void updateLevel​(MamdaOrderBookPriceLevel level)
        Update an existing level in the orderbook.
        Parameters:
        level - The details of the price level to update.
        Throws:
        MamdaOrderBookException - When an error is encountered during book processing.
      • populateDelta

        public boolean populateDelta​(com.wombat.mama.MamaMsg msg)
        Populate a MamaMsg of the changes to this order book. This will include the changes from the last time this function was called or all changes from the initial state.
        Parameters:
        msg - A MamaMsg ref containing all changes to the current book.
      • populateRecap

        public void populateRecap​(com.wombat.mama.MamaMsg msg)
        Populate a MamaMsg with the current state of this order book.
        Parameters:
        msg - A MamaMsg containing all book, price and entry (if applicable) details of the current book.
      • deleteLevel

        public void deleteLevel​(MamdaOrderBookPriceLevel level)
        Delete a price level from the orderbook.
        Parameters:
        level - The price level to delete from the orderbook.
        Throws:
        MamdaOrderBookException - When an error is encountered during book processing.
      • reevaluate

        public boolean reevaluate()
        Re-evaluate the order book. This would be performed after the status of sources and/or subsources of an "aggregated order book" (i.e., a book built from multiple sources) have changed.
        Returns:
        Whether the book info changed based on the re-evaluation.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • setNeedsReevaluation

        public void setNeedsReevaluation​(boolean need)
        Set whether this book needs a re-evaluation.
        Parameters:
        need - true if books requires re-evaluation.
      • getNeedsReevaluation

        public boolean getNeedsReevaluation()
        Get whether this book needs a re-evaluation.
        Returns:
        true if the book needs re-evaluation.
      • setCheckSourceState

        public void setCheckSourceState​(boolean check)
        Set whether to check the MamaSourceState when adding/deleting/re-evaluating entries in the book.
        Parameters:
        check - true to check the MamaSourceState.
      • getCheckSourceState

        public boolean getCheckSourceState()
        Get whether to check the MamaSourceState when adding/deleting/re-evaluating entries in the book.
        Returns:
        true if checking the MamaSourceState
      • getLevelAtPrice

        public MamdaOrderBookPriceLevel getLevelAtPrice​(double price,
                                                        char side)
        Return the order book price level at "price" on "side" of the order book.
        Parameters:
        price - The price of the order book price level.
        side - The side of the order book to search.
        Returns:
        The order book price level or NULL if not found.
      • getLevelAtPosition

        public MamdaOrderBookPriceLevel getLevelAtPosition​(long pos,
                                                           char side)
        Return the order book price level at position "pos" in the order book.
        Parameters:
        pos - The position of the order book price level.
        side - The side of the order book to search.
        Returns:
        The order book price level or NULL if not found.
      • getEntryAtPosition

        public MamdaOrderBookEntry getEntryAtPosition​(long pos,
                                                      char side)
        Return the order book entry at position "pos" in the order book.
        Parameters:
        pos - The position of the order book entry.
        side - The side of the order book to search.
        Returns:
        The order book entry or NULL if not found.
      • assertEqual

        public void assertEqual​(MamdaOrderBook rhs)
        Order book equality verification. A MamdaOrderBookException is thrown if the books are not equal, along with the reason for the inequality.
        Parameters:
        rhs - The order book to compare to the current book.
        Throws:
        MamdaOrderBookException - The two books are not equal.
      • assertEqual

        public void assertEqual​(MamdaOrderBookPriceLevel lhsLevel,
                                MamdaOrderBookPriceLevel rhsLevel)
        Order book level equality verification. A MamdaOrderBookException is thrown if the books are not equal, along with the reason for the inequality.
        Parameters:
        rhs - The order book to compare to the current book.
        Throws:
        MamdaOrderBookException - The two books are not equal.
      • setIsConsistent

        public void setIsConsistent​(boolean isConsistent)
        Set whether the order book is in a consistent or an an inconsistent state.
        Parameters:
        isConsistent - Whether the book is consistent.
      • getIsConsistent

        public boolean getIsConsistent()
        Get whether the order book is in a consistent or an an inconsistent state. The orderbook will be marked as inconsistent if a gap is detected by the Listener. The book will be marked consistent again once a full recap for the book has been obtained from the feed.
        Returns:
        boolean Whether the book is in a consistent state.
      • dump

        public void dump()
        Dump the order book to standard out.
      • dump

        public void dump​(java.io.OutputStream outputStream)
        Dump the order book to an OutputStream.
        Parameters:
        outputStream - the OutputStream
      • updateEntry

        public void updateEntry​(MamdaOrderBookEntry entry,
                                double size,
                                com.wombat.mama.MamaDateTime eventTime,
                                MamdaOrderBookBasicDelta delta)
        Update an entry in the order book and (if "delta" is not NULL) record information about the delta related to this action. If the entry is not internally "wired" to the order book, a MamdaOrderBookInvalidEntry exception is thrown.
        Parameters:
        entry - the entry
        size - the size
        eventTime - the event time
        delta - the delta.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • deleteEntry

        public void deleteEntry​(MamdaOrderBookEntry entry,
                                com.wombat.mama.MamaDateTime eventTime,
                                MamdaOrderBookBasicDelta delta)
        Delete an entry in the order book and (if "delta" is not NULL) record information about the delta related to this action. If the entry is not internally "wired" to the order book, a MamdaOrderBookInvalidEntry exception is thrown.
        Parameters:
        entry - the entry to detete.
        eventTime - the event time.
        delta - the delta
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • addPriceLevelsFromBookAsEntries

        public void addPriceLevelsFromBookAsEntries​(MamdaOrderBook book,
                                                    java.lang.String source,
                                                    MamdaOrderBookBasicDeltaList delta)
        Add all price levels from another book as entries (one per price level) into this book using "source" as the entryId for each entry.
        Parameters:
        book - The source book to add.
        source - The name to use as the entry ID.
        delta - An optional delta to collect the added entries.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • deleteEntriesFromSource

        public void deleteEntriesFromSource​(com.wombat.mama.MamaSource source,
                                            MamdaOrderBookBasicDeltaList delta)
        Delete all entries in this book that have "source" as its MamaSource.
        Parameters:
        source - The source to match.
        delta - An optional delta to collect the deleted entries.
        Throws:
        MamdaOrderBookException - if called on a read only order book
      • generateDeltaMsgs

        public void generateDeltaMsgs​(boolean publish)
        Enable the generation of book deltas for this book. When delta generation is enabled changes to the book are saved and can be popultaed to MamaMsgs.
        Parameters:
        publish - Whether book delta generation is enabled.
      • getGenerateDeltaMsgs

        public boolean getGenerateDeltaMsgs()
        Get whether book delta generation is enabled
        Returns:
        Whether book delta generation is enabled.
      • clearDeltaList

        public void clearDeltaList()
        clear the delta list using for storing generated deltas
      • addDelta

        public void addDelta​(MamdaOrderBookEntry entry,
                             MamdaOrderBookPriceLevel level,
                             double plDeltaSize,
                             char plAction,
                             char entryAction)
        For book delta generation. Add a delta to the order book delta list for the publishing of order book data
        Parameters:
        entry - MamdaOrderBookEntry where change occurred.
        level - MamdaOrderBookPriceLevel where change occurred.
        plDeltaSize - Pricelevel size change.
        plAction - Pricelevel action.
        entAction - Entry action.
      • detach

        public void detach​(MamdaOrderBookEntry entry)
        NOOP FOR JAVA Adds the entry to the list of entries to be detached.
        Parameters:
        entry - the entry to detach.
      • bidEntryIterator

        public java.util.Iterator bidEntryIterator()
        Iterator for all the bid side entries in the book.
        Returns:
        the iterator.
      • bidIterator

        public java.util.Iterator bidIterator()
        Allows an application to iterate over all the bid side price levels in the order book.
        Returns:
        Iterator java.util.Iterator for the bid side price levels in the order book.
      • askIterator

        public java.util.Iterator askIterator()
        Allows an application to iterate over all ask side price levels in the order book.
        Returns:
        Iterator java.util.Iterator for the ask side price levels in the order book.
      • askEntryIterator

        public java.util.Iterator askEntryIterator()
        Iterator for all the ask side entries in the book.
        Returns:
        the iterator.
      • setStrictChecking

        public static void setStrictChecking​(boolean strict)
        Enforce strict checking of order book modifications (at the expense of some performance). This setting is passed on to the MamdaOrderBookPriceLevel and MamdaOrderBookEntry classes.
        Parameters:
        strict - the value for strict checking.
      • cleanupDetached

        public void cleanupDetached()