-
Notifications
You must be signed in to change notification settings - Fork 0
/
order-book.cc
110 lines (86 loc) · 2.13 KB
/
order-book.cc
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
#include <iostream>
#include <list>
#include <set>
#include <map>
#include <stdlib.h>
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
class Order;
class Limit;
typedef int OrderId;
typedef int LimitPrice;
enum BuyOrSell { buy, sell };
class Order {
public:
Order(BuyOrSell, int, LimitPrice, int, int);
private:
OrderId idNumber;
BuyOrSell buyOrSell;
int shares;
LimitPrice limit;
int entryTime;
int eventTime;
Limit* parentLimit;
};
class Limit {
public:
Limit(LimitPrice);
private:
LimitPrice limitPrice;
int totalVolume;
std::list<Order> orders;
};
class OrderBook {
public:
OrderBook();
bool Add(Order);
bool Cancel(OrderId);
bool Execute(OrderId);
int GetVolumeAtLimit(LimitPrice, BuyOrSell) const;
LimitPrice GetBestBid(BuyOrSell) const;
private:
std::set<Limit> buy;
std::set<Limit> sell;
Limit* lowestSell;
Limit* highestBuy;
std::map<LimitPrice, Limit> limitBuyMap;
std::map<LimitPrice, Limit> limitSellMap;
std::map<OrderId, Order> orderMap;
};
Order::Order(BuyOrSell operation, int shareCount, LimitPrice price, int entry, int event) {
buyOrSell = operation;
shares = shareCount;
limit = price;
entryTime = entry;
eventTime = event;
parentLimit = nullptr;
idNumber = rand();
}
Limit::Limit(LimitPrice price) {
limitPrice = price;
totalVolume = 0;
}
OrderBook::OrderBook()
: lowestSell(nullptr), highestBuy(nullptr) {}
bool OrderBook::Add(Order order) {
std::map<LimitPrice, Limit> map;
if (order.buyOrSell == BuyOrSell::buy) {
map = this->limitBuyMap;
}
}
bool OrderBook::Cancel(OrderId id) {
}
bool OrderBook::Execute(OrderId id) {
}
int OrderBook::GetVolumeAtLimit(LimitPrice limit, BuyOrSell action) const {
std::map<LimitPrice, Limit> map;
if (action == BuyOrSell::buy) {
map = this->limitBuyMap;
} else {
map = this->limitSellMap;
}
}
LimitPrice OrderBook::GetBestBid(BuyOrSell) const {
}