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

836 lines
35 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/Initialization.h"
#include "OnixS/CME/MDP3/TcpRecovery.h"
#include "OnixS/CME/MDP3/FeedEngine.h"
#include "OnixS/CME/MDP3/FeedEnums.h"
namespace OnixS
{
namespace CME
{
namespace MDP3
{
/// Defines log alternates.
struct ONIXS_CME_MDP3_API LogModes
{
/// Log alternates.
enum Enum
{
/// Nothing is logged at all.
Disabled,
/// Only important information like
/// warnings and errors will be logged.
///
/// Mode is not suitable for further log
/// replays, because no market data is stored.
Important,
/// Handler will log miscellaneous aspects
/// related with its execution like changes
/// in state, network data obtained, etc. All
/// critical important information like warnings
/// and errors will be logged as well.
///
/// Most suitable mode to produce logs for further replay.
Regular,
/// In addition to the data logged in 'Regular'
/// mode, Handler will output additional information
/// like step-by-step changes into books, step-by-step
/// processing of received network packets.
Debug
};
/// Returns mode of given string presentation.
static Enum deserialize(const char*);
/// Returns string presentation of given mode.
static const char* toString(Enum);
};
/// Log mode.
typedef LogModes::Enum LogMode;
/// Additional options to control log information.
typedef unsigned AdvancedLogOptionSet;
/// Additional options to control log information.
struct ONIXS_CME_MDP3_API AdvancedLogOptions
{
enum Enum
{
/// Nothing except standard
/// information must be logged.
LogNothing = 0x0,
/// Log FIX messages in addition to the
/// packets received from the network.
LogFixMessages = 0x1,
/// Log full book once its updated.
LogFullBooks = 0x2,
/// Logs all additional data/events.
LogEverything = LogFixMessages | LogFullBooks
};
/// Returns string representation of an option.
static
std::string
toString(AdvancedLogOptionSet options);
/// Appends string representation of an option.
static
void
toString(
AdvancedLogOptionSet options,
std::string&);
/// Returns options of given string presentation.
static
AdvancedLogOptionSet
deserialize(
const std::string& options);
};
inline
std::string
AdvancedLogOptions::toString(
AdvancedLogOptionSet options)
{
std::string result;
toString(options, result);
return result;
}
/// Defines book update notification strategies.
struct
ONIXS_CME_MDP3_API
BookUpdateNotificationStrategies
{
enum Enum
{
/// Book update event is raised once security id is changed in
/// sequence of market data entries being processed by the Handler.
///
/// @warning Given strategy does not follow MDP policy
/// on exposing order books and thus can be used on own risk!
/// Also, books may not be in a valid state (especially consolidated),
/// as far as exposed earlier than data for entire market event
/// is processed.
OnSecurityChange,
/// Book update event is raised at the end of market event.
///
/// Direct books updates are raised at the end of real
/// quotes updates, implied books updates are raised at
/// the end of implied quotes updates and consolidated
/// books updates are raised at the end of entire event.
OnEndOfEvent
};
/// Returns strategy of given string presentation.
static Enum deserialize(const char*);
/// Returns string presentation.
static const char* toString(Enum);
};
/// Alias for book notification strategy.
typedef
BookUpdateNotificationStrategies::Enum
BookUpdateNotificationStrategy;
/// Defines Order Id processing strategies.
struct
ONIXS_CME_MDP3_API
OrderIdProcessingStrategies
{
enum Enum
{
/// No matching between trades and Order IDs performed. Message
/// Order IDs array delivered entirely to callback.
/// @see void OrderIdListener::onOrderIds(const MessageOrderIds&, const ChannelId&)
NoMatching,
/// Trades are matched with corresponding Order IDs. Order IDs
/// delivered to callback by associated trade.
/// @see void OrderIdListener::onOrderIds(const TradeOrderIds&, const ChannelId&)
TradeMatching
};
/// Returns strategy of given string presentation.
static Enum deserialize(const char*);
/// Returns string representation of constant.
static const char* toString(Enum);
};
/// Alias for Order Id processing strategy.
typedef
OrderIdProcessingStrategies::Enum
OrderIdProcessingStrategy;
/// Handler's configuration settings.
struct
ONIXS_CME_MDP3_API
HandlerSettings
: InitializationSettings
, TcpRecoverySettings
, FeedEngineSettings
{
/// ID of the CME FIX/SBE market data channel
/// from the channels configuration XML file.
const std::string& channelId() const
{
return *channelId_;
}
/// Sets channelId. @see channelId.
void channelId(const std::string& value)
{
*channelId_ = value;
}
/// Path to the channels configuration XML file.
const std::string& channelsConfigurationFile() const
{
return *channelsConfigurationFile_;
}
/// Sets channelsConfigurationFile. @see channelsConfigurationFile.
void channelsConfigurationFile(const std::string& value)
{
*channelsConfigurationFile_ = value;
}
/// Path to CME SBE templates xml file.
const std::string& codingTemplatesFile() const
{
return *codingTemplatesFile_;
}
/// Sets codingTemplatesFile. @see codingTemplatesFile.
void codingTemplatesFile(const std::string& value)
{
*codingTemplatesFile_ = value;
}
/// Option to use file-based caching of the security definitions.
///
/// @note The default value is 'false'.
///
/// @warning If this option is activated then it is recommended
/// to remove the cache file weekly to start the trading week
/// with the fresh copy of security definitions.
///
bool cacheSecurityDefinitions() const
{
return cacheSecurityDefinitions_;
}
/// Sets cacheSecurityDefinitions. @see cacheSecurityDefinitions.
void cacheSecurityDefinitions(bool value)
{
cacheSecurityDefinitions_ = value;
}
/// Option to recover the Security Definition messages
/// each time when the message sequence gap is detected.
///
/// During the trading day new instruments can be defined,
/// and these security definitions are sent over the Incremental
/// A and B feeds.
/// Therefore it is possible to miss new intra-day security definition
/// messages, so it could be required to listen to the instrument feed
/// again on a message gap.
///
/// On the other hand, this could significantly increase the time of
/// re-synchronization with the market after the detected message gap.
///
/// @note The default value is false.
///
bool recoverSecurityDefinitionsOnGap() const
{
return recoverSecurityDefinitionsOnGap_;
}
/// Sets recoverSecurityDefinitionsOnGap. @see recoverSecurityDefinitionsOnGap.
void recoverSecurityDefinitionsOnGap(bool value)
{
recoverSecurityDefinitionsOnGap_ = value;
}
/// Defines depth of direct order book for the instrument whose
/// definition wasn't received or had no corresponding data.
///
/// @note Default value is 10.
unsigned int directBookDepth() const
{
return directBookDepth_;
}
/// Sets directBookDepth. @see directBookDepth.
void directBookDepth(unsigned int value)
{
directBookDepth_ = value;
}
/// Defines depth of implied order book for the instrument whose
/// definition wasn't received or had no corresponding data.
///
/// @note Default value is 2.
unsigned int impliedBookDepth() const
{
return impliedBookDepth_;
}
/// Sets impliedBookDepth. @see impliedBookDepth.
void impliedBookDepth(unsigned int value)
{
impliedBookDepth_ = value;
}
/// Specifies whether the Handler should log its events
/// and which of events should be put into the log.
///
/// @note The default value is LogModes::Regular.
LogMode logMode() const
{
return logMode_;
}
/// Sets logMode. @see logMode.
void logMode(LogMode value)
{
logMode_ = value;
}
/// Additional options to control which data is to be logged.
/// Ignored if logging is disabled.
///
/// @note The default value is AdvancedLogOptions::LogEverything.
AdvancedLogOptionSet advancedLogOptions() const
{
return advancedLogOptions_;
}
/// Sets advancedLogOptions. @see advancedLogOptions.
void advancedLogOptions(AdvancedLogOptionSet value)
{
advancedLogOptions_ = value;
}
/// Log files are stored in this directory.
/// Ignored if logging is disabled.
const std::string& logDirectory() const
{
return *logDirectory_;
}
/// Sets logDirectory. @see logDirectory.
void logDirectory(const std::string& value)
{
*logDirectory_ = value;
}
/// Log file name are started from the prefix.
/// Ignored if logging is disabled.
const std::string& logFileNamePrefix() const
{
return *logFileNamePrefix_;
}
/// Sets logFileNamePrefix. @see logFileNamePrefix.
void logFileNamePrefix(const std::string& value)
{
*logFileNamePrefix_ = value;
}
/// Log file size limit (in bytes).
///
/// Handler detaches logged data into separate
/// file upon reaching given size limit.
///
/// @note Default value is '2145386496'.
size_t logFileSizeLimit() const
{
return logFileSizeLimit_;
}
/// Sets logFileSizeLimit. @see logFileSizeLimit.
void logFileSizeLimit(size_t value)
{
logFileSizeLimit_ = value;
}
/// Specifies maximal time interval between two
/// network packets. If no data is received during
/// specified time frame, warning is reported and handler
/// starts failovering to secondary feed if possible.
///
/// Interval is measured in seconds.
///
/// @note The default value is '30'.
unsigned int heartbeatInterval() const
{
return heartbeatInterval_;
}
/// Sets heartbeatInterval. @see heartbeatInterval.
void heartbeatInterval(unsigned int value)
{
heartbeatInterval_ = value;
}
/// Defines feed layout for instrument feed group.
///
/// @note By default, feed A is used as primary
/// source for market data with failover to feed B.
RecoveryFeedLayout::Enum instrumentFeedLayout() const
{
return instrumentFeedLayout_;
}
/// Sets instrumentFeedLayout. @see instrumentFeedLayout.
void instrumentFeedLayout(RecoveryFeedLayout::Enum value)
{
instrumentFeedLayout_ = value;
}
/// Defines feed layout for snapshot feed group.
///
/// @note By default, feed A is used as primary
/// source for market data with failover to feed B.
RecoveryFeedLayout::Enum snapshotFeedLayout() const
{
return snapshotFeedLayout_;
}
/// Sets snapshotFeedLayout. @see snapshotFeedLayout.
void snapshotFeedLayout(RecoveryFeedLayout::Enum value)
{
snapshotFeedLayout_ = value;
}
/// Defines feed layout for incremental feed group.
///
/// @note By default, Handler arbitrates between feeds A and B.
RealtimeFeedLayout::Enum incrementalFeedLayout() const
{
return incrementalFeedLayout_;
}
/// Sets incrementalFeedLayout. @see incrementalFeedLayout.
void incrementalFeedLayout(RealtimeFeedLayout::Enum value)
{
incrementalFeedLayout_ = value;
}
/// Specifies one or more network interfaces to use while
/// joining the multicast group; use semi-colon delimited
/// list if more than one.
///
/// @note On Linux the network interface is specified
/// by its name, on Windows - by IP address.
///
/// @note If the value is empty or absent then the
/// default networking interface is used.
///
/// @see networkInterfaceA, networkInterfaceB.
const std::string& networkInterface() const
{
return *networkInterface_;
}
/// Sets networkInterface. @see networkInterface.
void networkInterface(const std::string& value)
{
*networkInterface_ = value;
}
/// Specifies one or more network interfaces to use for
/// "A" feeds while joining the multicast group; use
/// semi-colon delimited list if more than one.
///
/// @note On Linux the network interface is specified
/// by its name, on Windows - by IP address.
///
/// @note If the value is empty or absent then the
/// Settings::networkInterface value is used.
const std::string& networkInterfaceA() const
{
return *networkInterfaceA_;
}
/// Sets networkInterfaceA. @see networkInterfaceA.
void networkInterfaceA(const std::string& value)
{
*networkInterfaceA_ = value;
}
/// Specifies one or more network interfaces to use for "B"
/// feeds while joining the multicast group; use semi-colon
/// delimited list if more than one.
///
/// @note On Linux the network interface is specified by
/// its name, on Windows - by IP address.
///
/// @note If the value is empty or absent then the
/// Settings::networkInterface value is used.
const std::string& networkInterfaceB() const
{
return *networkInterfaceB_;
}
/// Sets networkInterfaceB. @see networkInterfaceB.
void networkInterfaceB(const std::string& value)
{
*networkInterfaceB_ = value;
}
/// Maximum number of packets to be hold in internal queues
/// used by the Handler while processing incoming market data.
///
/// Handler uses internal queues while processes incoming market data.
/// When Handler recovers order books from snapshots, given parameter
/// limits size of internal queue used by the Handler to keep packets
/// coming from incremental feeds. Upon reaching limit, newer packets
/// substitute older ones.
///
/// Also, if Handler configured to use shared feed engine with multiple threads,
/// given parameter also limits size of queue/buffer used by Handler to store
/// incoming packets received by Handler but not yet processed by main market
/// data processing loop. An important aspect is that single buffer/queue is
/// used to store packets comming from all feeds (A and B) within same multicast
/// group (incremental, snapshot, instrument). New packets are not pushed to queue
/// upon reaching buffer limit in this case.
///
/// @note The default value is 10000.
unsigned int packetQueueMaxSize() const
{
return packetQueueMaxSize_;
}
/// Sets packetQueueMaxSize. @see packetQueueMaxSize.
void packetQueueMaxSize(unsigned int value)
{
packetQueueMaxSize_ = value;
}
/// Max size for network packet transmitted by MDP.
///
/// @note Default value is '1420'.
unsigned int maxPacketSize() const
{
return maxPacketSize_;
}
/// Sets maxPacketSize. @see maxPacketSize.
void maxPacketSize(unsigned int value)
{
maxPacketSize_ = value;
}
/// Limits packet pool size.
///
/// To speed-up data processing, Handler may accumulate packets
/// for further reuse during data bursts to avoid slowdowns caused
/// by memory allocations. Given parameter defines maximal number
/// of packets allowed for storing in pool for further reuse.
///
/// @note Default value is '1000'.
unsigned int packetPoolMaxSize() const
{
return packetPoolMaxSize_;
}
/// Sets packetPoolMaxSize. @see packetPoolMaxSize.
void packetPoolMaxSize(unsigned int value)
{
packetPoolMaxSize_ = value;
}
/// Defines value of threshold used by Handler to differ
/// out-of-order packets from gaps.
///
/// Due to unreliable nature of multicast, packets transmitted by MDP
/// may be received in the order different to original. To differ the
/// case when Handler received out-of-order packets from the case when
/// some of packets were completely lost, Handler uses given parameter.
/// It defines size of interval for incoming packets starting from the
/// last received. Packet is considered as out-of-order if its sequence
/// number fits into interval [seqNumberOfLastReceivedPacket,
/// seqNumberOfLastReceivedPacket + outOfOrderPacketsMaxInterval].
/// In that case Handler waits for other packets to fulfill the incoming
/// sequence. If received packet has greater sequence number than
/// 'seqNumberOfLastReceivedPacket + outOfOrderPacketsMaxInterval',
/// then Handler makes a decision on packets lost and gap is reported.
///
/// @note When out-of-order packet is received, Handler makes a decision
/// on data loss if either waiting time is over or if newly received packet
/// has sequence number greater than 'seqNumberOfLastReceivedPacket +
/// outOfOrderPacketMaxInterval'.
///
/// @see 'lostPacketWaitTime' parameter for more information.
///
/// @note The default value is '3'.
unsigned int outOfOrderPacketMaxInterval() const
{
return outOfOrderPacketMaxInterval_;
}
/// Sets outOfOrderPacketMaxInterval. @see outOfOrderPacketMaxInterval.
void outOfOrderPacketMaxInterval(unsigned int value)
{
outOfOrderPacketMaxInterval_ = value;
}
/// Indicates for how long Handler should wait for
/// the packet before it's considered as totally lost.
///
/// Due to unreliable nature of multicast, data transmitted by MDP
/// may come in order other than original or be completely lost. When
/// Handler receives packet with sequence number greater than expected,
/// it considers received data as out-of-order. If for a certain time
/// interval Handler receives missing data, Handler resumes normal data
/// processing. However, if no data is received for predefined time frame,
/// Handler considers missing data as lost and raises packet gap event.
/// Given parameter defines size of time interval Handler waits for missing
/// data.
///
/// @note When out-of-order packet is received, Handler makes a decision
/// on data loss if either waiting time is over or if newly received packet
/// has sequence number greater than 'seqNumberOfLastReceivedPacket +
/// outOfOrderPacketMaxInterval'.
///
/// @see 'outOfOrderPacketMaxInterval' parameter for more information.
///
/// Time interval is measured in microseconds (usec).
///
/// @note The default value is '100000' (100 milliseconds).
unsigned int lostPacketWaitTime() const
{
return lostPacketWaitTime_;
}
/// Sets lostPacketWaitTime. @see lostPacketWaitTime.
void lostPacketWaitTime(unsigned int value)
{
lostPacketWaitTime_ = value;
}
/// Defines size of buffer in bytes for UDP/multicast sockets.
///
/// @note Default value is zero which means
/// system default setting will be used.
unsigned int udpSocketBufferSize() const
{
return udpSocketBufferSize_;
}
/// Sets udpSocketBufferSize. @see udpSocketBufferSize.
void udpSocketBufferSize(unsigned int value)
{
udpSocketBufferSize_ = value;
}
/// Maximum number of repeating group entries.
///
/// This setting could be used to detect mismatch between
/// the SBE template that was used for message encoding
/// and the SBE template that is used for message decoding.
///
/// @note The default value is 1000.
unsigned int repeatingGroupEntriesMaxCount() const
{
return repeatingGroupEntriesMaxCount_;
}
/// Sets repeatingGroupEntriesMaxCount. @see repeatingGroupEntriesMaxCount.
void repeatingGroupEntriesMaxCount(unsigned int value)
{
repeatingGroupEntriesMaxCount_ = value;
}
/// Indicates whether local or UTC time is used by the Handler
/// while assigning timestamps to log events and packets received.
/// @note Default value is 'false' thus local time is used.
bool useUniversalTime() const
{
return useUniversalTime_;
}
/// Sets useUniversalTime. @see useUniversalTime.
void useUniversalTime(bool value)
{
useUniversalTime_ = value;
}
/// Forces Handler to build direct order book.
///
/// Unless book update listener is registered or
/// best bid/ask is tracked, Handler doesn't construct
/// and thus doesn't maintain order book. If book isn't
/// maintained, snapshot retrieval is not possible.
///
/// @note Default value is 'false'.
bool forceDirectBookMaintenance() const
{
return forceDirectBookMaintenance_;
}
/// Sets forceDirectBookMaintenance. @see forceDirectBookMaintenance.
void forceDirectBookMaintenance(bool value)
{
forceDirectBookMaintenance_ = value;
}
/// Forces Handler to build implied order book.
///
/// Unless book update listener is registered or
/// best bid/ask is tracked, Handler doesn't construct
/// and thus doesn't maintain order book. If book isn't
/// maintained, snapshot retrieval is not possible.
///
/// @note Default value is 'false'.
bool forceImpliedBookMaintenance() const
{
return forceImpliedBookMaintenance_;
}
/// Sets forceImpliedBookMaintenance. @see forceImpliedBookMaintenance.
void forceImpliedBookMaintenance(bool value)
{
forceImpliedBookMaintenance_ = value;
}
/// Forces Handler to build consolidated order book.
///
/// Unless book update listener is registered or
/// best bid/ask is tracked, Handler doesn't construct
/// and thus doesn't maintain order book. If book isn't
/// maintained, snapshot retrieval is not possible.
///
/// @note Default value is 'false'.
bool forceConsolidatedBookMaintenance() const
{
return forceConsolidatedBookMaintenance_;
}
/// Sets forceConsolidatedBookMaintenance. @see forceConsolidatedBookMaintenance.
void forceConsolidatedBookMaintenance(bool value)
{
forceConsolidatedBookMaintenance_ = value;
}
/// Book update notification strategy.
///
/// Defines the way Handler raises order book update event.
///
/// @note Default strategy is BookUpdateNotificationStrategies::OnEndOfEvent.
BookUpdateNotificationStrategy bookUpdateNotificationStrategy() const
{
return bookUpdateNotificationStrategy_;
}
/// Sets bookUpdateNotificationStrategy. @see bookUpdateNotificationStrategy.
void bookUpdateNotificationStrategy(BookUpdateNotificationStrategy value)
{
bookUpdateNotificationStrategy_ = value;
}
/// Order IDs processing strategy.
///
/// Defines the way Handler processes Order IDs array.
///
/// @note Default strategy is OrderIdProcessingStrategies::NoMatching.
OrderIdProcessingStrategy orderIdProcessingStrategy() const
{
return orderIdProcessingStrategy_;
}
/// Sets orderIdProcessingStrategy. @see orderIdProcessingStrategy.
void orderIdProcessingStrategy(OrderIdProcessingStrategy value)
{
orderIdProcessingStrategy_ = value;
}
/// Initializes parameters with default values.
HandlerSettings();
/// Cleans everything up.
~HandlerSettings();
/// Returns textual presentation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Returns textual presentation.
void toString(std::string&) const;
private:
Exportable<std::string> channelId_;
Exportable<std::string> channelsConfigurationFile_;
Exportable<std::string> codingTemplatesFile_;
bool cacheSecurityDefinitions_;
bool recoverSecurityDefinitionsOnGap_;
unsigned int directBookDepth_;
unsigned int impliedBookDepth_;
LogMode logMode_;
AdvancedLogOptionSet advancedLogOptions_;
Exportable<std::string> logDirectory_;
Exportable<std::string> logFileNamePrefix_;
size_t logFileSizeLimit_;
unsigned int heartbeatInterval_;
RecoveryFeedLayout::Enum instrumentFeedLayout_;
RecoveryFeedLayout::Enum snapshotFeedLayout_;
RealtimeFeedLayout::Enum incrementalFeedLayout_;
Exportable<std::string> networkInterface_;
Exportable<std::string> networkInterfaceA_;
Exportable<std::string> networkInterfaceB_;
unsigned int packetQueueMaxSize_;
unsigned int maxPacketSize_;
unsigned int packetPoolMaxSize_;
unsigned int outOfOrderPacketMaxInterval_;
unsigned int lostPacketWaitTime_;
unsigned int udpSocketBufferSize_;
unsigned int repeatingGroupEntriesMaxCount_;
bool useUniversalTime_;
bool forceDirectBookMaintenance_;
bool forceImpliedBookMaintenance_;
bool forceConsolidatedBookMaintenance_;
BookUpdateNotificationStrategy bookUpdateNotificationStrategy_;
OrderIdProcessingStrategy orderIdProcessingStrategy_;
};
}
}
}