示例#1
0
void BookPublisher::releaseLock(const char* symbol)
{
    //acquirelock on listener
    MamdaOrderBookListener* bookListener = NULL;
    MamdaSubscription* mamdaSub = getMamdaSubscription(symbol);

    try
    {
        vector<MamdaMsgListener*>& msgListeners = mamdaSub->getMsgListeners();
        unsigned long size = msgListeners.size();
        for (unsigned long i = 0; i < size; i++)
        {
            MamdaMsgListener* listener = msgListeners[i];
            bookListener = (MamdaOrderBookListener*)listener;
        }  
    }
    catch (std::exception &e)
    {
      std::cerr << "Exception: " << e.what() << std::endl;
    }
    catch (...)
    {
      std::cerr << "Exception: Unknown" << std::endl;
    }
    
    bookListener->releaseWriteLock();
    printf("\n Listener book lock released \n");
}
示例#2
0
void BookPublisher::subscribeToSymbols () 
{ 

    for (vector<const char*>::const_iterator i = mSymbolList.begin ();
         i != mSymbolList.end ();
         ++i)
    {   
        const char* symbol = *i;
        mBook = new MamdaOrderBook();
        // Turn on delta generation
        mBook->generateDeltaMsgs(true);
        MamdaSubscription*      aSubscription = new MamdaSubscription;
        MamdaOrderBookListener* aBookListener = new MamdaOrderBookListener(mBook);
        aSubscription->addMsgListener (aBookListener);
        aBookListener->setProcessEntries (mProcessEntries);

        BookTicker* aTicker = new BookTicker;
        aBookListener->addHandler (aTicker);
       
        aSubscription->setType (MAMA_SUBSC_TYPE_BOOK);
        aSubscription->setMdDataType (MAMA_MD_DATA_TYPE_ORDER_BOOK);
        mSubscriptionList.push_back (aSubscription);

        aSubscription->create (Mama::getDefaultEventQueue (mBridge), mSubSource, symbol, NULL);

    }
}
示例#3
0
void BookChurn::subscribeToBooks (const char* symbol, MamaQueue* queue)
{
    MamdaSubscription*      aSubscription   = new MamdaSubscription;
    MamdaOrderBookListener* aBookListener   = new MamdaOrderBookListener;
    aSubscription->addMsgListener (aBookListener);
    aBookListener->addHandler  (&mChurn);
    aSubscription->addQualityListener (&mChurn);
    aSubscription->addErrorListener (&mChurn);
    aSubscription->setType (MAMA_SUBSC_TYPE_BOOK);
    aSubscription->setMdDataType (MAMA_MD_DATA_TYPE_ORDER_BOOK);
    aSubscription->create (queue, gSource, symbol);
    mSubscriptionList.push_back (aSubscription);
}
示例#4
0
int main (int argc, const char **argv)
{
    setbuf (stdout, NULL);
    try
    {
        CommonCommandLineParser     cmdLine (argc, argv);
        // Initialize the MAMA API
        mamaBridge bridge = cmdLine.getBridge();
        Mama::open ();

        const vector<const char*>&  symbolList    = cmdLine.getSymbolList ();
        MamaSource*                 source        = cmdLine.getSource();
        MamaQueueGroup              queues (cmdLine.getNumThreads(), bridge);
        DictRequester               dictRequester (bridge);

        // We might as well enforce strict checking of order book updates
        // (at the expense of some performance).
        MamdaOrderBook::setStrictChecking (true);

        signal (SIGINT, finish);         /* arrange interrupts to terminate */
        bool useColor = !cmdLine.getOptBool ('b');  /* check for blk & white */
        start (useColor);

        // Get and initialize the dictionary
        dictRequester.requestDictionary     (cmdLine.getDictSource());
        MamdaCommonFields::setDictionary    (*dictRequester.getDictionary ());
        MamdaOrderBookFields::setDictionary (*dictRequester.getDictionary ());

        const char* symbolMapFile = cmdLine.getSymbolMapFile ();
        if (symbolMapFile)
        {
            MamaSymbolMapFile* aMap = new MamaSymbolMapFile;
            if (MAMA_STATUS_OK == aMap->load (symbolMapFile))
            {
                source->getTransport()->setSymbolMap (aMap);
            }
        }

        for (vector<const char*>::const_iterator i = symbolList.begin ();
             i != symbolList.end ();
             ++i)
        {
            const char* symbol = *i;
            MamdaSubscription*      aSubscription = new MamdaSubscription;
            MamdaOrderBookListener* aBookListener = new MamdaOrderBookListener;
            BookViewer* aViewer = 
                new BookViewer (*aBookListener->getOrderBook());

            aBookListener->setProcessEntries  (true);
            aBookListener->addHandler         (aViewer);
            aSubscription->addMsgListener     (aBookListener);
            aSubscription->addQualityListener (aViewer);
            aSubscription->addErrorListener   (aViewer);
            aSubscription->setType            (MAMA_SUBSC_TYPE_BOOK);
            aSubscription->setMdDataType      (MAMA_MD_DATA_TYPE_ORDER_BOOK);
            aSubscription->create             (queues.getNextQueue (),
                                               source,
                                               symbol);

            aViewer->setShowEntries (false);

            (new MamaIo ())->create (queues.getNextQueue (),
                                aViewer,
                                0,  /* stdin */
                                MAMA_IO_READ);
        }

        Mama::start (bridge);
    }
    catch (MamaStatus &e)
    {
        /*
           This exception can be thrown from Mama::start ().
           Mama::createTransport (transportName) and from
           MamdaSubscription constructor when entitlements is enabled.
        */
        cerr << "MamaStatus exception in main (): " << e.toString () << endl;
        exit (1);
    }
    catch (std::exception &ex)
    {
        cerr << "Exception in main (): " << ex.what () << endl;
        exit (1);
    }
    catch (...)
    {
        cerr << "Unknown Exception in main ()." << endl;
        exit (1);
    }

    return 1;
}
int main (int argc, const char **argv)
{
    try
    {
        CommonCommandLineParser  cmdLine (argc, argv);
        setvbuf (stdout, (char *) NULL, _IONBF, 0);
        // Initialise the MAMA API
        mamaBridge bridge = cmdLine.getBridge();
        Mama::open ();

        const vector<const char*>&
                         symbolList          = cmdLine.getSymbolList ();
        double           throttleRate        = cmdLine.getThrottleRate ();
        int              snapshotInterval    = cmdLine.getOptInt    ("snapshot");
        int              precision           = cmdLine.getPrecision ();
        bool             processEntries      = cmdLine.getOptBool   ('e');
        bool             strictChecking      = !cmdLine.getOptBool  ('C');
        bool             processMarketOrders = cmdLine.getOptBool   ('k');
        bool             showDeltas          = cmdLine.showDeltas   ();
        const char*      dictFile            = cmdLine.getOptString("use_dict_file");
        MamaSource*      source              = cmdLine.getSource    ();
        MamaQueueGroup   queues (cmdLine.getNumThreads(), bridge);
        DictRequester    dictRequester (bridge);

        // We might as well enforce strict checking of order book updates
        // (at the expense of some performance).
        if (strictChecking)
        {
            cout << "MamdaOrderBook strict checking is on" << endl;
            MamdaOrderBook::setStrictChecking (true);
        }
        else
        {
            cout << "MamdaOrderBook strict checking is off" << endl;
            MamdaOrderBook::setStrictChecking (false);
        }

        // Get and initialize the dictionary
        if(dictFile)
        {
            MamaDictionary* dict =new MamaDictionary;
            dict->populateFromFile(dictFile);
            MamdaCommonFields::setDictionary    (*dict);
            MamdaOrderBookFields::setDictionary (*dict);
        }
        else
        {
            dictRequester.requestDictionary     (cmdLine.getDictSource());
            MamdaCommonFields::setDictionary    (*dictRequester.getDictionary());
            MamdaOrderBookFields::setDictionary (*dictRequester.getDictionary ());
        }
        const char* symbolMapFile = cmdLine.getSymbolMapFile ();
        if (symbolMapFile)
        {
            MamaSymbolMapFile* aMap = new MamaSymbolMapFile;
            if (MAMA_STATUS_OK == aMap->load (symbolMapFile))
            {
                source->getTransport()->setSymbolMap (aMap);
            }
        }
        
        for (vector<const char*>::const_iterator i = symbolList.begin ();
            i != symbolList.end ();
            ++i)
        {
            const char* symbol = *i;
            MamdaSubscription*      aSubscription = new MamdaSubscription;
            MamdaOrderBookListener* aBookListener = new MamdaOrderBookListener;
            aSubscription->addMsgListener         (aBookListener);
            aBookListener->setProcessMarketOrders (processMarketOrders);
            aBookListener->setProcessEntries      (processEntries);

            BookTicker* aTicker = new BookTicker;

            aBookListener->addHandler         (aTicker);
            aSubscription->addQualityListener (aTicker);
            aSubscription->addErrorListener   (aTicker);

            aTicker->setShowEntries      (processEntries);
            aTicker->setShowMarketOrders (processMarketOrders);
            aTicker->setShowDeltas       (showDeltas);
            aTicker->setPrecision        (precision);
            
            aSubscription->setType (MAMA_SUBSC_TYPE_BOOK);
            aSubscription->setMdDataType (MAMA_MD_DATA_TYPE_ORDER_BOOK);
            
            aSubscription->create (queues.getNextQueue(), source, symbol);
        }

        Mama::start (bridge);
    }
    catch (MamaStatus &e)
    {  
        // This exception can be thrown from Mama.open ()
        // Mama::createTransport (transportName) and from
        // MamdaSubscription constructor when entitlements is enabled.
        cerr << "MamaStatus exception in main (): " << e.toString () << endl;
        exit (1);
    }
    catch (std::exception &ex)
    {
        cerr << "Exception in main (): " << ex.what () << endl;
        exit (1);
    }
    catch (...)
    {
        cerr << "Unknown Exception in main ()." << endl;
        exit (1);
    }

    exit (1);
}