Beispiel #1
0
TEST_F(MamaFieldCacheFieldTypesTest, testDateTime)
{
    MamaFieldCacheField fieldBase;
    fieldBase.create(1, MAMA_FIELD_TYPE_TIME, "");
    MamaFieldCacheFieldDateTime field;
    const char* s;

    MamaDateTime value;
    MamaDateTime dateTime1;
    dateTime1.setEpochTimeF64(2000);
    field.set(fieldBase, dateTime1);
    s = dateTime1.getAsString();

    MamaDateTime dateTimeRet1 = field.get(fieldBase);
    ASSERT_DOUBLE_EQ(2000, dateTimeRet1.getEpochTimeSeconds());
    s = dateTimeRet1.getAsString();
    getFieldValue(fieldBase, value);
    ASSERT_DOUBLE_EQ(2000, value.getEpochTimeSeconds());

    MamaDateTime dateTime2;
    dateTime2.setEpochTimeF64(2500);
    setFieldValue(fieldBase, dateTime2);
    s = dateTime2.getAsString();

    MamaDateTime dateTimeRet2 = field.get(fieldBase);
    ASSERT_DOUBLE_EQ(2500, dateTimeRet2.getEpochTimeSeconds());
    s = dateTimeRet2.getAsString();
    getFieldValue(fieldBase, value);
    ASSERT_DOUBLE_EQ(2500, value.getEpochTimeSeconds());
}
    void MamdaOptionExpirationDateSet::getExpirations (
        MamdaOptionExpirationDateSet&  result,
        int                            numExpirations) const
    {
        if (this == &result)
            return;

        MamaDateTime date;
        const_iterator iterEnd = end();
        const_iterator i;

        for (i = begin();
             (i != iterEnd) && (numExpirations > 0);
             ++i)
        {
            date = i->first;
            --numExpirations;
        }

        if ((numExpirations == 0) && (!date.empty()))
        {
            getExpirationsBefore(result,date);
        }
        else
        {
            result.copyStrikes(*this);
        }
    }
Beispiel #3
0
int main (int argc, const char** argv)
{
    MamdaOrderBook  book;
    setbuf (stdout, NULL);
    book.setSymbol (symbol);

    // Populate an order book with N price levels ranging from 50.00
    // to 150.00, with M entries in each level.
    char uniqueId[32];
    for (int level = 0; level < N; level++)
    {
        MamdaOrderBookTypes::Side side = (level < N/2) ?
                                         MamdaOrderBookTypes::MAMDA_BOOK_SIDE_BID :
                                         MamdaOrderBookTypes::MAMDA_BOOK_SIDE_ASK;
        double price = 50.0 + (100.0 * level/(double)N);

        for (int entry = 0; entry < M; entry++)
        {
            mama_u64_t   size = 10 * entry;
            MamaDateTime now;
            now.setToNow();
            snprintf(uniqueId, 32, "%s%.4g%c", symbol, price, (char)side);
//            book.addUniqueEntry (uniqueId, price, size, side, now);
        }
    }

    return 0;
}
TEST_F(MamaDateTimeTest, CompareDates)
{
	// Get todays date in a date time
	MamaDateTime *today = NULL;
    try
    {
        today = new MamaDateTime();
    }
    catch (...)
    {
        ASSERT_TRUE(today != NULL);
    }
	//ASSERT_EQ(mamaDateTime_create(&today), MAMA_STATUS_OK);
    today->setToNow();
    //ASSERT_EQ(mamaDateTime_setToNow(today), MAMA_STATUS_OK);

	// Get the string representation of the data
	char stringDate[100] = "";
	//ASSERT_EQ(mamaDateTime_getAsFormattedString(today, stringDate, 100, "%Y-%m-%d"), MAMA_STATUS_OK);
    today->getAsFormattedString(stringDate, 100, "%Y-%m-%d");

	// Destroy the date
	//ASSERT_EQ(mamaDateTime_destroy(today), MAMA_STATUS_OK);
    delete today;

	// Format a string using today's date and a time, this should be as "2010-07-04 10:00:00.000"
	const char *time = "10:00:00.000000";
	char completeDateTime[100] = "";
	sprintf(completeDateTime, "%s %s", stringDate, time);

	// Set the date from this string
	//ASSERT_EQ(mamaDateTime_setFromString(m_cDateTime, completeDateTime), MAMA_STATUS_OK);
    m_DateTime = new MamaDateTime(completeDateTime);    

	// Get the number of seconds
	mama_f64_t completeDateSeconds = 0;
	//ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_cDateTime, &completeDateSeconds), MAMA_STATUS_OK);
    completeDateSeconds = m_DateTime->getEpochTimeSecondsWithCheck();

	// Set the date using just the time string
	//ASSERT_EQ(mamaDateTime_clear(m_cDateTime), MAMA_STATUS_OK);
    m_DateTime->clear();
	//ASSERT_EQ(mamaDateTime_setFromString(m_cDateTime, time), MAMA_STATUS_OK);
    m_DateTime->setFromString(time);

	// Get the number of seconds from this
	mama_f64_t timeSeconds = 0;
	//ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_cDateTime, &timeSeconds), MAMA_STATUS_OK);
    timeSeconds = m_DateTime->getEpochTimeSecondsWithCheck();
    
	// These must be the same
	ASSERT_EQ(completeDateSeconds, timeSeconds);
}
void BookPublisher::createBook (const char* symbol, const char* partId) 
{ 
    mBook = new MamdaOrderBook();
    // This turns on the generation of deltas at the order book 
    mBook->generateDeltaMsgs (true);
    if (symbol) mBook->setSymbol (symbol); 
    if (partId) mBook->setPartId (partId); 
    mBookTime.setToNow();
    mBook->setBookTime (mBookTime);
    mSymbolList.push_back (symbol);
}
    void MamdaOptionExpirationDateSet::copyStrikes (
        const MamdaOptionExpirationDateSet&  rhs)
    {
        // Shallow copy is not good enough.  We want a copy that deep
        // copies the MamdaOptionExpirationStrikes, but not the
        // contents of those strike sets.

        MamaDateTime today;
        today.setToNow();

        clear();
        const_iterator iterEnd = rhs.end();
        const_iterator i;

        for (i = rhs.begin(); i != iterEnd; ++i)
        {
            const MamaDateTime& expireDate = i->first;
            MamdaOptionExpirationStrikes* strikes = i->second;
            insert (value_type (expireDate, new MamdaOptionExpirationStrikes(*strikes)));
        }
    }
