223 lines
5.5 KiB
C++
223 lines
5.5 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/CME/MDH/ImpliedPriceLevel.h>
|
|
#include <OnixS/CME/MDH/DirectPriceLevel.h>
|
|
|
|
ONIXS_CMEMDH_NAMESPACE_BEGIN
|
|
|
|
/// Price level data attributes of bid
|
|
/// or ask of consolidated order book.
|
|
///
|
|
/// Instance exposes consolidated price
|
|
/// level data as well as provides references
|
|
/// to price level from direct and implied order
|
|
/// books which comply consolidated price level.
|
|
ONIXS_CMEMDH_LTWT_CLASS ConsolidatedPriceLevel
|
|
{
|
|
// Direct price level component.
|
|
const DirectPriceLevel* direct_;
|
|
|
|
// Implied price level component.
|
|
const ImpliedPriceLevel* implied_;
|
|
|
|
// Used to make all references as a valid ones.
|
|
ONIXS_CMEMDH_LTWT_EXPORTED
|
|
static
|
|
const
|
|
DirectPriceLevel*
|
|
null()
|
|
{
|
|
static const
|
|
DirectPriceLevel null_;
|
|
|
|
return &null_;
|
|
}
|
|
|
|
public:
|
|
/// Initializes instance indicating
|
|
/// absence of consolidated data.
|
|
ConsolidatedPriceLevel()
|
|
: direct_(null())
|
|
, implied_(null())
|
|
{
|
|
}
|
|
|
|
/// Initializes instance from direct price level only.
|
|
ConsolidatedPriceLevel(
|
|
const DirectPriceLevel& direct)
|
|
: direct_(&direct), implied_(null())
|
|
{
|
|
}
|
|
|
|
/// Initializes instance from implied price level only.
|
|
ConsolidatedPriceLevel(
|
|
const ImpliedPriceLevel& implied)
|
|
: direct_(null()), implied_(&implied)
|
|
{
|
|
}
|
|
|
|
/// Initializes instance from both
|
|
/// direct and implied price levels.
|
|
ConsolidatedPriceLevel(
|
|
const DirectPriceLevel& direct,
|
|
const ImpliedPriceLevel& implied)
|
|
: direct_(&direct), implied_(&implied)
|
|
{
|
|
}
|
|
|
|
/// Initializes instance as copy of the other one.
|
|
ConsolidatedPriceLevel(
|
|
const ConsolidatedPriceLevel& other)
|
|
: direct_(other.direct_)
|
|
, implied_(other.implied_)
|
|
{
|
|
}
|
|
|
|
/// Finalizes instance.
|
|
~ConsolidatedPriceLevel()
|
|
{
|
|
}
|
|
|
|
/// Indicates whether instance has a valid data
|
|
/// and actually exists at the level accessed.
|
|
bool exist() const
|
|
{
|
|
return (
|
|
direct_->exist() ||
|
|
implied_->exist()
|
|
);
|
|
}
|
|
|
|
/// Price component.
|
|
const Decimal& price() const
|
|
{
|
|
return (
|
|
direct_->exist()
|
|
? direct_->price()
|
|
: implied_->price()
|
|
);
|
|
}
|
|
|
|
/// Quantity component.
|
|
Int32 quantity() const
|
|
{
|
|
return (
|
|
direct_->quantity() +
|
|
implied_->quantity()
|
|
);
|
|
}
|
|
|
|
/// Reference to price level from direct
|
|
/// book consolidated into given instance.
|
|
///
|
|
/// Use 'exist' member of returned reference
|
|
/// to check whether returned instance refers
|
|
/// to a valid data or there were no corresponding
|
|
/// level available in direct book.
|
|
const
|
|
DirectPriceLevel&
|
|
direct() const
|
|
{
|
|
return *direct_;
|
|
}
|
|
|
|
/// Consolidates direct price level data part.
|
|
void
|
|
consolidate(
|
|
const DirectPriceLevel& direct)
|
|
{
|
|
direct_ = &direct;
|
|
}
|
|
|
|
/// Reference to price level from implied
|
|
/// book consolidated into given instance.
|
|
///
|
|
/// Use 'exist' member of returned reference
|
|
/// to check whether returned instance refers
|
|
/// to a valid data or there were no corresponding
|
|
/// level available in implied book.
|
|
const
|
|
ImpliedPriceLevel&
|
|
implied() const
|
|
{
|
|
return *implied_;
|
|
}
|
|
|
|
/// Consolidates implied price level data part.
|
|
void
|
|
consolidate(
|
|
const ImpliedPriceLevel& implied)
|
|
{
|
|
implied_ = &implied;
|
|
}
|
|
|
|
/// Casts instance to implied price level.
|
|
operator ImpliedPriceLevel() const
|
|
{
|
|
if (direct_->exist())
|
|
{
|
|
return
|
|
ImpliedPriceLevel(
|
|
direct_->price(),
|
|
quantity());
|
|
}
|
|
else
|
|
{
|
|
return *implied_;
|
|
}
|
|
}
|
|
|
|
/// Re-initializes instance as copy of other one.
|
|
ConsolidatedPriceLevel&
|
|
operator =(
|
|
const ConsolidatedPriceLevel& other)
|
|
{
|
|
direct_ = other.direct_;
|
|
implied_ = other.implied_;
|
|
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
/// Serializes price level attributes into a string.
|
|
ONIXS_CMEMDH_EXPORTED
|
|
void
|
|
toStr(
|
|
std::string&,
|
|
const ConsolidatedPriceLevel&);
|
|
|
|
/// Serializes price level attributes into a string.
|
|
inline
|
|
std::string
|
|
toStr(
|
|
const ConsolidatedPriceLevel& priceLevel)
|
|
{
|
|
std::string str;
|
|
|
|
toStr(str, priceLevel);
|
|
|
|
return str;
|
|
}
|
|
|
|
ONIXS_CMEMDH_NAMESPACE_END
|