-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderBook.cpp
More file actions
37 lines (35 loc) · 910 Bytes
/
Copy pathOrderBook.cpp
File metadata and controls
37 lines (35 loc) · 910 Bytes
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
enum class Side {Bid, Ask};
using orderId = uint64_t;
using Volume = int64_t;
void ModifyOrder(uint_64_t orderId, Volume newVolume);
void
AddOrder(uint64_t orderId, Side side, Price price, Volume volume)
{
...
auto [it, inserted] = mOrders.emplace(orderID,...);
EXPECT(inserted,"duplicate order");
...
}
void
DeleteOrder(uint64_t orderId)
{
auto it = mOrders.find(orderId);
EXPECT(it != mOrders.end(), "missing order");
}
std::Map<Price,Volume, std::greater<Price>> mbidLevels;
std::Map<Price,Volume, std::less<Price>> maskLevels;
template <class T>
typename T::iterator AddOrder(T& levels, Price price, Volume volume)
{
auto [it,inserted] = levels.try_emplace(price,volume);
if (inserted==false)
it->second +=volume;
return it;
}
template <class T>
void DeleteOrder(typename T::iterator, T&levels, Price price, Volume volume)
{
it->second -= volume;
if (it->second <= 0)
levels.erase(it);
}