-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (55 loc) · 2.4 KB
/
main.cpp
File metadata and controls
78 lines (55 loc) · 2.4 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
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
#include<iostream>
#include<fstream>
#include "order.cpp"
#include "orderbook.cpp"
#include "helpers.hpp"
int main(int32_t argc, char* argv[])
{
std::fstream f;
if(f.is_open())
std::cout<<f.rdbuf()<<"\n";;
Orderbook obj;
while(true)
{
std::cout<<" OPTIONS \n ---------------------------------------------------------- \n";
std::cout<<" 1) Print Orderbook 2) Submit Orderbook 3) Exit\n ----------------------------------------------------------\n"<<"\n";
int32_t action; std::cout<<" "; std::cin>>action;
std::cout<<"\n";
if(action==1)
obj.print();
else if(action==2)
{
int32_t order_type_input, quantity, side_input;
double price;
std::cout<<" Enter the order type-"<<"\n";
std::cout<<" 1) Market order 2) Limit order"<<"\n";
std::cout<<" "; std::cin>>order_type_input;
OrderType order_type= static_cast<OrderType>(order_type_input);
std::cout<<" Enter the side \n";
std::cout<<" 1) Buy 2) Sell"<<"\n";
std::cout<<" "; std::cin>>side_input;
Side side= static_cast<Side>(side_input);
std::cout<<" Enter the quantity \n";
std::cout<<" "; std::cin>>quantity;
if(order_type==market)
{
std::cout<<" Submitting market "<<((side==buy)?"buy":"sell")<<" order for "<<quantity<<" units"<<"\n";
u_int64_t start_time= unix_time();
std::tuple<int32_t,double>fill= obj.execute_order(order_type, quantity, side);
u_int64_t end_time= unix_time();
std::cout<<" Filled "<<std::get<0>(fill)<<"/"<<quantity<<" units at $"<<std::get<1>(fill)/std::get<0>(fill)<<" Average price. Time taken: "<<(end_time-start_time)<<" nano seconds\033[0m"<<"\n";
}else if(order_type==limit)
{
std::cout<<" Enter price limit: \n";
std::cout<<" "; std::cin>>price;
std::cout<<" Submitting limit "<<((side==buy)?"buy":"sell")<<" order for "<<quantity<<" units "<<"and limit price being "<<price<<"\n";
u_int64_t start_time= unix_time();
std::tuple<int32_t,double>fill= obj.execute_order(order_type, quantity, side, price);
u_int64_t end_time= unix_time();
std::cout<<" Filled "<<std::get<0>(fill)<<"/"<<quantity<<" units at $"<<std::get<1>(fill)/std::get<0>(fill)<<" Average price. Time taken: "<<(end_time-start_time)<<" nano seconds\033[0m" <<"\n";
}
std::cout<<"\n";
}else if(action==3) break;
else std::cout<<" Enter the correct option \n\n";
}
}