-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvisorBot.cpp
More file actions
189 lines (160 loc) · 6.15 KB
/
AdvisorBot.cpp
File metadata and controls
189 lines (160 loc) · 6.15 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "AdvisorBot.h"
#include "StringParser.h"
#include "Command.h"
#include <iostream>
#include <string>
#include <algorithm>
// Tell compiler to create default constructor
AdvisorBot::AdvisorBot() = default;
void AdvisorBot::init()
{
std::vector<std::string> input;
currentTime = orderBook.getLaterTime();
welcomePrompt();
while (true)
{
input = getUserOption();
handleUserOptions(orderBook, currentTime, input);
}
}
void AdvisorBot::welcomePrompt()
{
std::cout << "===============================================" << std::endl;
std::cout << " $$$$$***** Welcome to AdvisorBot *****$$$$$ " << std::endl;
std::cout << "==============================================="
<< "\n"
<< std::endl;
std::cout << "Usage:"
<< "\n"
<< std::endl;
std::cout << " advisorbot$ <info>"
<< std::endl;
std::cout << " user$ <cmd>"
<< "\n"
<< std::endl;
std::cout << "All commands:"
<< "\n"
<< std::endl;
std::cout << " help "
<< "list all available commands" << std::endl;
std::cout << " help <cmd> "
<< "output help for the specified <command>" << std::endl;
std::cout << " prod "
<< "list available products" << std::endl;
std::cout << " min <product> <order> "
<< "find minimum <order> for <product> in current time step" << std::endl;
std::cout << " max <product> <order> "
<< "find maximum <order> for <product> in current time step" << std::endl;
std::cout << " avg <product> <order> <timesteps> "
<< "compute average <order> for the sent <product> over the sent number of <timesteps>" << std::endl;
std::cout << " predict <max/min> <order> <product> "
<< "predict <max> or <min> and <order> for the sent <product> for the next time step" << std::endl;
std::cout << " time "
<< "state current time in dataset, i.e. which timeframe are we looking at" << std::endl;
std::cout << " step "
<< "move to next time step" << std::endl;
std::cout << " import <file> "
<< "update current csv <file> to be used as new dataset" << std::endl;
std::cout << "\n"
<< std::endl;
std::cout << "Inputs:"
<< "\n"
<< std::endl;
std::cout << " <product> "
<< "ETH/BTC, DOGE/BTC, BTC/USDT, ETH/USDT, DOGE/USDT" << std::endl;
std::cout << " <order> "
<< "bid, ask" << std::endl;
std::cout << " <timesteps> "
<< "integer (i.e. 50, 999)" << std::endl;
std::cout << " <file> "
<< "*.csv (timestep, product, order, price, amount)" << std::endl;
std::cout << "\n"
<< std::endl;
}
std::vector<std::string> AdvisorBot::getUserOption()
{
// User input
std::string userOption;
std::string line;
// Commands vector to be returned
std::vector<std::string> commands;
// Main menu prompt
std::cout << "advisorbot$ "
<< "Please enter a valid command, or enter help to list all available commands" << std::endl;
std::cout << "user$ ";
// Accept user input and test for correctness
std::getline(std::cin, line);
try
{
userOption = line;
std::cout << "advisorbot$ You entered: " << userOption << std::endl;
// Call command parser and return vector of strings
commands = StringParser::tokeniseCmds(userOption, ' ');
if (commands.size() < 1 || commands.size() > 4) // Incorrect input
{
std::cout << "Bad input, incorrect number of arguments" << std::endl;
throw std::exception{};
}
if (std::find(possibleCmds.begin(), possibleCmds.end(), commands[0]) != possibleCmds.end())
{
for (int i = 1; i < commands.size(); i++)
{
if (std::find(possibleArgs.begin(), possibleArgs.end(), commands[i]) != possibleArgs.end())
{
continue;
}
else
{
std::cout << "Bad input, incorrect arguments given" << std::endl;
throw std::exception{};
}
}
}
else
{
std::cout << "Bad input, incorrect command given" << std::endl;
throw std::exception{};
}
}
catch (const std::exception &e)
{
//
}
return commands;
}
void AdvisorBot::handleUserOptions(OrderBook orderBook, std::string currentTime, std::vector<std::string> userOption)
{
// Call different constructor methods based on size of input from user
if (userOption.size() == 1)
{
std::string cmd = userOption[0];
Command command(orderBook, currentTime, cmd);
command.invoke();
}
if (userOption.size() == 2)
{
std::string cmd = userOption[0];
std::string arg1 = userOption[1];
Command command(orderBook, currentTime, cmd, arg1);
command.invoke();
}
if (userOption.size() == 3)
{
std::string cmd = userOption[0];
std::string arg1 = userOption[1];
std::string order = userOption[2];
OrderBookType arg2 = OrderBookEntry::stringToOrderBookType(userOption[2]);
Command command(orderBook, currentTime, cmd, arg1, arg2, order);
command.invoke();
}
if (userOption.size() == 4)
{
std::string cmd = userOption[0];
std::string arg1 = userOption[1];
std::string order = userOption[2];
OrderBookType arg2 = OrderBookEntry::stringToOrderBookType(userOption[2]);
std::string arg3 = userOption[3];
Command command(orderBook, currentTime, cmd, arg1, arg2, order, arg3);
command.invoke();
}
}