Files

194 lines
4.0 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/Decimal.h>
#include <OnixS/CME/MDH/Composites.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Type for order identification.
typedef UInt64 OrderId;
/// Type for order priority.
typedef UInt64 OrderPriority;
/// Presents display quantity.
typedef Int32 DisplayQuantity;
/// Some basic traits for the order.
ONIXS_CMEMDH_LTWT_STRUCT
OrderTraits
{
/// Returns null order id.
static OrderId nullId()
{
return 18446744073709551615ul;
}
/// Returns null order priority.
static OrderPriority nullPriority()
{
return 18446744073709551615ul;
}
/// Returns mantissa of the null price.
static Int64 nullPriceMantissa()
{
return 9223372036854775807l;
}
/// Returns mantissa of the null price.
static
bool
nullPrice(
const Decimal& price)
{
return (
price.mantissa() ==
nullPriceMantissa()
);
}
/// Returns null display quantity.
static DisplayQuantity nullQuantity()
{
return 2147483647;
}
};
/// Order as the member of the Market By Order (MBO) book.
ONIXS_CMEMDH_LTWT_CLASS Order
{
protected:
OrderId id_;
OrderPriority priority_;
Decimal price_;
DisplayQuantity quantity_;
public:
/// Initializes blank/null instance.
Order()
: id_(
OrderTraits::nullId())
, priority_(
OrderTraits::nullPriority())
, price_(
OrderTraits::nullPriceMantissa(),
0)
, quantity_(
OrderTraits::nullQuantity())
{
}
/// Initializes instance according to given values.
Order(
OrderId id,
OrderPriority priority,
const Decimal& price,
DisplayQuantity quantity)
: id_(id)
, priority_(priority)
, price_(price)
, quantity_(quantity)
{
}
/// Order identifier.
OrderId id() const
{
return id_;
}
/// Updates order identifier.
void
id(
OrderId id)
{
id_ = id;
}
/// Order priority.
OrderPriority priority() const
{
return priority_;
}
/// Updates order priority.
void
priority(
OrderPriority priority)
{
priority_ = priority;
}
/// Order price.
const Decimal& price() const
{
return price_;
}
/// Updates order price.
void
price(
const Decimal& price)
{
price_ = price;
}
/// Display quantity.
DisplayQuantity quantity() const
{
return quantity_;
}
/// Updates display quantity.
void
quantity(
DisplayQuantity quantity)
{
quantity_ = quantity;
}
};
/// Appends representation of order to given string.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
const Order&);
/// Returns string representation of the order.
inline
std::string
toStr(
const Order& order)
{
std::string str;
toStr(str, order);
return str;
}
ONIXS_CMEMDH_NAMESPACE_END