-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathExchangeRules.h
More file actions
69 lines (57 loc) · 1.87 KB
/
Copy pathExchangeRules.h
File metadata and controls
69 lines (57 loc) · 1.87 KB
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
#pragma once
#include "Types.h"
// Exchange trading rules
struct ExchangeRules {
Price tickSize = 1; // min price incr (in cents)
Quantity lotSize = 1; // min quantity incr (e.g., 1 share)
Quantity minQuantity = 1; // min order size
Quantity maxQuantity = 1000000; // max order size
Price minNotional = 0; // min order value (price * quantity)
bool IsValidPrice(Price price) const {
if (price <= 0) return false;
return price % tickSize == 0;
}
bool IsValidQuantity(Quantity quantity) const {
if (quantity < minQuantity || quantity > maxQuantity) return false;
return quantity % lotSize == 0;
}
bool IsValidNotional(Price price, Quantity quantity) const {
int64_t notional = static_cast<int64_t>(price) * static_cast<int64_t>(quantity);
return notional >= minNotional;
}
bool IsValidOrder(Price price, Quantity quantity) const {
return IsValidPrice(price) &&
IsValidQuantity(quantity) &&
IsValidNotional(price, quantity);
}
Price RoundToTick(Price price) const {
if (tickSize <= 1) return price;
return (price / tickSize) * tickSize;
}
Quantity RoundToLot(Quantity quantity) const {
if (lotSize <= 1) return quantity;
return (quantity / lotSize) * lotSize;
}
};
enum class RejectReason {
None,
InvalidPrice,
InvalidQuantity,
BelowMinQuantity,
AboveMaxQuantity,
BelowMinNotional,
DuplicateOrderId,
InvalidOrderType,
EmptyBook
};
// Structure to hold order validation result
struct OrderValidation {
bool isValid = true;
RejectReason reason = RejectReason::None;
static OrderValidation Accept() {
return OrderValidation{true, RejectReason::None};
}
static OrderValidation Reject(RejectReason reason) {
return OrderValidation{false, reason};
}
};