26 #include <boost/format.hpp> 27 #include <boost/foreach.hpp> 29 #include "NamespaceHelper.h" 31 ONIXS_HANDLER_NAMESPACE_BEGIN
36 void bestBid2string(std::stringstream& ss, Price price,
Quantity quantity)
38 ss << boost::format(
" - | %9d | %20d |") % quantity % price.value();
41 void bestAsk2string(std::stringstream& ss, Price price,
Quantity quantity)
43 ss << boost::format(
"%20d | %9d | - |") % price.value() % quantity ;
46 void bid2string(std::stringstream& ss,
const PriceLevel& bid)
48 ss << boost::format(
" %9d | %9d | %20d |") % bid.numberOfOrders() % bid.quantity() % bid.price().value();
51 void ask2string(std::stringstream& ss,
const PriceLevel& ask)
53 ss << boost::format(
"%20d | %9d | %9d |") % ask.price().value() % ask.quantity() % ask.numberOfOrders();
56 void printLevels(std::stringstream& presentation,
const PriceLevels& levels)
63 level != levels.end();
66 presentation << level->toString();
68 if (level != lastLevel)
77 OrderInfo::OrderInfo() :
94 (void) numberOfOrders;
103 orders_.reserve(OrderIdsDefaultSize);
119 : price_(other.price_)
121 , orders_(other.orders_)
125 #if defined(ONIXS_SGXTITAN_ITCH_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_SGXTITAN_ITCH_COMPILER_CXX_RVALUE_REFERENCES 129 : price_(std::move(other.price_))
130 , qty_(std::move(other.qty_))
131 , orders_(std::move(other.orders_))
172 return static_cast<Quantity>(orders_.size());
182 std::swap(price_, obj.price_);
183 std::swap(qty_, obj.qty_);
184 std::swap(orders_, obj.orders_);
189 BOOST_ASSERT(
id != 0);
190 BOOST_ASSERT(quantity != 0);
192 orders_.push_back(
OrderInfo(
id, quantity));
195 struct FindById :
public std::binary_function<OrderInfo, OrderId, bool>
199 BOOST_ASSERT(
id != 0);
207 void PriceLevel::removeOrderId(
OrderId id)
209 BOOST_ASSERT(std::find_if(orders_.begin(), orders_.end(), std::bind2nd(
FindById(),
id)) != orders_.end());
210 orders_.erase(std::remove_if(orders_.begin(), orders_.end(), std::bind2nd(
FindById(),
id)), orders_.end());
215 return level.
price();
220 BOOST_ASSERT(level.quantity() >= level.numberOfOrders());
221 BOOST_ASSERT(level.numberOfOrders() == level.orders().size());
223 return (level.quantity() != 0);
235 std::stringstream ss;
237 ss <<
"PriceLevel [price=" 241 <<
", numberOfOrders=" 262 userPointer_(nullptr)
272 userPointer_ = pointer;
282 return doBestAsk(price, quantity);
287 return doBestBid(price, quantity);
297 return doOrderBookId();
302 return doAsks().empty() && doBids().empty();
326 std::stringstream ss;
328 <<
"Book [securityId=" 334 printLevels(ss,
bids());
337 printLevels(ss,
asks());
355 std::stringstream ss;
358 <<
", depth=" <<
depth() <<
"]";
373 std::stringstream ss;
377 ss << briefInfo <<
"\n";
380 ss <<
" |-------------------------------------------------------------------------------------------------|\n";
381 ss <<
" | BID | | ASC |\n";
382 ss <<
" |-----------------------------------------------+-+-----------------------------------------------|\n";
383 ss <<
" | OrderCount | Quantity | Price | | Price | Quantity | OrderCount |\n";
384 ss <<
" |------------+-----------+----------------------+-+----------------------+-----------+------------|\n";
386 Price bestBidPrice(0);
388 bool bestBidAvailable =
bestBid(bestBidPrice, bestBidQuantity);
390 Price bestAskPrice(0);
392 bool bestAskAvailable =
bestAsk(bestAskPrice, bestAskQuantity);
394 if( bestBidAvailable || bestAskAvailable )
401 bestBid2string(ss, bestBidPrice, bestBidQuantity);
405 bestAsk2string(ss, bestAskPrice, bestAskQuantity);
414 ss <<
"------------+-----------+----------------------+-+----------------------+-----------+------------|\n";
423 for (
size_t level = 0; level <
depth; ++level)
426 << ((level < 9) ?
" " :
" ")
432 level <
bids().size()
433 ?
bids().at(level) : zeroPriceLevel);
440 level <
asks().size()
441 ?
asks().at(level) : zeroPriceLevel);
444 if (level + 1 != depth)
449 ss <<
" |-------------------------------------------------------------------------------------------------|\n";
461 ONIXS_HANDLER_NAMESPACE_END
UInt64 OrderId
Alias for OrderId type.
const Price & price() const
Price value.
void checkSanity(const OrderBook &book)
checks whether the given book is properly built
bool operator()(const OrderInfo &oInf, OrderId id) const
const PriceLevels & bids() const
Returns a set of ascending ask prices for the given security.
bool bestBid(Price &price, Quantity &quantity) const
void swap(PriceLevel &)
swap values
OrderBookId orderBookId() const
Unique instrument Id as qualified.
std::string toShortString() const
Returns brief book info.
Encapsulates price level concept.
#define ONIXS_SGXTITAN_ITCH_NOTHROW
const PriceLevels & asks() const
Returns a set of descending bid prices for the given security.
UInt64 Quantity
Alias for Quantity type.
UInt32 OrderBookId
Alias for Security Id type.
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
const size_t OrderIdsDefaultSize
const Price & getPrice(const PriceLevel &level)
const OrderInfos & orders() const
orders ids for a given level
Quantity quantity() const
Quantify for the given price.
std::vector< OrderInfo > OrderInfos
void setUserPointer(void *pointer)
sets user data pointer
void * getUserPointer() const
returns kept user data pointer
size_t depth() const
Returns the maximum book depth.
std::string toString() const
String presentation of the book.
ONIXS_SGXTITAN_ITCH_API std::ostream & operator<<(std::ostream &stream, const ServiceDescriptor &descriptor)
bool empty() const
Indicates whether book has no bids & asks.
bool bestAsk(Price &price, Quantity &quantity) const
virtual ~OrderBook()
Destruction interface.
bool isValid(const PriceLevel &level)
OrderBook()
Base initialization.
PriceLevel & operator=(const PriceLevel &other)
Quantity numberOfOrders() const
Total number of orders of given price.
std::string toString() const
Returns string representation of the instance.
PriceLevelCollections::ArrayConstEntry PriceLevelsConstEntry
Iterator over read-only collection of price levels.
std::string toFormattedString() const
Returns formatted presentation of the book.