-
Notifications
You must be signed in to change notification settings - Fork 0
/
Order.cpp
129 lines (106 loc) · 4.24 KB
/
Order.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "Order.h"
const char Order::orderNew = 'N';
const char Order::orderModify = 'M';
const char Order::orderCancel = 'X';
const char Order::orderTypeBuy = 'B';
const char Order::orderTypeSell = 'S';
const size_t Order::orderSymbolLength = 12;
Order::Order()
{
}
// Default Constructor parameterized.
Order::Order(const long& orderSequenceId, const long& orderId, const char& orderSide, const char& orderType, const double& orderPrice, const long& orderSize, const std::string& orderSymbolName) : m_orderSequenceId(orderSequenceId), m_orderId(orderId), m_orderSide(orderSide), m_orderType(orderType), m_orderPrice(orderPrice), m_orderSize(orderSize), m_orderSymbolName(orderSymbolName)
{
}
// Copy constructor.
Order::Order(const Order& copyRef)
{
this->m_orderSequenceId = copyRef.m_orderSequenceId;
this->m_orderId = copyRef.m_orderId;
this->m_orderSide = copyRef.m_orderSide;
this->m_orderSize = copyRef.m_orderSize;
this->m_orderType = copyRef.m_orderType;
this->m_orderPrice = copyRef.m_orderPrice;
this->m_orderSymbolName = copyRef.m_orderSymbolName;
}
// Assignment operator constructor.
Order& Order::operator=(const Order& assignRef)
{
this->m_orderSequenceId = assignRef.m_orderSequenceId;
this->m_orderId = assignRef.m_orderId;
this->m_orderSide = assignRef.m_orderSide;
this->m_orderSize = assignRef.m_orderSize;
this->m_orderType = assignRef.m_orderType;
this->m_orderPrice = assignRef.m_orderPrice;
this->m_orderSymbolName = assignRef.m_orderSymbolName;
return(*this);
}
Order::Order(Order&& moveRef)
{
this->m_orderSequenceId = moveRef.m_orderSequenceId;
this->m_orderId = moveRef.m_orderId;
this->m_orderSide = moveRef.m_orderSide;
this->m_orderSize = moveRef.m_orderSize;
this->m_orderType = moveRef.m_orderType;
this->m_orderPrice = moveRef.m_orderPrice;
this->m_orderSymbolName = std::move(moveRef.m_orderSymbolName);
moveRef.m_orderSymbolName = "";
}
Order& Order::operator=(Order&& moveRef)
{
this->m_orderSequenceId = moveRef.m_orderSequenceId;
this->m_orderId = moveRef.m_orderId;
this->m_orderSide = moveRef.m_orderSide;
this->m_orderSize = moveRef.m_orderSize;
this->m_orderType = moveRef.m_orderType;
this->m_orderPrice = moveRef.m_orderPrice;
this->m_orderSymbolName = std::move(moveRef.m_orderSymbolName);
moveRef.m_orderSymbolName = "";
return(*this);
}
// All getters are below.
long Order::getOrderSequenceId() const { return(m_orderSequenceId); }
long Order::getOrderId() const { return(m_orderId); }
char Order::getOrderSide() const { return(m_orderSide); }
char Order::getOrderType() const { return(m_orderType); }
double Order::getOrderPrice() const { return(m_orderPrice); }
long Order::getOrderSize() const { return(m_orderSize); }
std::string Order::getOrderSymbolName() const { return(m_orderSymbolName); }
// Implementation of sorting criteria for the Order.
bool operator < (const Order& lhs, const Order& rhs)
{
// First priority is given to cancel orders to move ahead.
if(lhs.getOrderType() == Order::orderCancel && rhs.getOrderType() != Order::orderCancel)
return(true);
if(rhs.getOrderType() == Order::orderCancel && lhs.getOrderType() != Order::orderCancel)
return(false);
// If both are cancels then seqId / arrival timestamp gets priority.
// If both are not cancel then queue as per seqId.
// The check is also not required if both are cancel types or not cancel types. Because above code would catch all other case types.
if(lhs.getOrderSequenceId() < rhs.getOrderSequenceId())
return(true);
else
return(false);
}
std::string Order::getOrderMessage() const
{
// Order Layout.
// seqId, orderType, orderId, orderSide, orderQty, orderPrice, orderSymbol
// A,100001,B,1000,101.50,SINTEXSYMBOL
std::string returnMessage = "orderSequenceId = ";
returnMessage += std::to_string(m_orderSequenceId);
returnMessage += ", orderType = ";
returnMessage += m_orderType;
returnMessage += ", orderId = ";
returnMessage += std::to_string(m_orderId);
returnMessage += ", orderSide = ";
std::string str(1,m_orderSide);
returnMessage += str;
returnMessage += ", orderQty = ";
returnMessage += std::to_string(m_orderSize);
returnMessage += ", orderPrice = ";
returnMessage += std::to_string(m_orderPrice);
returnMessage += ", orderSymbol = ";
returnMessage += m_orderSymbolName;
return(returnMessage);
}