-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.h
139 lines (115 loc) · 2.4 KB
/
Order.h
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
129
130
131
132
133
134
135
136
137
138
139
#pragma once
#include <iostream>
#include <string>
/**
* This file has Side, Date and Time, and Order classes.
*/
struct Side
{
enum Enum
{
Buy,
Sell
};
};
class DateTime
{
public:
DateTime() { }
DateTime(int year, int month, int day, int hour, int minute, int second)
: year(year), month(month), day(day), hour(hour), minute(minute), second(second)
{
}
bool operator<(const DateTime& other) const
{
if (year < other.year)
return true;
if (year > other.year)
return false;
if (month < other.month)
return true;
if (month > other.month)
return false;
if (day < other.day)
return true;
if (day > other.day)
return false;
if (hour < other.hour)
return true;
if (hour > other.hour)
return false;
if (minute < other.minute)
return true;
if (minute > other.minute)
return false;
if (second < other.second)
return true;
if (second > other.second)
return false;
return false;
}
private:
int year;
int month;
int day;
int hour;
int minute;
int second;
};
class Order
{
public:
Order() { }
Order(int orderId, DateTime timestamp, Side::Enum side, double price, int initialQuantity, std::string client)
{
orderId_ = orderId;
timestamp_ = timestamp;
side_ = side;
price_ = price;
quantity_ = initialQuantity;
client_ = client;
}
int getOrderId() const
{
return orderId_;
}
DateTime getTimestamp() const
{
return timestamp_;
}
Side::Enum getSide() const
{
return side_;
}
double getPrice() const
{
return price_;
}
int getQuantity() const
{
return quantity_;
}
std::string getClient() const
{
return client_;
}
bool isFilled() const
{
return quantity_ == 0;
}
void Fill(int quantity)
{
if(quantity > quantity_)
{
throw std::runtime_error("Not enough quantity in order");
}
quantity_ -= quantity;
}
private:
int orderId_;
DateTime timestamp_;
Side::Enum side_;
double price_;
int quantity_;
std::string client_;
};