Update OnixS cme handler to 4.3.0

This commit is contained in:
Eric Harding committed 2017-09-27 15:49:20 -04:00
1 parent 466db3141f
commit c29bf90d2c
1699 files changed
+98019 -147167

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@
#include <OnixS/CME/MDH/Memory.h>
#include <OnixS/CME/MDH/String.h>
#include <OnixS/CME/MDH/QuickSet.h>
#include <OnixS/CME/MDH/TinySet.h>
#include <OnixS/CME/MDH/Domain.h>
+4 -17
View File
@@ -457,33 +457,20 @@ template
typename Depth
>
class
VariableDepthBookManagement
AnyDepthBookManagement
: public BaseBookManagement
<
BboTracking
>
{
Depth initialCapacity_;
Depth reserved_;
public:
/// Initializes instance with default values.
VariableDepthBookManagement()
AnyDepthBookManagement()
: BaseBookManagement<BboTracking>()
, initialCapacity_(200)
{
}
/// Defines initial capacity of order book.
Depth initialCapacity() const
{
return initialCapacity_;
}
/// Defines initial capacity of order book.
void initialCapacity(Depth value)
{
initialCapacity_ = value;
}
};
/// Defines book update notification strategies.
@@ -540,7 +527,7 @@ ONIXS_CMEMDH_LTWT_CLASS BookManagement
public:
/// Management and tracking parameters for MBO books.
typedef
VariableDepthBookManagement
AnyDepthBookManagement
<
MboBboTracking,
SortedOrders::size_type
+2 -4
View File
@@ -20,11 +20,9 @@
#pragma once
#include <memory>
#include <OnixS/CME/MDH/String.h>
#include <OnixS/CME/MDH/Integral.h>
#include <OnixS/CME/MDH/QuickSet.h>
#include <OnixS/CME/MDH/TinySet.h>
#include <OnixS/CME/MDH/Time.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
@@ -38,7 +36,7 @@ ONIXS_CMEMDH_LTWT_CLASS ThreadAffinity
public:
/// Alias for collection of CPU indices.
typedef
QuickSet<CpuIndex>
TinySet<CpuIndex>
CpuIndices;
/// Initializes empty set.
+6 -6
View File
@@ -21,8 +21,8 @@
#pragma once
#include <OnixS/CME/MDH/Integral.h>
#include <OnixS/CME/MDH/QuickSet.h>
#include <OnixS/CME/MDH/Security.h>
#include <OnixS/CME/MDH/TinySet.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
@@ -35,25 +35,25 @@ public:
/// Collection of security ids specified
/// for given instrument selection.
typedef
QuickSet<SecurityId>
TinySet<SecurityId>
SecurityIds;
/// Collection of symbols specified
/// for given instrument selection.
typedef
QuickStrSet
TinyStrSet
Symbols;
/// Collection of security groups specified
/// for given instrument selection.
typedef
QuickStrSet
TinyStrSet
SecurityGroups;
/// Collection of assets specified
/// for given instrument selection.
typedef
QuickStrSet
TinyStrSet
Assets;
/// Initializes empty selection.
@@ -236,7 +236,7 @@ selected(
inline
bool
selected(
const QuickStrSet& selection,
const TinyStrSet& selection,
const StrRef& value)
{
return (
+7 -7
View File
@@ -88,7 +88,7 @@ public:
/// Listeners are to be associated before starting market data
/// processing - Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
registerListener(
HandlerListener& listener);
@@ -102,7 +102,7 @@ public:
/// Listeners are to be associated before starting market data
/// processing - Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
registerFeedListener(
FeedListener& listener);
@@ -116,7 +116,7 @@ public:
/// Listeners are to be associated before starting market data
/// processing - Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
registerMarketDataListener(
MarketDataListener& listener);
@@ -130,7 +130,7 @@ public:
/// Listeners are to be associated before starting market data
/// processing - Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
registerSecurityListener(
SecurityListener& listener);
@@ -139,7 +139,7 @@ public:
///
/// Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
bindFeedEngine(
FeedEngine& feedEngine);
@@ -148,7 +148,7 @@ public:
///
/// Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
bindTcpRecovery(
TcpRecoveryService& tcpRecovery);
@@ -157,7 +157,7 @@ public:
///
/// Handler must be in stopped state.
///
/// @throw Error in case when handler is not in configurable state.
/// @throw std::exception in case when handler is not in configurable state.
void
bindLogger(
Logger& logger);
@@ -31,6 +31,8 @@
#include <OnixS/CME/MDH/HandlerDebugLogging.h>
#include <OnixS/CME/MDH/MemoryPoolSettings.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Handler's configuration settings.
@@ -48,6 +50,8 @@ ONIXS_CMEMDH_LTWT_CLASS HandlerSettings
HandlerDebugLoggingSettings debugLogging_;
MemoryPoolSettings memoryPool_;
public:
/// Initializes parameters with default values.
HandlerSettings()
@@ -184,6 +188,23 @@ public:
{
return debugLogging_;
}
/// Parameters affecting behavior of memory pool
/// used by Handler while processing market data.
MemoryPoolSettings&
memoryPool()
{
return memoryPool_;
}
/// Parameters affecting behavior of memory pool
/// used by Handler while processing market data.
const
MemoryPoolSettings&
memoryPool() const
{
return memoryPool_;
}
};
/// Serializes BBA tracking parameters into string.
+91 -21
View File
@@ -25,8 +25,62 @@
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Private base for MBO book.
///
/// Manages internals related with
/// efficient order entry allocation.
ONIXS_CMEMDH_LTWT_CLASS
MboBookBase
{
MemoryPool& pool_;
const bool releasePool_;
protected:
/// Instantiates allocator using MemoryPool for orders.
typedef
MemoryPoolAllocator<Order>
OrderAllocator;
/// Initializes with privately maintained memory pool.
MboBookBase()
: pool_(
*makeMemoryPool
(
64,
1,
20,
1
)
)
, releasePool_(true)
{
}
/// Binds to given memory pool.
MboBookBase(
MemoryPool& sharedPool)
: pool_(sharedPool)
, releasePool_(false)
{
}
/// Releases memory pool according to policy.
~MboBookBase()
{
if (releasePool_)
pool_.release();
}
/// Allocator over memory pool.
OrderAllocator allocator() const
{
return OrderAllocator(pool_);
}
};
/// Market By Order book.
ONIXS_CMEMDH_LTWT_CLASS MboBook
ONIXS_CMEMDH_LTWT_CLASS
MboBook : MboBookBase
{
BookState::Enum state_;
@@ -37,34 +91,53 @@ public:
/// Order as book entry.
typedef Order Entry;
/// Sorted orders are book entries.
typedef SortedOrders Entries;
/// Book depth type.
typedef
SortedOrders::size_type
Depth;
/// Sorted orders are book entries.
typedef SortedOrders Entries;
/// Iterator over bids and offers.
typedef
Entries::const_iterator
EntryIterator;
/// Initializes blank order book.
MboBook()
: state_(
BookState::Constructed)
, bids_(
allocator())
, offers_(
allocator())
{
}
/// Initializes book using given memory pool.
MboBook(
Depth reserve = 0)
: state_(
BookState::Constructed)
MemoryPool& pool)
: MboBookBase(pool)
, state_(
BookState::Constructed)
, bids_(
allocator())
, offers_(
allocator())
{
if (0 < reserve)
{
bids_.reserve(reserve);
offers_.reserve(reserve);
}
}
/// Initializes as copy of other book.
MboBook(
const MboBook& other)
: state_(other.state())
, bids_(other.bids())
, offers_(other.offers())
: MboBookBase()
, state_(other.state())
, bids_(allocator())
, offers_(allocator())
{
bids_ = other.bids();
offers_ = other.offers();
}
/// Disposes allocated resources.
@@ -168,13 +241,10 @@ public:
{
if (this != &other)
{
SortedOrders bids(other.bids());
SortedOrders offers(other.offers());
std::swap(bids_, bids);
std::swap(offers_, offers);
state_ = other.state();
bids_ = other.bids();
offers_ = other.offers();
}
return *this;
+7 -2
View File
@@ -20,15 +20,20 @@
#pragma once
#include <vector>
#include <list>
#include <OnixS/CME/MDH/Order.h>
#include <OnixS/CME/MDH/MemoryPool.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Arranged collection of orders.
typedef
std::vector<Order>
std::list
<
Order,
MemoryPoolAllocator<Order>
>
SortedOrders;
ONIXS_CMEMDH_NAMESPACE_END
+6
View File
@@ -90,6 +90,12 @@ public:
>
Entries;
/// Iterator over bids and offers.
typedef
typename
Entries::ConstIterator
EntryIterator;
/// Initializes instance with given attributes.
///
/// Bids and offers are stored in given segments of
+274
View File
@@ -0,0 +1,274 @@
// 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
#if defined(ONIXS_CMEMDH_ENABLE_TRACING)
#include <ostream>
#endif
#include <cassert>
#include <OnixS/CME/MDH/Bootstrap.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Memory pool abstraction.
///
/// Defines interface for memory block
/// allocation and disposing.
ONIXS_CMEMDH_EXPORTED_CLASS MemoryPool
{
// Copies are disallowed.
MemoryPool(
const MemoryPool&)
{
}
// Assignment is disallowed.
MemoryPool&
operator =(
const MemoryPool&)
{
return *this;
}
protected:
/// Default initialization.
///
/// Instance construction is
/// assumed through descendants.
MemoryPool()
{
}
/// Destruction is through descendants.
virtual ~MemoryPool()
{
}
public:
/// Releases given instance.
virtual void release() = 0;
/// Allocates memory block of given size.
virtual void* allocate(size_t) = 0;
/// Releases previously allocated memory block.
virtual void deallocate(void*) = 0;
#if defined(ONIXS_CMEMDH_ENABLE_TRACING)
virtual void trace(std::ostream&) = 0;
#endif
};
// Implements STL allocator over MemoryPool.
template
<
class Object
>
class MemoryPoolAllocator
{
MemoryPool* pool_;
public:
typedef Object value_type;
typedef Object* pointer;
typedef const Object* const_pointer;
typedef Object& reference;
typedef const Object& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
template
<
class Other
>
struct rebind
{
typedef
MemoryPoolAllocator<Other>
other;
};
MemoryPoolAllocator()
: pool_(NULL)
{
}
MemoryPoolAllocator(
MemoryPool& memoryPool)
: pool_(&memoryPool)
{
}
MemoryPoolAllocator(
const MemoryPoolAllocator& other)
: pool_(other.pool_)
{
}
template
<
class Other
>
MemoryPoolAllocator(
const MemoryPoolAllocator<Other>& other)
: pool_(&other.memoryPool())
{
}
~MemoryPoolAllocator()
{
}
MemoryPool& memoryPool() const
{
return *pool_;
}
pointer
address(
reference obj) const
{
return &obj;
}
const_pointer
address(
const_reference x) const
{
return &x;
}
pointer
allocate(
size_type qty)
{
assert(NULL != pool_);
return static_cast<pointer>
(
pool_->allocate
(
qty * sizeof(value_type)
)
);
}
void
deallocate(
pointer block,
size_type)
{
assert(NULL != pool_);
pool_->deallocate(block);
}
void
construct(
pointer block,
const value_type& obj)
{
new (block) value_type(obj);
}
void
destroy(
pointer obj)
{
obj->~value_type();
}
size_type max_size() const
{
return
static_cast<size_type>(-1) /
sizeof(value_type);
}
MemoryPoolAllocator&
operator =(
const MemoryPoolAllocator& other)
{
pool_ = other.pool_;
return *this;
}
template
<
class Other
>
MemoryPoolAllocator&
operator =(
const MemoryPoolAllocator<Other>& other)
{
pool_ = &other.memoryPool();
return *this;
}
};
template
<
class Object,
class OtherObject
>
inline
bool
operator ==(
const MemoryPoolAllocator<Object>& left,
const MemoryPoolAllocator<OtherObject>& right)
{
return
(
&left.memoryPool() == &right.memoryPool()
);
}
template
<
class Object,
class OtherObject
>
inline
bool
operator !=(
const MemoryPoolAllocator<Object>& left,
const MemoryPoolAllocator<OtherObject>& right)
{
return
(
&left.memoryPool() != &right.memoryPool()
);
}
/// Constructs memory pool instance
/// according to given configuration.
ONIXS_CMEMDH_EXPORTED
MemoryPool*
makeMemoryPool(
size_t, size_t, size_t, size_t);
ONIXS_CMEMDH_NAMESPACE_END
@@ -0,0 +1,206 @@
// 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 <string>
#include <stdexcept>
#include <OnixS/CME/MDH/Bootstrap.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Raises exception on zero parameter value.
inline
void
throwZeroParameter(
const char* parameter)
{
std::string reason;
reason += "Non-zero value is expected for '";
reason += parameter ? parameter : "<unknown>";
reason += "' parameter. ";
throw std::out_of_range(reason);
}
/// Memory pool settings.
///
/// Control parameters affecting behavior of memory
/// pool used by Handler while processing market data.
ONIXS_CMEMDH_LTWT_CLASS MemoryPoolSettings
{
size_t blockIncrease_;
size_t increaseQty_;
size_t chunkSize_;
size_t chunkScaling_;
public:
/// Initializes parameters with default values.
MemoryPoolSettings()
: blockIncrease_(48)
, increaseQty_(32)
, chunkSize_(20)
, chunkScaling_(2)
{
}
/// Memory block increase value.
///
/// Memory pool allocates blocks divisible by given value.
size_t blockIncrease() const
{
return blockIncrease_;
}
/// Updates memory block increase value.
///
/// Memory pool allocates blocks divisible by given value.
void
blockIncrease(
size_t increase)
{
if (0 < increase)
{
blockIncrease_ = increase;
}
else
{
throwZeroParameter("blockIncrease");
}
}
/// Limits number of increases memory pool does.
///
/// Memory pool allocates blocks divisible by 'blockIncrease' value.
/// Efficient allocation is performed for blocks whose size doesn't
/// exceeds multiplication of 'blockIncrease' and 'increaseQty' values.
/// Other blocks are allocated upon request without caching.
size_t increaseQty() const
{
return increaseQty_;
}
/// Limits number of increases memory pool does.
///
/// Memory pool allocates blocks divisible by 'blockIncrease' value.
/// Efficient allocation is performed for blocks whose size doesn't
/// exceeds multiplication of 'blockIncrease' and 'increaseQty' values.
/// Other blocks are allocated upon request without caching.
void
increaseQty(
size_t qty)
{
if (0 < qty)
{
increaseQty_ = qty;
}
else
{
throwZeroParameter("increaseQty");
}
}
/// Number of blocks per chunk.
///
/// Memory pool allocates chunks of blocks thus reducing
/// number of actual allocations. Given parameter specifies
/// number of memory blocks of same size allocated at once
/// if pool is empty.
size_t chunkSize() const
{
return chunkSize_;
}
/// Number of blocks per chunk.
///
/// Memory pool allocates chunks of blocks thus reducing
/// number of actual allocations. Given parameter specifies
/// number of memory blocks of same size allocated at once
/// if pool is empty.
void
chunkSize(
size_t size)
{
if (0 < size)
{
chunkSize_ = size;
}
else
{
throwZeroParameter("chunkSize");
}
}
/// Defines chunk scale factor.
///
/// Each time memory pool allocates a new chunk
/// of blocks, its size is scaled by given factor.
size_t chunkScaling() const
{
return chunkScaling_;
}
/// Defines chunk scale factor.
///
/// Each time memory pool allocates a new chunk
/// of blocks, its size is scaled by given factor.
void
chunkScaling(
size_t factor)
{
if (0 < factor)
{
chunkScaling_ = factor;
}
else
{
throwZeroParameter("chunkScaling");
}
}
};
/// Serializes memory pool settings into a string.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
const
MemoryPoolSettings&);
/// Serializes memory pool settings into a string.
inline
std::string
toStr(
const
MemoryPoolSettings& settings)
{
std::string str;
toStr(str, settings);
return str;
}
ONIXS_CMEMDH_NAMESPACE_END
@@ -28,13 +28,13 @@
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Class implementing set over flat array (vector)
/// to speed-up manipulations over small-sized sets.
/// Class implementing set optimized
/// for storing small number of items.
template
<
class Key
>
class QuickSet
class TinySet
{
public:
/// Aliases set item type.
@@ -52,7 +52,7 @@ public:
ConstIterator;
/// Initializes empty set.
QuickSet()
TinySet()
{
}
@@ -60,21 +60,21 @@ public:
/// internal storage to be enough capacious
/// to store given number of items.
explicit
QuickSet(
TinySet(
size_t capacity)
{
reserve(capacity);
}
/// Initializes set as copy of other one.
QuickSet(
const QuickSet& other)
TinySet(
const TinySet& other)
: items_(other.items_)
{
}
/// Cleans everything up.
~QuickSet()
~TinySet()
{
}
@@ -177,7 +177,7 @@ public:
/// Swaps content with the other instance.
void
swap(
QuickSet& other)
TinySet& other)
{
std::swap(
items_,
@@ -185,13 +185,13 @@ public:
}
/// Re-initializes instance as copy of other instance.
QuickSet&
TinySet&
operator =(
const QuickSet& other)
const TinySet& other)
{
if (&other != this)
{
QuickSet copy(other);
TinySet copy(other);
swap(copy);
}
@@ -203,12 +203,9 @@ private:
Items items_;
};
/// Implements quick set for StrRef class.
/// In contrast to QuickSet<StrRef> instantiation,
/// given class stores content referred by StrRef
/// instances being inserted.
/// Implements iterator for TinyStrSet class.
ONIXS_CMEMDH_LTWT_CLASS
QuickStrSetIterator
TinyStrSetIterator
{
public:
/// Aliases internal representation.
@@ -222,27 +219,27 @@ public:
ItemIterator;
/// Initializes iterator pointing to nowhere.
QuickStrSetIterator()
TinyStrSetIterator()
{
}
/// Initializes instance as copy of the other one.
QuickStrSetIterator(
const QuickStrSetIterator& other)
TinyStrSetIterator(
const TinyStrSetIterator& other)
: iterator_(other.iterator_)
{
}
/// Initializes from iterator over internal store.
explicit
QuickStrSetIterator(
TinyStrSetIterator(
const ItemIterator& iterator)
: iterator_(iterator)
{
}
/// Cleans everything up.
~QuickStrSetIterator()
~TinyStrSetIterator()
{
}
@@ -257,7 +254,7 @@ public:
bool
operator ==(
const
QuickStrSetIterator& other) const
TinyStrSetIterator& other) const
{
return iterator_ == other.iterator_;
}
@@ -266,16 +263,16 @@ public:
bool
operator !=(
const
QuickStrSetIterator& other) const
TinyStrSetIterator& other) const
{
return iterator_ != other.iterator_;
}
/// Re-initializes as copy of the other instance.
QuickStrSetIterator&
TinyStrSetIterator&
operator =(
const
QuickStrSetIterator& other)
TinyStrSetIterator& other)
{
iterator_ = other.iterator_;
@@ -283,7 +280,7 @@ public:
}
/// Advances instance to the next item.
QuickStrSetIterator&
TinyStrSetIterator&
operator ++()
{
++iterator_;
@@ -295,11 +292,14 @@ private:
ItemIterator iterator_;
};
/// Quick set implementation for string references
/// (StrRef) which stores copies of strings being
/// referenced by StrRef instances.
/// Implements TinySet for StrRef class.
///
/// In contrast to TinySet<StrRef> instantiation,
/// given class allocates space for content being
/// referenced by StrRef instances inserted into
/// given set.
ONIXS_CMEMDH_LTWT_CLASS
QuickStrSet
TinyStrSet
{
public:
/// Items of collection.
@@ -307,32 +307,32 @@ public:
/// Aliases iterator type.
typedef
QuickStrSetIterator
TinyStrSetIterator
ConstIterator;
/// Initializes empty set.
QuickStrSet()
TinyStrSet()
{
}
/// Initializes empty set capacious
/// enough to store given number of items.
explicit
QuickStrSet(
TinyStrSet(
size_t capacity)
{
reserve(capacity);
}
/// Initializes as copy of other instance.
QuickStrSet(
const QuickStrSet& other)
TinyStrSet(
const TinyStrSet& other)
: items_(other.items_)
{
}
/// Performs clean-up.
~QuickStrSet()
~TinyStrSet()
{
}
@@ -441,11 +441,13 @@ public:
/// Exchanges content with the other instance.
void
swap(
QuickStrSet& other)
TinyStrSet& other)
{
std::swap(
std::swap
(
items_,
other.items_);
other.items_
);
}
private:
+30 -6
View File
@@ -125,6 +125,24 @@ public:
return (items_ + size_);
}
/// Provides access to the front item if available.
Item&
front()
{
assert(0 < size_);
return items_[0];
}
/// Provides access to the front item if available.
const Item&
front() const
{
assert(0 < size_);
return items_[0];
}
/// Accesses to item by index.
Item&
operator[](
@@ -154,8 +172,10 @@ public:
if (index < size_)
return items_[index];
throw std::runtime_error(
"Index outside of range.");
throw std::out_of_range
(
"Index outside of range."
);
}
/// Accesses to item by index
@@ -167,8 +187,10 @@ public:
if (index < size_)
return items_[index];
throw std::runtime_error(
"Index outside of range.");
throw std::out_of_range
(
"Index outside of range."
);
}
/// Inserts new item to given position.
@@ -316,9 +338,11 @@ copy(
if (itemCount > target.capacity())
{
throwVectorCopyOverflow(
throwVectorCopyOverflow
(
target.capacity(),
itemCount);
itemCount
);
}
target.resize(itemCount);