-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.hpp
More file actions
52 lines (43 loc) · 1.74 KB
/
Order.hpp
File metadata and controls
52 lines (43 loc) · 1.74 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
#pragma once
#include <list>
#include <memory>
#include <stdexcept>
#include "Constants.hpp"
#include "OrderType.hpp"
#include "Side.hpp"
#include "Usings.hpp"
class Order {
public:
Order(OrderType orderType, OrderId orderId, Side side, Price price, Quantity quantity)
: orderType_{orderType}, orderId_{orderId}, side_{side}, price_{price}, initialQuantity_{quantity}, remainingQuantity_{quantity} {}
Order(OrderId orderId, Side side, Quantity quantity)
: Order(OrderType::Market, orderId, side, Constants::InvalidPrice, quantity) {}
OrderId GetOrderId() const { return orderId_; }
Side GetSide() const { return side_; }
Price GetPrice() const { return price_; }
OrderType GetOrderType() const { return orderType_; }
Quantity GetInitialQuantity() const { return initialQuantity_; }
Quantity GetRemainingQuantity() const { return remainingQuantity_; }
Quantity GetFilledQuantity() const { return GetInitialQuantity() - GetRemainingQuantity(); }
bool IsFilled() const { return GetRemainingQuantity() == 0; }
void Fill(Quantity quantity) {
if (quantity > GetRemainingQuantity())
throw std::logic_error("Order (" + std::to_string(GetOrderId()) + ") cannot be filled for more than its remaining quantity.");
remainingQuantity_ -= quantity;
}
void ToGoodTillCancel(Price price) {
if (GetOrderType() != OrderType::Market)
throw std::logic_error("Order (" + std::to_string(GetOrderId()) + ") cannot have its price adjusted, only market orders can.");
price_ = price;
orderType_ = OrderType::GoodTillCancel;
}
private:
OrderType orderType_;
OrderId orderId_;
Side side_;
Price price_;
Quantity initialQuantity_;
Quantity remainingQuantity_;
};
using OrderPointer = std::shared_ptr<Order>;
using OrderPointers = std::list<OrderPointer>;