-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderCore.hpp
More file actions
83 lines (75 loc) · 1.75 KB
/
OrderCore.hpp
File metadata and controls
83 lines (75 loc) · 1.75 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <stdexcept>
#include <string>
class IOrderCore {
public:
virtual ~IOrderCore() = default;
virtual long getOrderId() const = 0;
virtual int getSecurityId() const = 0;
virtual const std::string &getUsername() const = 0;
};
class OrderCore : public IOrderCore {
public:
OrderCore(long orderId, int securityId, const std::string &username)
: orderId(orderId), securityId(securityId), username(username) {}
long getOrderId() const override {
return orderId;
}
int getSecurityId() const override {
return securityId;
}
const std::string &getUsername() const override {
return username;
}
private:
long orderId;
int securityId;
std::string username;
};
class Order : public IOrderCore {
public:
Order(OrderCore &&core, long price, uint quantity, bool isBuy)
: core(std::move(core)),
price(price),
initialQuantity(quantity),
currentQuantity(quantity),
isBuy(isBuy) {
orderId = core.getOrderId();
}
long getOrderId() const override {
return core.getOrderId();
}
int getSecurityId() const override {
return core.getSecurityId();
}
const std::string &getUsername() const override {
return core.getUsername();
}
long getPrice() const {
return price;
}
uint getInitialQuantity() const {
return initialQuantity;
}
uint getCurrentQuantity() const {
return currentQuantity;
}
bool isBuyOrder() const {
return isBuy;
}
void increaseQuantity(uint quantityDelta) {
currentQuantity += quantityDelta;
}
void decreaseQuantity(uint quantityDelta) {
if (quantityDelta > currentQuantity) {
throw std::out_of_range("Cannot decrease quantity below zero");
}
currentQuantity -= quantityDelta;
}
private:
OrderCore core;
long price;
uint initialQuantity;
uint currentQuantity;
bool isBuy;
};