本文整理汇总了C++中MamdaOrderBook类的典型用法代码示例。如果您正苦于以下问题:C++ MamdaOrderBook类的具体用法?C++ MamdaOrderBook怎么用?C++ MamdaOrderBook使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MamdaOrderBook类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}
示例2: onBookAtomicEndBook
/**
* Method invoked when we stop processing the last level in a message. We
* invoke this method after the last entry for the level gets processed.
* The subscription may be destroyed from this callback.
*/
void onBookAtomicEndBook (
MamdaSubscription* subscription,
MamdaBookAtomicListener& listener)
{
/**
* When level recap/delta is received, it is stored in a MamdaOrderBookPriceLevel.
* If no entry deltas/recaps are received, then the price level should be applied
* to the book.
* The entry delta/recap callback will mark the price level with an UNKNOWN side to
* show that it does not need to be applied to the book
*/
if(mReusablePriceLevel.getSide() != MamdaOrderBookPriceLevel::MAMDA_BOOK_SIDE_UNKNOWN)
{
if (gExampleLogLevel == EXAMPLE_LOG_LEVEL_NORMAL
&& mOrderBook.getQuality() == MAMA_QUALITY_OK)
{
prettyPrint(subscription, mReusablePriceLevel);
}
applyLevel(mReusablePriceLevel);
mReusablePriceLevel.setSide(MamdaOrderBookPriceLevel::MAMDA_BOOK_SIDE_UNKNOWN);
}
if(mOrderBook.getQuality() == MAMA_QUALITY_OK && gExampleLogLevel == EXAMPLE_LOG_LEVEL_NORMAL)
{
prettyPrint(mOrderBook);
}
cout<< "BOOK END\n";
}
示例3: attron
void BookViewer::displayLevels (const MamdaOrderBook& book)
{
const char* symbol = book.getSymbol ();
int symbolCol = sMidColumn - (strlen (symbol)/2);
attron (A_BOLD);
mvprintw (0, symbolCol, "%s", symbol);
mvprintw (1, 0, "%s | %s",
" Time Num Size Price",
"Price Size Num Time ");
attroff (A_BOLD);
MamdaOrderBook::constBidIterator bidIter = book.bidBegin ();
MamdaOrderBook::constBidIterator bidEnd = book.bidEnd ();
MamdaOrderBook::constAskIterator askIter = book.askBegin ();
MamdaOrderBook::constAskIterator askEnd = book.askEnd ();
for (int i = 2; i < LINES-1; i++)
{
move (i, 0);
if (i < 7)
attron (COLOR_PAIR (i-1));
if (bidIter != bidEnd)
{
const MamdaOrderBookPriceLevel* bidLevel = *bidIter;
printw (" %12s %4d %7d %7.4f ",
bidLevel->getTime ().getTimeAsString (),
bidLevel->getNumEntries (),
(long)bidLevel->getSize (),
bidLevel->getPrice ());
++bidIter;
}
else
{
printw (" ");
}
printw ("|");
if (askIter!= askEnd)
{
const MamdaOrderBookPriceLevel* askLevel = *askIter;
printw (" %-7.4f %-7d %-6d %-12s ",
askLevel->getPrice (),
(long)askLevel->getSize (),
askLevel->getNumEntries (),
askLevel->getTime ().getTimeAsString ());
++askIter;
}
else
{
printw (" ");
}
if (i < 7)
attroff (COLOR_PAIR (i-1));
}
refresh (); // refresh the screen
}
示例4: MamdaOrderBook
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);
}
示例5: updateQuoteFields
void MamdaQuoteToBookListenerImpl::handleRecap (MamdaSubscription* subscription,
const MamaMsg& msg)
{
// Clear the book
mFullBook->clear();
// Clear ask/bid
mQuoteCache.mBidPrice = 0.0;
mQuoteCache.mBidSize = 0.0;
mQuoteCache.mAskPrice = 0.0;
mQuoteCache.mAskSize = 0.0;
// get all the fields out of the message
updateQuoteFields (msg);
checkQuoteCount (subscription, msg);
if (mFullBook->getIsConsistent()==false)
{
mama_log (MAMA_LOG_LEVEL_NORMAL,
"Received Recap: Book now consistent for %s\n",
(subscription ? subscription->getSymbol() : "no symbol"));
}
MamdaOrderBookPriceLevel* level = NULL;
if (mQuoteCache.mGotBidSize || mQuoteCache.mGotBidPrice)
{
addLevel (level,
mQuoteCache.mBidPrice.getValue(),
mQuoteCache.mBidSize,
MamdaOrderBookPriceLevel::MAMDA_BOOK_SIDE_BID,
mQuoteCache.mQuoteTime);
}
if (mQuoteCache.mGotAskSize || mQuoteCache.mGotAskPrice)
{
addLevel (level,
mQuoteCache.mAskPrice.getValue(),
mQuoteCache.mAskSize,
MamdaOrderBookPriceLevel::MAMDA_BOOK_SIDE_ASK,
mQuoteCache.mQuoteTime);
}
mFullBook->setIsConsistent (true);
setQuality (subscription, MAMA_QUALITY_OK);
invokeRecapHandlers (subscription, &msg);
MamdaOrderBookComplexDelta::clear();
}
示例6: MamdaOrderBook
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);
}
}
示例7: invokeDeltaHandlers
void MamdaQuoteToBookListenerImpl::invokeDeltaHandlers (
MamdaSubscription* subscription,
const MamaMsg* msg)
{
if (mCurrentDeltaCount == 0)
{
// no deltas - no change to the top of book on this update.
return;
}
deque<MamdaOrderBookHandler*>::iterator end = mHandlers.end();
deque<MamdaOrderBookHandler*>::iterator i = mHandlers.begin();
for (; i != end; ++i)
{
MamdaOrderBookHandler* handler = *i;
if (mCurrentDeltaCount == 1)
{
handler->onBookDelta (subscription, mListener, msg,
*this, *mFullBook);
}
else
{
MamdaOrderBookComplexDelta::setOrderBook(mFullBook);
handler->onBookComplexDelta (subscription, mListener, msg,
*this, *mFullBook);
MamdaOrderBookComplexDelta::clear();
}
}
mFullBook->cleanupDetached();
mCurrentDeltaCount =0;
}
示例8: onBookAtomicLevelDelta
/**
* Method invoked when an order book delta is reported.
*/
void onBookAtomicLevelDelta (
MamdaSubscription* subscription,
MamdaBookAtomicListener& listener,
const MamaMsg& msg,
const MamdaBookAtomicLevel& level)
{
/**
* The level should only be processed when entires are not received
* i.e. for level only based feeds
* If an entry was received on the previous level, then the level will
* have been marked with an UNKNOWN side and should not be applied to
* the book
*/
if(mReusablePriceLevel.getSide() != MamdaOrderBookPriceLevel::MAMDA_BOOK_SIDE_UNKNOWN)
{
if (gExampleLogLevel == EXAMPLE_LOG_LEVEL_NORMAL
&& mOrderBook.getQuality() == MAMA_QUALITY_OK)
{
prettyPrint(subscription, mReusablePriceLevel);
}
applyLevel(mReusablePriceLevel);
}
/**
* Store the current level
*/
storeLevel(level);
}
示例9: onFailure
void onFailure (MamdaOrderBookCheckType type,
const char* reason,
const MamaMsg* msg,
const MamdaOrderBook& realTimeBook,
const MamdaOrderBook& checkBook)
{
cout << "Failed check ("
<< mamdaOrderBookCheckTypeToString(type) << "): "
<< reason << "\n";
if (gExampleLogLevel >= EXAMPLE_LOG_LEVEL_QUIET)
{
if (msg)
cout << "Failed message: " << msg->toString() << "\n";
cout << "Failed current book: "; realTimeBook.dump(cout);
cout << "Failed checking book: "; checkBook.dump(cout);
cout << "\n";
}
}
示例10: onBookGap
void onBookGap (
MamdaSubscription* subscription,
MamdaOrderBookListener& listener,
const MamaMsg* msg,
const MamdaOrderBookGap& event,
const MamdaOrderBook& book)
{
printf("\n Book Gap \n");
book.dump(std::cout);
}
示例11: addDelta
void MamdaQuoteToBookListenerImpl::deleteLevel (
MamdaOrderBookPriceLevel* level,
MamdaOrderBookPriceLevel::Side plSide,
const MamaDateTime& plTime)
{
mFullBook->detach (level); // remove level from book, but still use level for indicating change
level->setTime (plTime);
level->setSize (0);
addDelta (level, (0-level->getSize()), MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_DELETE);
}
示例12: onBookDelta
void onBookDelta (
MamdaSubscription* subscription,
MamdaOrderBookListener& listener,
const MamaMsg* msg,
const MamdaOrderBookSimpleDelta& delta,
const MamdaOrderBook& book)
{
printf("\n Book Delta \n");
book.dump(std::cout);
}
示例13: onBookClear
void onBookClear (
MamdaSubscription* subscription,
MamdaOrderBookListener& listener,
const MamaMsg* msg,
const MamdaOrderBookClear& clear,
const MamdaOrderBook& book)
{
printf("\n Book Clear \n");
book.dump(std::cout);
}
示例14: setQuality
void MamdaQuoteToBookListenerImpl::setQuality (
MamdaSubscription* sub,
mamaQuality quality)
{
if (mFullBook->getQuality() == quality)
return; // no change
mFullBook->setQuality (quality);
switch (quality)
{
case MAMA_QUALITY_OK:
break;
case MAMA_QUALITY_STALE:
case MAMA_QUALITY_MAYBE_STALE:
case MAMA_QUALITY_PARTIAL_STALE:
case MAMA_QUALITY_FORCED_STALE:
case MAMA_QUALITY_UNKNOWN:
if (mClearStaleBook)
{
acquireLock();
clear();
invokeClearHandlers (sub, NULL);
releaseLock();
}
}
}
示例15: AtomicBookBuilder
AtomicBookBuilder (
const char* symbol)
: mShowEntries (false)
, mShowMarketOrders (false)
, mEntryPtr (NULL)
, mLevelPtr (NULL)
, mSymbol (strdup(symbol))
{
mOrderBook.setSymbol (mSymbol);
mOrderBook.setQuality (MAMA_QUALITY_OK);
}