Esempio n. 1
0
    /*
     * Helper function to print a MamdaOrderBookPriceLevel
     */
    void prettyPrint(
        MamdaSubscription*                  subscription,
        const MamdaOrderBookPriceLevel&     level)
    {
        // Print Entry Level Info
        const char* symbol        = subscription->getSymbol ();
        const char* time          = level.getTime().getTimeAsString();
        double      price         = level.getPrice ();
        char        side          = level.getSide();
        char        action        = level.getAction ();
        double      size          = level.getSize ();

        cout << "LEVEL "
             << symbol << " "
             << time   << " "
             << action << " "
             << price  << " "
             << side   << " "
             << size   << endl;
    }
Esempio n. 2
0
    /**
     * Helper function to apply a MamdaOrderBookPriceLevel to
     * a MamdaOrderBook
     */
    void applyLevel (MamdaOrderBookPriceLevel& level)
    {
        if(mOrderBook.getQuality() == MAMA_QUALITY_OK)
        {
            switch(level.getAction())
            {
            case MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_UPDATE :
                try
                {
                    /*
                     * When in the order book the only Action which makes sense is
                     * ADD
                     */
                    level.setAction(MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_ADD);

                    mOrderBook.updateLevel(level);
                }
                catch ( MamdaOrderBookException &e)
                {
                    //Exception is thrown when updating level which does not exist
                    //level will be added so handled internally
                }
                break;
            case MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_ADD :
                try
                {
                    mLevelPtr = new MamdaOrderBookPriceLevel(level);
                    /*
                     * When in the order book the only Action which makes sense is
                     * ADD
                     */
                    mLevelPtr->setAction(MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_ADD);

                    mOrderBook.addLevel(*mLevelPtr);
                    //ownership of ptr passed to MamdaOrderBook
                }
                catch ( MamdaOrderBookException &e)
                {
                    //Exception is thrown if adding a level already in book
                    //handled internally by updating level
                    delete mLevelPtr;
                }
                break;
            case MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_DELETE :
                try
                {
                    mOrderBook.deleteLevel(mReusablePriceLevel);
                }
                catch (MamdaOrderBookException &e)
                {
                    //Thrown if the level cannot be found in the book
                    //No need for handling as level is deleted
                }
                break;
            default:
                cout << "atomicbookbuilder: Unknown price level ["
                     << level.getAction() << "]\n";
                break;
            }

            mLevelPtr = NULL;
        }
    }