コード例 #1
0
    void onSecurityCreate (
        MamdaSubscription*             subscription,
        MamdaMultiSecurityManager&     manager,
        const char*                    securitySymbol,
        bool                           isPrimary)
    {
        // Create a trade and quote listener for the security
        MamdaTradeListener* aTradeListener = new MamdaTradeListener;
        MamdaQuoteListener* aQuoteListener = new MamdaQuoteListener;
        ComboTicker*        aTicker = new ComboTicker (*aTradeListener,
                                                       *aQuoteListener);

        aQuoteListener->addHandler (aTicker);
        aTradeListener->addHandler (aTicker);
        manager.addSecurityListener (aQuoteListener, securitySymbol);
        manager.addSecurityListener (aTradeListener, securitySymbol);
    }
コード例 #2
0
int main (int argc, const char **argv)
{
    try
    {
        CommonCommandLineParser     cmdLine (argc, argv);
        // Initialise the MAMA API
        mamaBridge bridge = cmdLine.getBridge();
        Mama::open ();

        const vector<const char*>&  symbolList    = cmdLine.getSymbolList ();
        MamaSource*                 source        = cmdLine.getSource();
        MamaSource*                 optionSource  = cmdLine.getOptionSource();
        int                         duration      = cmdLine.getOptInt ("duration");
        double                      timeout       = cmdLine.getTimeout ();
        MamaLogLevel                subscLogLevel = cmdLine.getSubscLogLevel();
        MamaQueueGroup  queues (cmdLine.getNumThreads(), bridge);

        double  throttleRate  = cmdLine.getThrottleRate ();
        if ((throttleRate > 100.0) || (throttleRate <= 0.0))
        {
            // We don't really want to swamp the FHs with these types of
            // subscriptions.  
            throttleRate = 100.0;
        }
        source->getTransport()->setOutboundThrottle (throttleRate,
                                                     MAMA_THROTTLE_DEFAULT);

        DictRequester   dictRequester (bridge);
        dictRequester.requestDictionary (cmdLine.getDictSource());
        MamdaTradeFields::setDictionary (*dictRequester.getDictionary());
        MamdaQuoteFields::setDictionary (*dictRequester.getDictionary());
        MamdaFundamentalFields::setDictionary (*dictRequester.getDictionary());
        MamdaOptionFields::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);
                optionSource->getTransport()->setSymbolMap (aMap);
            }
        }

        for (vector<const char*>::const_iterator i = symbolList.begin ();
            i != symbolList.end ();
            ++i)
        {
            const char* symbol = *i;
            MamaQueue* queue = queues.getNextQueue();

            // Create chain and listener objects.
            MamdaTradeListener* aBaseTradeListener = new MamdaTradeListener;
            MamdaQuoteListener* aBaseQuoteListener = new MamdaQuoteListener;
            MamdaFundamentalListener* aFundamentalListener
                = new MamdaFundamentalListener;
            MamdaOptionChain*   anOptionChain = new MamdaOptionChain (symbol);
            anOptionChain->setUnderlyingQuoteListener (aBaseQuoteListener);
            anOptionChain->setUnderlyingTradeListener (aBaseTradeListener);
            MamdaOptionChainListener*  anOptionListener =
                new MamdaOptionChainListener (anOptionChain);

            // By Default Expirate Date , Strike Price and PutCall fields
            // are considered manditory to the creation of an option contract
            // Clear monditory status of each of these fields if so directed
            // n the command line.
            anOptionListener->setManditoryFields (
                !cmdLine.getOptBool ("noExpire"),
                !cmdLine.getOptBool ("noStrike"),
                !cmdLine.getOptBool ("noPutCall"));

            // Create our handlers (the UnderlyingTicker and
            // OptionChainDisplay could be a single class).
            UnderlyingTicker*   aBaseTicker = 
                new UnderlyingTicker (*anOptionChain);
            OptionChainDisplay*  aDisplay = 
                new OptionChainDisplay (*anOptionChain);

            // Create subscriptions for underlying and option chain:
            MamdaSubscription*  anOptionSubscription = new MamdaSubscription;

            // Register for underlying quote and trade events.
            aBaseTradeListener->addHandler (aBaseTicker);
            aBaseQuoteListener->addHandler (aBaseTicker);
            aFundamentalListener->addHandler (aBaseTicker);
 


            // Register for underlying option events.
            anOptionListener->addHandler (aDisplay);

            // The timeout defaults to 1 for this example because we
            // currently use the timeout feature to determine when
            // to say that we have received all of the initials.     
            anOptionSubscription->setTimeout (timeout);
            anOptionSubscription->addMsgListener (anOptionListener);
            anOptionSubscription->addQualityListener (aDisplay);
            anOptionSubscription->addErrorListener (aDisplay);
            anOptionSubscription->setType (MAMA_SUBSC_TYPE_GROUP);
            anOptionSubscription->create (queue, source, symbol);
            // logger...
            anOptionSubscription->getMamaSubscription ()->
                setDebugLevel (subscLogLevel);
        }
        
        ShutdownTimer shutdownCallback (bridge);
        MamaTimer     shutdownTimer;
        if (duration > 0)
        {
            shutdownTimer.create (Mama::getDefaultEventQueue (bridge), 
                                  &shutdownCallback, duration, 
                                  queues.getNextQueue());
        }
        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 << "Exception in main (): " << e.toString () << endl;
        exit (1);
    }
    catch (exception &ex)
    {
        cerr << "Exception in main (): " << ex.what () << endl;
        exit (1);
    }
    catch (...)
    {
        cerr << "Unknown Exception in main ()." << endl;
        exit (1);
    }
}
コード例 #3
0
ファイル: tradeticker.cpp プロジェクト: antmd/OpenMAMA
int main (int argc, const char **argv)
{
    setbuf (stdout, NULL);
    try
    {
        CommonCommandLineParser     cmdLine (argc, argv);
        // Initialise 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);
        dictRequester.requestDictionary (cmdLine.getDictSource());
        MamdaCommonFields::setDictionary (*dictRequester.getDictionary());
        MamdaTradeFields::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;
            MamdaTradeListener* aTradeListener = new MamdaTradeListener;
            TradeTicker*        aTicker        = new TradeTicker;

            aTradeListener->addHandler (aTicker);
            aSubscription->addMsgListener (aTradeListener);
            aSubscription->addQualityListener (aTicker);
            aSubscription->addErrorListener (aTicker);
            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 (exception &ex)
    {
        cerr << "Exception in main (): " << ex.what () << endl;
        exit (1);
    }
    catch (...)
    {
        cerr << "Unknown Exception in main ()." << endl;
        exit (1);
    }
    return 1;
}
コード例 #4
0
    void onTradeReport (
        MamdaSubscription*      subscription,
        MamdaTradeListener&     listener,
        const MamaMsg&          msg,
        const MamdaTradeReport& event,
        const MamdaTradeRecap&  recap)
    {
        ofstream Fieldtest1; 
        //Fieldtest1.open ("ControlCallBackMsgs/TradeFields/TradeFieldTest.out");
        Fieldtest1.open ("newMsgs/newTradeFieldTest.out");
        if(!Fieldtest1)
        {
            cout << "Cannot open file.\n";
            exit(1);
        }

        Fieldtest1  << recap.getSymbol() 
                    << recap.getSrcTime().getAsString()  
                    << event.getTradePartId()
                    //<< recap.getF64("wTotalVolume",475,113561846)    
                    << recap.getTotalValue()
                    << recap.getVwap() 
                    << recap.getTradeCount()
                    << event.getIsIrregular()
                    << event.getTradeQual()  
                    //<< recap.getI32("wTradeSeqNum",483, 1)
                    << event.getTradeQualNative()
                    << listener.getTradePrice().getValue() 
                    << recap.getNetChange().getValue()   
                    << recap.getPctChange()
                    << recap.getTradeUnits() 
                    << recap.getTradeDirection()
                    << recap.getLastTime().getAsString()
                    << event.getTradeVolume()  
                    << recap.getActivityTime().getAsString() 
                    //<< recap.MamaMsg::getDateTime("wSendTime",?, val)    
                    << recap.getLineTime().getAsString()                         
                    << listener.getPubId()    
                    << recap.getEventSeqNum()   
                    << event.getEventTime().getAsString()      
                    << recap.getIrregPartId()     
                    << recap.getIrregVolume()    
                    << recap.getIrregTime().getAsString()      
                    << recap.getTradeDate().getAsString()   
                    << recap.getOffExAccVolume()    
                    << recap.getOnExAccVolume()   
                    << recap.getOpenPrice().getValue()         
                    << recap.getHighPrice().getValue()  
                    << recap.getLowPrice().getValue()    
                    << recap.getClosePrice().getValue()    
                    << recap.getPrevClosePrice().getValue()    
                    << recap.getAdjPrevClosePrice().getValue()    
                    << recap.getPrevCloseDate().getAsString()    
                    << recap.getBlockCount()   
                    << recap.getBlockVolume()  
                    << recap.getOffExVwap()    
                    << recap.getOnExVwap()    
                    << recap.getOffExTotalValue()    
                    << recap.getOnExTotalValue()    
                    << recap.getStdDev()    
                    << recap.getStdDevSum()    
                    << recap.getStdDevSumSquares()   
                    << recap.getLastSeqNum()   
                    << recap.getHighSeqNum()    
                    << recap.getLowSeqNum()    
                    << recap.getTotalVolumeSeqNum()    
                    << recap.getCurrencyCode()      
                    << recap.getSettlePrice().getValue()     
                    << recap.getSettleDate().getAsString()    
                    << listener.getOrderId()    
                    << listener.getUniqueId()     
                    << listener.getTradeAction()   
                    << listener.getTradeExecVenue() 
                    << listener.getTradeSellersSaleDays()
                    << listener.getOrigStopStock() 
                    //<< recap.getI64("wOrigSeqNum",423, 1) causes this test to abort    
                    << listener.getOrigPrice().getValue()   
                    << listener.getOrigVolume()    
                    << listener.getOrigPartId()    
                    << listener.getOrigQual()    
                    << listener.getOrigQualNative()    
                    //<< recap.getI64("wOrigSaleDays",422, 1) causes this test to abort    
                    << listener.getOrigStopStock()  
                    << listener.getCorrPrice().getValue()    
                    << listener.getCorrPartId()    
                    << listener.getCorrQual()    
                    << listener.getCorrQualNative()    
                    //<< recap.getI64("wCorrSaleDays",250, 1)causes this test to abort      
                    << listener.getCorrStopStock()    
                    << listener.getOffExchangeTradePrice().getValue()    
                    << listener.getOnExchangeTradePrice().getValue()   
                    << flush; 
  
        Fieldtest1.close();     
        
        ofstream  Fieldtest2;  
        //Fieldtest2.open ("ControlCallBackMsgs/TradeFieldStates/TradeFieldStateTest.out");
        Fieldtest2.open ("newMsgs/newTradeFieldStatesTest.out");  
        if(!Fieldtest2)
        {
            cout << "Cannot open file.\n";
            exit(1);
        }
            
        Fieldtest2  << recap.getSymbolFieldState()          
                    << recap.getSrcTimeFieldState()   
                    << event.getTradePartIdFieldState()
                    //<< recap.getF64("wTotalVolume",475,113561846)    
                    << recap.getTotalValueFieldState() 
                    << recap.getVwapFieldState()
                    << recap.getTradeCountFieldState()
                    << event.getIsIrregularFieldState() 
                    << event.getTradeQualFieldState()  
                    //<< recap.getI32("wTradeSeqNum",483, 1)
                    << event.getTradeQualNativeFieldState()
                    << listener.getTradePriceFieldState()
                    << recap.getNetChangeFieldState()  
                    << recap.getPctChangeFieldState()
                    << recap.getTradeUnitsFieldState() 
                    << recap.getTradeDirectionFieldState()
                    << recap.getLastTimeFieldState()
                    << event.getTradeVolumeFieldState()  
                    << recap.getActivityTimeFieldState() 
                    //<< recap.MamaMsg::getDateTime("wSendTime",?, val)    
                    << recap.getLineTimeFieldState()                       
                    << listener.getPubIdFieldState()    
                    << recap.getEventSeqNumFieldState()   
                    << event.getEventTimeFieldState()      
                    << recap.getIrregPartIdFieldState()     
                    << recap.getIrregVolumeFieldState()    
                    << recap.getIrregTimeFieldState()      
                    << recap.getTradeDateFieldState()  
                    << recap.getOffExAccVolumeFieldState()    
                    << recap.getOnExAccVolumeFieldState()   
                    << recap.getOpenPriceFieldState()         
                    << recap.getHighPriceFieldState() 
                    << recap.getLowPriceFieldState()  
                    << recap.getClosePriceFieldState()  
                    << recap.getPrevClosePriceFieldState()    
                    << recap.getAdjPrevClosePriceFieldState()    
                    << recap.getPrevCloseDateFieldState()    
                    << recap.getBlockCountFieldState()   
                    << recap.getBlockVolumeFieldState()  
                    << recap.getOffExVwapFieldState()    
                    << recap.getOnExVwapFieldState()    
                    << recap.getOffExTotalValueFieldState()    
                    << recap.getOnExTotalValueFieldState()    
                    << recap.getStdDevFieldState()    
                    << recap.getStdDevSumFieldState()    
                    << recap.getStdDevSumSquaresFieldState()   
                    << recap.getLastSeqNumFieldState()   
                    << recap.getHighSeqNumFieldState()    
                    << recap.getLowSeqNumFieldState()    
                    << recap.getTotalVolumeSeqNumFieldState()    
                    << recap.getCurrencyCodeFieldState()     
                    << recap.getSettlePriceFieldState()    
                    << recap.getSettleDateFieldState()    
                    << listener.getOrderIdFieldState()    
                    << listener.getUniqueIdFieldState()     
                    << listener.getTradeActionFieldState()   
                    << listener.getTradeExecVenueFieldState() 
                    << listener.getTradeSellersSaleDaysFieldState()
                    << listener.getOrigStopStockFieldState() 
                    //<< recap.getI64("wOrigSeqNum",423, 1) causes this test to abort    
                    << listener.getOrigPriceFieldState()   
                    << listener.getOrigVolumeFieldState()    
                    << listener.getOrigPartIdFieldState()    
                    << listener.getOrigQualFieldState()    
                    << listener.getOrigQualNativeFieldState()    
                    //<< recap.getI64("wOrigSaleDays",422, 1) causes this test to abort    
                    << listener.getOrigStopStockFieldState()  
                    << listener.getCorrPriceFieldState()   
                    << listener.getCorrPartIdFieldState()    
                    << listener.getCorrQualFieldState()    
                    << listener.getCorrQualNativeFieldState()    
                    //<< recap.getI64("wCorrSaleDays",250, 1)causes this test to abort      
                    << listener.getCorrStopStockFieldState()    
                    << listener.getOffExchangeTradePriceFieldState()   
                    << listener.getOnExchangeTradePriceFieldState()   
                    << flush;  
   
        Fieldtest2.close();            
        return ;   
    }