Files
2019-02-11 17:36:12 +00:00

196 lines
5.3 KiB
C++

/*
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
*
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
* and international copyright treaties.
*
* Access to and use of the software is governed by the terms of the applicable OnixS Software
* Services Agreement (the Agreement) and Customer end user license agreements granting
* a non-assignable, non-transferable and non-exclusive license to use the software
* for it's own data processing purposes under the terms defined in the Agreement.
*
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
* of this source code or associated reference material to any other location for further reproduction
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
*
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
* the terms of the Agreement is a violation of copyright law.
*/
#pragma once
#include <OnixS/ICE/iMpact/MarketData/ABI.h>
#include <OnixS/ICE/iMpact/MarketData/Containers.h>
#include <OnixS/ICE/iMpact/MarketData/Rational.h>
#include <OnixS/ICE/iMpact/MarketData/Time.h>
#include <OnixS/ICE/iMpact/MarketData/Types.h>
namespace OnixS { namespace ICE { namespace iMpact { namespace MarketData {
/// forward declarations
class OrderBookHolder;
/// \brief Defines data for single price level of order book.
struct ONIXS_ICE_IMPACT_MD_API PriceLevel
{
typedef Rational Price;
/// Raw exchange price (fixed point).
Rational price;
/// Total order quantity at price.
int quantity;
/// Implied order quantity at price.
int impliedQuantity;
/// Order count at price.
short orderCount;
/// Implied order count at price.
short impliedOrderCount;
/// Constructor.
explicit PriceLevel(
const Rational& inPrice = Rational()
, int inQuantity = 0
, int inImpliedQuantity = 0
, short inOrderCount = 0
, short inImpliedOrderCount = 0
)
: price(inPrice)
, quantity(inQuantity)
, impliedQuantity(inImpliedQuantity)
, orderCount(inOrderCount)
, impliedOrderCount(inImpliedOrderCount)
{
}
};
/// /brief Defines data for single entry of full order depth book.
struct ONIXS_ICE_IMPACT_MD_API Order
{
typedef OnixS::ICE::iMpact::MarketData::OrderId OrderId;
/// Order ID unique for market.
OrderId orderId;
/// Order entry date/time (milliseconds since 01-01-1970 00:00 GMT).
DateTime entryDateTime;
/// Raw exchange price (fixed point).
Rational price;
/// Order quantity.
int quantity;
/// Sub-milliseconds ordering sequence.
int sequenceWithinMillis;
/// Legacy order modification count.
short orderSequenceId;
/// True if order is implied.
bool isImplied;
/// True if order is Request For Quote.
bool isRFQ;
/// Constructor.
explicit Order(
OrderId inOrderId = OrderId()
, const DateTime& inEntryDateTime = DateTime()
, const Rational& inPrice = Rational()
, int inQuantity = 0
, int inSequenceWithinMillis = 0
, short inOrderSequenceId = 0
, bool inIsImplied = false
, bool inIsRFQ = false
)
: orderId(inOrderId)
, entryDateTime(inEntryDateTime)
, price(inPrice)
, quantity(inQuantity)
, sequenceWithinMillis(inSequenceWithinMillis)
, orderSequenceId(inOrderSequenceId)
, isImplied(inIsImplied)
, isRFQ(inIsRFQ)
{
}
};
typedef ArrayRef<const PriceLevel, std::size_t> PriceLevelArray;
typedef ArrayRef<const Order, std::size_t> OrderArray;
/// \brief Book instance composing price level book and full order depth book.
class ONIXS_ICE_IMPACT_MD_API OrderBook
{
public:
/// Unique identifier of a market.
MarketId marketId() const;
/// Returns the maximum book depth.
std::size_t depth() const;
/// Indicates whether book has no bids & asks.
bool empty() const;
/// Gets bid side of the price level book.
const PriceLevelArray& bids() const;
/// Gets offer side of the price level book.
const PriceLevelArray& offers() const;
/// Gets bid side of the full order depth book.
const OrderArray& bidOrders() const;
/// Gets offer side of the full order depth book.
const OrderArray& offerOrders() const;
/// Returns brief book info.
std::string brief() const;
/// Appends brief book info to the string.
void brief(std::string&) const;
/// String presentation of the book.
std::string toString() const;
/// String presentation of the book.
void toString(std::string&) const;
/// Creates immutable snapshot of the book owned by caller.
/// It's responsibility of caller to delete returned snapshot.
const OrderBook* snapshot() const;
/// Destructor
~OrderBook();
private:
friend class OrderBookHolder;
struct Impl;
OrderBook(Impl*);
// No implementation
OrderBook(const OrderBook&);
OrderBook& operator=(const OrderBook&);
Impl* impl_;
};
inline std::string OrderBook::brief() const
{
std::string str;
brief(str);
return str;
}
inline std::string OrderBook::toString() const
{
std::string str;
toString(str);
return str;
}
}}}} // namespace MarketData, iMpact, ICE, OnixS