CppTrader 1.0.5.0
C++ Trader
Loading...
Searching...
No Matches
order.cpp
Go to the documentation of this file.
1
10
11namespace CppTrader {
12namespace Matching {
13
14ErrorCode Order::Validate() const noexcept
15{
16 // Validate order Id
17 assert((Id > 0) && "Order Id must be greater than zero!");
18 if (Id == 0)
20
21 // Validate order quantity
22 assert((Quantity >= LeavesQuantity) && "Order quantity must be greater than or equal to order leaves quantity!");
25 assert((LeavesQuantity > 0) && "Order leaves quantity must be greater than zero!");
26 if (LeavesQuantity == 0)
28
29 // Validate market order
30 if (IsMarket())
31 {
32 assert((IsIOC() || IsFOK()) && "Market order must have 'Immediate-Or-Cancel' or 'Fill-Or-Kill' parameter!");
33 if (!IsIOC() && !IsFOK())
35 assert(!IsIceberg() && "Market order cannot be 'Iceberg'!");
36 if (IsIceberg())
38 }
39
40 // Validate limit order
41 if (IsLimit())
42 {
43 assert(!IsSlippage() && "Limit order cannot have slippage parameter!");
44 if (IsSlippage())
46 }
47
48 // Validate stop order
49 if (IsStop() || IsTrailingStop())
50 {
51 assert(!IsAON() && "Stop order cannot have 'All-Or-None' parameter!");
52 if (IsAON())
54 assert(!IsIceberg() && "Stop order cannot be 'Iceberg'!");
55 if (IsIceberg())
57 }
58
59 // Validate stop-limit order
61 {
62 assert(!IsSlippage() && "Stop-limit order cannot have slippage!");
63 if (IsSlippage())
65 }
66
67 // Validate trailing order
69 {
70 assert((TrailingDistance != 0) && "Trailing stop order must have non zero distance to the market!");
71 if (TrailingDistance == 0)
73
74 if (TrailingDistance > 0)
75 {
76 assert(((TrailingStep >= 0) && (TrailingStep < TrailingDistance)) && "Trailing step must be less than trailing distance!");
79 }
80 else
81 {
82 assert(((TrailingDistance <= -1) && (TrailingDistance >= -1000)) && "Trailing percentage distance must be in the range [0.01, 100%] (from -1 down to -10000)!");
83 if ((TrailingDistance > -1) || (TrailingDistance < -1000))
85 assert(((TrailingStep <= 0) && (TrailingStep > TrailingDistance)) && "Trailing step must be less than trailing distance!");
88 }
89 }
90
91 return ErrorCode::OK;
92}
93
94} // namespace Matching
95} // namespace CppTrader
ErrorCode
Error code.
Definition errors.h:21
C++ Trader project definitions.
Definition errors.h:16
Order definition.
bool IsFOK() const noexcept
Is the 'Fill-Or-Kill' order?
Definition order.h:240
ErrorCode Validate() const noexcept
Validate order parameters.
Definition order.cpp:14
bool IsIceberg() const noexcept
Is the 'Iceberg' order?
Definition order.h:247
bool IsStopLimit() const noexcept
Is the stop-limit order?
Definition order.h:224
bool IsAON() const noexcept
Is the 'All-Or-None' order?
Definition order.h:242
bool IsTrailingStop() const noexcept
Is the trailing stop order?
Definition order.h:226
int64_t TrailingStep
Order trailing step.
Definition order.h:198
bool IsSlippage() const noexcept
Is the order have slippage?
Definition order.h:250
uint64_t LeavesQuantity
Order leaves quantity.
Definition order.h:147
bool IsLimit() const noexcept
Is the limit order?
Definition order.h:220
bool IsMarket() const noexcept
Is the market order?
Definition order.h:218
int64_t TrailingDistance
Order trailing distance to market.
Definition order.h:189
uint64_t Id
Order Id.
Definition order.h:130
bool IsIOC() const noexcept
Is the 'Immediate-Or-Cancel' order?
Definition order.h:238
bool IsStop() const noexcept
Is the stop order?
Definition order.h:222
bool IsTrailingStopLimit() const noexcept
Is the trailing stop-limit order?
Definition order.h:228
uint64_t Quantity
Order quantity.
Definition order.h:143