TEST_F(MamdaQuoteListenerPerfTest, ProcessUpdateMsgLatency)
{
    MamdaQuoteListener *myQuoteListener = new MamdaQuoteListener;
    mySubscription->addMsgListener (myQuoteListener);
    QuoteTicker *ticker = new QuoteTicker;
    myQuoteListener->addHandler(ticker);

    // create and fire recap msg
    MamaMsg *msg = new MamaMsg();
    msg->create();
    SetQuoteRecapFields(*msg);
    ticker->callMamdaOnMsg(mySubscription, *msg);

    // clear msg and create update msg
    msg->clear();
    SetQuoteUpdateFields(*msg);

    MamaDateTime *begin = new MamaDateTime();
    MamaDateTime *end   = new MamaDateTime();

    begin->setToNow();
    for (int i = 0; i < ITERATIONS; ++i)
    {
        ticker->callMamdaOnMsg(mySubscription, *msg);
    }
    end->setToNow();

    mama_f64_t totalTime = (end->getEpochTimeMicroseconds() - begin->getEpochTimeMicroseconds());
    mama_quantity_t latency = totalTime / ITERATIONS;

    const ::testing::TestInfo* const test_info =
        ::testing::UnitTest::GetInstance()->current_test_info();
    std::cout << "\n" << test_info->name() << ": Latency = " << latency << "us \n";

    if (HasFailure())
    {
        printf("\n **********************************************************************************   "
               "\n \t\t      **** %s failed ****                                                        "
               "\n This test creates recap msg and sends this mgs to orderBookListener                  "
               "\n repetitively (%d), not processing entries                                       "
               "\n ********************************************************************************** \n",
               test_info->name(), ITERATIONS);
    }

    delete ticker;
    ticker = NULL;
    delete myQuoteListener;
    myQuoteListener = NULL;
    delete msg;
    msg = NULL;
    delete begin;
    begin = NULL;
    delete end;
    end = NULL;
}
void QuoteCache::initialize()
{
    mSrcTime.clear();
    mActTime.clear();
    mLineTime.clear();
    mSendTime.clear();
    mBidPrice = 0.0;
    mBidSize  = 0.0;
    mAskPrice = 0.0;
    mAskSize  = 0.0;
    mQuoteTime.clear();
    mQuoteDate.clear();
    mAskTime.clear();
    mBidTime.clear();
    mTmpQuoteCount = 0;
    mQuoteCount    = 0;
    mQuoteSeqNum   = 0;
    mLastGenericMsgWasQuote = false;
    mGotBidPrice = false;
    mGotAskPrice = false;
    mGotBidSize  = false;
    mGotAskSize  = false; 
}
void BookPublisher::processOrder () 
{   
    MamdaOrderBookPriceLevel* level = NULL;
    MamdaOrderBookEntry*      entry = NULL;
    order thisOrder = orderArray[mOrderCount];
    mBookTime.setToNow();

    if (mProcessEntries)
    {          
        switch (thisOrder.entAction)
        {
            case ENTDELETE:
            {
                level = mBook->getLevelAtPrice (thisOrder.price, thisOrder.side);
                
                if (level)
                    entry = level->findEntry (thisOrder.entId);
                if (entry)
                    mBook->deleteEntry (entry, mBookTime, NULL);
                break;
            }
            case ENTADD:
            {
                mBook->addEntry (thisOrder.entId, thisOrder.entSize,
                                 thisOrder.price, thisOrder.side,
                                 mBookTime, NULL, NULL);
                break;
            }
            case ENTUPDATE:
            {
                entry = level->findEntry (thisOrder.entId);
                mBook->updateEntry (entry, thisOrder.entSize,
                                    mBookTime, NULL);
                break;
            }
        }
    }
    else
    {
        level = mBook->getLevelAtPrice(thisOrder.price, thisOrder.side);
        if (level)
        {
            level->setSizeChange (thisOrder.sizeChange);
            level->setPrice      (thisOrder.price);
            level->setSize       (thisOrder.volume);
            level->setNumEntries (thisOrder.numEntries);           
            level->setTime       (mBookTime);
            level->setAction     (thisOrder.plAction);
        }
        else
        {
            level = new MamdaOrderBookPriceLevel();
            level->setSide       (thisOrder.side);
            level->setSizeChange (thisOrder.sizeChange);
            level->setPrice      (thisOrder.price);
            level->setSize       (thisOrder.volume);
            level->setNumEntries (thisOrder.numEntries);           
            level->setTime       (mBookTime);
            level->setAction     (thisOrder.plAction);                
        }
        
        switch (thisOrder.plAction)
        {
            case PLDELETE:
                mBook->deleteLevel(*level);
                break;
            case PLADD:
                mBook->addLevel(*level);
                break;
            case PLUPDATE:
                mBook->updateLevel(*level);
                break;
        }
    }
    mOrderCount++;
}