-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
127 lines (111 loc) · 3.32 KB
/
main.cpp
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
/******************************************************************************
C++ Compiler. C++ 14
Ariel Silahian
How technology and automation can help to improve Execution Quality in FX
Creating a simple FX Aggregator
*******************************************************************************/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class price_level{
public:
double price;
double size;
};
class lob{
public:
double get_best_offer(){
return 0;
}
double get_best_bid(){
return 0;
}
void AddNewLevel(price_level& pl, bool is_bid){
if (is_bid){
bids.push_back(pl);
std::sort(bids.begin(), bids.end(), [](auto const& l, auto const& r)
{ return l.price > r.price; } ); //DESCENDING
}
else{
offers.push_back(pl);
std::sort(offers.begin(), offers.end(), [](auto const& l, auto const& r)
{ return l.price < r.price; } ); //ASCENDING
}
}
void DeleteLevel(double price, bool is_bid){
if (is_bid){
bids.erase(
std::remove_if(bids.begin(), bids.end(), [&](auto const & l) {
return l.price == price;
}),
bids.end());
}
else{
offers.erase(
std::remove_if(offers.begin(), offers.end(), [&](auto const & l) {
return l.price == price;
}),
offers.end());
}
}
void UpdateLevel(price_level& pl, bool is_bid){
vector<price_level>::iterator it;
if (is_bid){
it = std::find_if(bids.begin(), bids.end(),
[&](auto const &l) {return l.price == pl.price;});
}
else{
it = std::find_if(offers.begin(), offers.end(),
[&](auto const &l) {return l.price == pl.price;});
}
if (it != bids.end())
{
it->price = pl.price;
it->size = pl.size;
}
}
private:
vector<price_level> bids;
vector<price_level> offers;
};
class aggregated_lob{
public:
//METHODS TO HANDLE INDIVIDUAL BOOK METHODS
void AddNewLevel(int venue_id, price_level& pl, bool is_bid){
all_books[venue_id].AddNewLevel(pl, is_bid);
}
void DeleteLevel(int venue_id, double price, bool is_bid){
all_books[venue_id].DeleteLevel(price, is_bid);
}
void UpdateLevel(int venue_id, price_level& pl, bool is_bid){
all_books[venue_id].UpdateLevel(pl, is_bid);
}
double get_best_offer(){
double best_offer;
for (const lob& b: all_books){
if (best_offer == 0)
best_offer = b.get_best_offer();
else
best_offer = min(best_offer, b.get_best_offer());
}
return best_offer;
}
double get_best_bid(){
double best_bid;
for (const lob& b: all_books){
if (best_bid == 0)
best_bid = b.get_best_bid();
else
best_bid = max(best_bid, b.get_best_bid());
}
return best_bid;
}
private:
vector<lob> all_books;
};
int main()
{
cout<<"Hello World";
return 0;
}