Files
externals/linux/include/OnixS/CME/MDP3/Statistics.h
T
2017-08-09 14:33:06 +00:00

752 lines
23 KiB
C++
Executable File

// 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/MDP3/Tags.h"
#include "OnixS/CME/MDP3/Messaging.h"
#include "OnixS/CME/MDP3/EventIndicator.h"
#include "OnixS/CME/MDP3/SettlementPriceType.h"
namespace OnixS
{
namespace CME
{
namespace MDP3
{
// Known statistics types.
struct
ONIXS_CME_MDP3_API
StatisticsTypes
{
// Known statistics types.
enum Enum
{
OpenPrice = '4',
SettlementPrice = '6',
TradingSessionHighPrice = '7',
TradingSessionLowPrice = '8',
SessionHighBid = 'N',
SessionLowOffer = 'O',
ClearedVolume = 'B',
OpenInterest = 'C',
FixingPrice = 'W',
ThresholdLimits = 'g'
};
/// Returns constant from its string representation.
static Enum deserialize(const char*);
/// Returns string representation of statistics type.
static const char* toString(Enum type);
};
/// Type of statistics.
typedef
StatisticsTypes::Enum
StatisticsType;
/// Statistics base attributes.
class
ONIXS_CME_MDP3_API
Statistics
{
public:
/// Start of event processing time (UTC) with nanoseconds precision.
Timestamp transactTime() const
{
return marketDataEntry().message().getTimestamp(
Tags::TransactTime, SinceEpochUnits::Nanoseconds);
}
/// Tag 48. Unique instrument ID as qualified
/// by the exchange per tag 22-SecurityIDSource.
SecurityId
securityId() const
{
return security_;
}
/// Statistics type.
StatisticsType
type() const
{
return type_;
}
/// Market data events present in the
/// message containing given instance.
EventIndicator
eventIndicator() const
{
return EventIndicator(entry_.message());
}
/// Underlying FIX message containing statistics.
/// Group entry contains all the data related with this statistics.
const
GroupInstance&
marketDataEntry() const
{
return entry_;
}
protected:
/// Initializes instance from primary attributes.
Statistics(
SecurityId id,
StatisticsType type,
const GroupInstance& entry)
: security_(id),
type_(type),
entry_(entry)
{
}
/// Cleans everything up.
~Statistics()
{
}
private:
const SecurityId security_;
const StatisticsType type_;
const GroupInstance entry_;
Statistics(const Statistics&);
Statistics& operator =(const Statistics&);
};
/// Flags describing Open Price entry.
struct
ONIXS_CME_MDP3_API
OpenCloseSettlementFlags
{
enum Enum
{
/// Undefined value.
Undefined = -1,
/// Daily Open Price.
DailyOpenPrice = 0,
/// Indicative Opening Price.
IndicativeOpeningPrice = 5
};
/// Returns constant from its string representation.
static Enum deserialize(const char*);
/// Returns string representation of statistics type.
static const char* toString(Enum type);
};
/// Open price flag.
typedef
OpenCloseSettlementFlags::Enum
OpenCloseSettlementFlag;
// Opening Price.
class
ONIXS_CME_MDP3_API
OpeningPrice : public Statistics
{
public:
/// Initializes instance from primary attributes.
OpeningPrice(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::OpenPrice,
marketData)
{
}
/// Detaches from associated market data.
~OpeningPrice()
{
}
/// Statistic field value.
Price
value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Open/Close Settlement Flag.
OpenCloseSettlementFlag
openCloseSettlementFlag() const
{
return getIntEnumFieldValue
<OpenCloseSettlementFlags>(
marketDataEntry(),
Tags::OpenCloseSettlFlag);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Settlement price.
class
ONIXS_CME_MDP3_API
SettlementPrice : public Statistics
{
public:
/// Initializes instance from primary attributes.
SettlementPrice(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::SettlementPrice,
marketData)
{
}
/// Detaches from underlying resources.
~SettlementPrice()
{
}
/// Statistic field value.
Price value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Bitmap field of eight Boolean type indicators representing settlement price type
SettlementPriceType settlPriceType() const
{
return SettlementPriceType(marketDataEntry());
}
/// Trading reference date.
bool tradingReferenceDate(Timestamp& date) const
{
return getDate(marketDataEntry(), Tags::TradingReferenceDate, date);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Trading Session High Price.
class
ONIXS_CME_MDP3_API
TradingSessionHighPrice : public Statistics
{
public:
/// Initializes instance from primary attributes.
TradingSessionHighPrice(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::TradingSessionHighPrice,
marketData)
{
}
/// Detaches from underlying resources.
~TradingSessionHighPrice()
{
}
/// Statistic field value.
Price
value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Trading Session Low Price.
class
ONIXS_CME_MDP3_API
TradingSessionLowPrice : public Statistics
{
public:
/// Initializes instance from primary attributes.
TradingSessionLowPrice(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::TradingSessionLowPrice,
marketData)
{
}
/// Detaches from underlying resources.
~TradingSessionLowPrice()
{
}
/// Statistic field value.
Price
value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Session High Bid.
class
ONIXS_CME_MDP3_API
SessionHighBid : public Statistics
{
public:
/// Initializes instance from primary attributes.
SessionHighBid(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::SessionHighBid,
marketData)
{
}
/// Detaches from underlying resources.
~SessionHighBid()
{
}
/// Statistic field value.
Price
value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Session Low Offer.
class
ONIXS_CME_MDP3_API
SessionLowOffer : public Statistics
{
public:
/// Initializes instance from primary attributes.
SessionLowOffer(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::SessionLowOffer,
marketData)
{
}
/// Detaches from underlying resources.
~SessionLowOffer()
{
}
/// Statistic field value.
Price
value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Trade Volume.
class
ONIXS_CME_MDP3_API
TradeVolume : public Statistics
{
public:
/// Initializes instance from primary attributes.
TradeVolume(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::ClearedVolume,
marketData)
{
}
/// Detaches from underlying resources.
~TradeVolume()
{
}
/// Statistic field value.
SignedQuantity
value() const
{
return marketDataEntry().getInt32(Tags::MDEntrySize);
}
/// Trading reference date.
bool tradingReferenceDate(Timestamp& date) const
{
return getDate(marketDataEntry(), Tags::TradingReferenceDate, date);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Open Interest.
class
ONIXS_CME_MDP3_API
OpenInterest : public Statistics
{
public:
/// Initializes instance from primary attributes.
OpenInterest(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::OpenInterest,
marketData)
{
}
/// Detaches from underlying resources.
~OpenInterest()
{
}
/// Statistic field value.
SignedQuantity
value() const
{
return marketDataEntry().getInt32(Tags::MDEntrySize);
}
/// Trading reference date.
bool tradingReferenceDate(Timestamp& date) const
{
return getDate(marketDataEntry(), Tags::TradingReferenceDate, date);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Fixing Price.
class
ONIXS_CME_MDP3_API
FixingPrice : public Statistics
{
public:
/// Initializes instance from primary attributes.
FixingPrice(
SecurityId security,
const GroupInstance& marketData)
: Statistics(
security,
StatisticsTypes::FixingPrice,
marketData)
{
}
/// Detaches from underlying resources.
~FixingPrice()
{
}
/// Statistic field value.
Price
value() const
{
return marketDataEntry().getDecimal(Tags::MDEntryPx);
}
/// Trading reference date.
bool tradingReferenceDate(Timestamp& date) const
{
return getDate(marketDataEntry(), Tags::TradingReferenceDate, date);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Threshold Limits/Banding.
class
ONIXS_CME_MDP3_API
ThresholdLimits : public Statistics
{
public:
/// Initializes instance from primary attributes.
ThresholdLimits(
SecurityId id,
const GroupInstance& marketData)
: Statistics(
id,
StatisticsTypes::ThresholdLimits,
marketData)
{
}
/// Cleans everything up.
~ThresholdLimits()
{
}
/// Low limit price.
bool
lowLimitPrice(Price& value) const
{
return marketDataEntry().
get(Tags::LowLimitPrice).
toNumber(value);
}
/// High limit price.
bool
highLimitPrice(Price& value) const
{
return marketDataEntry().
get(Tags::HighLimitPrice).
toNumber(value);
}
/// Max price variation.
bool
maxPriceVariation(Price& value) const
{
return marketDataEntry().
get(Tags::MaxPriceVariation).
toNumber(value);
}
/// Returns the string representation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Appends the string representation.
void toString(std::string&) const;
};
/// Statistics updates listener.
class
ONIXS_CME_MDP3_API
StatisticsListener
{
public:
/// Is called with a statistics is
/// removed at the end of a trading session.
virtual
void
onStatisticsReset(
SecurityId securityId,
const ChannelId& channelId) = 0;
/// Is called with a statistics is
/// removed at the end of a trading session.
virtual
void
onStatisticsReset(
const StringRef& securityGroup,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const OpeningPrice& openingPrice,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const SettlementPrice& settlementPrice,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const TradingSessionHighPrice& highPrice,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const TradingSessionLowPrice& lowPrice,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const SessionHighBid& highBid,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const SessionLowOffer& lowOffer,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const TradeVolume& volume,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const OpenInterest& interest,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const FixingPrice& fixingPrice,
const ChannelId& channelId) = 0;
/// Invoked when statistics of certain type is received.
virtual
void
onStatistics(
const ThresholdLimits& limits,
const ChannelId& channelId) = 0;
protected:
virtual ~StatisticsListener();
};
}
}
}