-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvisorMain.cpp
More file actions
695 lines (637 loc) · 25.6 KB
/
AdvisorMain.cpp
File metadata and controls
695 lines (637 loc) · 25.6 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
#include "AdvisorMain.h"
#include "OrderBookEntry.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include "CSVReader.h"
AdvisorMain::AdvisorMain()
{
}
void AdvisorMain::init()
{
std::string input;
currentTime = orderBook.getEarliestTime(); // user starts at the first timestamp in the dataset
printMenu();
// infinite loop to keep app running, awaiting the user's input
while (true)
{
input = getUserOption();
processUserOption(input);
}
}
void AdvisorMain::printMenu()
{ // prints introduction to the advisorbot when the program first initializes
std::cout << "Welcome to AdvisorBot. AdvisorBot is a command line program that can carry out various" << std::endl;
std::cout << "tasks to help a cryptocurrency investor analyse the data available on an exchange." << std::endl;
std::cout << "======================================================================================" << std::endl;
std::cout << "To begin, please enter a command, or type 'help' for a list of commands" << std::endl;
}
void AdvisorMain::printHelp(std::string userOption)
{ // print help function, when prints all available commands, and also prints each command's use and purpose
if (userOption == "help")
{
std::cout << "The available commands are: help, help <cmd>, prod, min, max, avg, predict, liquidity, time, step <no>" << std::endl;
std::cout << "======================================================================================================" << std::endl;
}
else if (userOption == "help prod")
{
std::cout << "Command: prod" << std::endl;
std::cout << "Purpose: List all available products." << std::endl;
std::cout << "Example: user> help prod" << std::endl;
std::cout << " advisorbot> ETH/BTC, DOGE/BTC etc." << std::endl;
}
else if (userOption == "help min")
{
std::cout << "Command: min product bid/ask" << std::endl;
std::cout << "Purpose: Find the minimum bid or ask for product in current time step" << std::endl;
std::cout << "Example: user> min ETH/BTC ask" << std::endl;
std::cout << " advisorbot> The min ask for ETH/BTC is 0.0248261" << std::endl;
}
else if (userOption == "help max")
{
std::cout << "Command: max product bid/ask" << std::endl;
std::cout << "Purpose: Find the maximum bid or ask for product in current time step" << std::endl;
std::cout << "Example: user> max ETH/BTC ask" << std::endl;
std::cout << " advisorbot> The max ask for ETH/BTC is 0.0251581" << std::endl;
}
else if (userOption == "help avg")
{
std::cout << "Command: avg product ask/bid timesteps" << std::endl;
std::cout << "Purpose: Compute the average ask or bid for the sent product over the sent number of time steps" << std::endl;
std::cout << "Example: user> avg ETH/BTC ask 10" << std::endl;
std::cout << " advisorbot> The average ETH/BTC ask price over the last 10 timesteps was 0.0249612" << std::endl;
}
else if (userOption == "help predict")
{
std::cout << "Command: predict max/min product ask/bid" << std::endl;
std::cout << "Purpose: Predict the max or min ask or bid for the sent product for the next time step, requires user to be at minimum the 5th timestamp" << std::endl;
std::cout << "Example: user> predict max BTC/USDT bid" << std::endl;
std::cout << " advisorbot> The predicted max ask price for ETH/BTC is 0.0222814 for the next time frame" << std::endl;
}
else if (userOption == "help liquidity")
{
std::cout << "Command: liquidity product" << std::endl;
std::cout << "Purpose: Averages the liquidity of product for the past 10 timesteps, uses bid-ask spread as the measure" << std::endl;
std::cout << "Example: user> liquidity DOGE/BTC" << std::endl;
std::cout << " advisorbot> The average liquidity of DOGE/BTC for the previous 10 steps is 4.07%" << std::endl;
}
else if (userOption == "help time")
{
std::cout << "Command: time" << std::endl;
std::cout << "Purpose: State current time in dataset, i.e. which timeframe are we looking at" << std::endl;
std::cout << "Example: user> time" << std::endl;
std::cout << " advisorbot> Current time is 2020/03/17 17:01:24, timestamp: 5" << std::endl;
}
else if (userOption == "help step")
{
std::cout << "Command: step <no.>" << std::endl;
std::cout << "Purpose: Moves to the next specified amount of timesteps, defaults to 1" << std::endl;
std::cout << "Example: user> step" << std::endl;
std::cout << " advisorbot> Now at 2020/03/17 17:01:30" << std::endl;
}
else
{ // if none of the above was matched, returns invalid input statement and tells user to type help for all valid commands
std::cout << "Invalid input. Type 'help' to display all valid commands" << std::endl;
}
}
void AdvisorMain::printProducts()
{ // 'prod' command, prints out all available products in the dataset
bool first = true;
std::cout << "Known products: "
<< "";
for (std::string const &p : orderBook.getKnownProducts())
{ // Gets all known products from the orderbook using getKnownProducts function
if (!first)
{
std::cout << "," << p << ""; // separates the products with commas to be printed
}
else
{
std::cout << p << "";
first = false;
}
}
std::cout << std::endl;
}
void AdvisorMain::printMinMax(std::string userOption)
{ // Minimum / Maximum command which returns the min/max as/bid of the product the user has input
std::vector<std::string> userOptionLine = userOptionTokenise(userOption);
int valid = 0;
for (std::string const &p : orderBook.getKnownProducts())
{ // counts the number of products in the current timeframe to be used for validation
valid++;
};
if (userOptionLine.size() != 3)
{ // user input must be a line which can be separated into 3 individual strings
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else
{
std::string type = userOptionLine[2];
std::string product = userOptionLine[1];
if (product.rfind("DOGE", 0) == 0)
{ // Changing precision when printing DOGE products to show more accurately their value rather than scientific notations
std::cout.precision(10);
std::cout << std::fixed;
}
else
{ // If user is analysing other products, change back the precision to the default
std::cout.precision(-1);
std::cout << std::defaultfloat;
}
for (std::string const &p : orderBook.getKnownProducts())
{ // loops through the known products to match whichever product the user has input
if ((type == "bid" || type == "ask") && product == p)
{ // validates if their input contains bid/ask and also matches the product to their input
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime); // gets the order book entry depending on the bid/ask which the user input
if (userOptionLine[0] == "min")
{ // matches if the user wanted to search for min
std::cout << "The min " << type << " for " << product << " is " << OrderBook::getLowPrice(entries) << std::endl;
}
else if (userOptionLine[0] == "max")
{ // matches if the user wanted to search for max
std::cout << "The max " << type << " for " << product << " is " << OrderBook::getHighPrice(entries) << std::endl;
}
}
else
{
valid--; // How many ever products is in the timestamp, the for loop should match 1 out of x products and have valid equal to 1
}
}
if (valid != 1)
{ // If 1 line of data is not matched in the for loop, the input is not valid and prints wrong line input
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
}
}
void AdvisorMain::printAvg(std::string userOption)
{ // Average command. Averages the ask/bid of a product for the x past numbers of timesteps
std::vector<std::string> userOptionLine = userOptionTokenise(userOption);
// variables needed for the average function
int valid = 0;
for (std::string const &p : orderBook.getKnownProducts())
{ // counts the number of products in the current timeframe to be used for validation
valid++;
};
double avg = 0;
double sum = 0;
unsigned int timesteps; // How many past timesteps (including current) the user wants to average
unsigned int userTimeStamp; // Which timestamp the user is current at
bool first = true;
if (userOptionLine.size() != 4)
{ // user input must be a line which can be separated into 4 individual strings from a vector
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else
{
std::string type = userOptionLine[2];
std::string product = userOptionLine[1];
try
{
timesteps = std::stoi(userOptionLine[3]); // convert user's input from string to int
}
catch (const std::exception &e)
{
std::cout << "Please input a number for your timesteps" << std::endl;
timesteps = 0;
return; // If user inputs non int for timestep value, return without executing any more code
}
try
{
if (type != "ask" && type != "bid")
{ // validation to check if user inputed a valid type
std::cout << "Wrong line input, please check order of commands" << std::endl;
return;
}
}
catch (const std::exception &e)
{
//
}
if (product.rfind("DOGE", 0) == 0)
{ // Changing precision when printing DOGE products to show more accurately their value rather than scientific notations
std::cout.precision(10);
std::cout << std::fixed;
}
else
{ // If user is analysing other products, change back the precision to the default
std::cout.precision(-1);
std::cout << std::defaultfloat;
}
userTimeStamp = timeStepsTaken + 1; // timestepstaken is how many time steps the user taken which starts at 0, usertimestamp starts at 1
if (timesteps == userTimeStamp && timesteps > 1)
{ // if the user wants to analyse all the timestamps they have passed through, minus
timesteps--; // timesteps to go back by 1 so that they dont go 1 further back
}
if (timesteps > userTimeStamp)
{ // validation if the user inputs more timesteps to analyse than their current timestamp number
std::cout << "You entered a greater number of timesteps to your current timestamp, please enter a timestep equal or less than your timestamp" << std::endl;
return;
}
else if (timesteps == 0)
{
std::cout << "Please enter a number greater than 0" << std::endl;
return;
}
for (std::string const &p : orderBook.getKnownProducts())
{
if ((type == "bid" || type == "ask") && product == p && userOptionLine[0] == "avg" && userTimeStamp >= timesteps)
{
if (userTimeStamp == 1)
{ // If the user has not taken any timesteps; they are on the first time stamp, do not go back any timestamps
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getAvgPrice(entries);
}
else
{
for (int i = 0; i < timesteps; i++)
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getAvgPrice(entries); // sums the average price each loop for current time
gotoPrevTimeFrame(); // go back 1 timestamp
// For the last iteration of the loop, add to the sum of average prices but do no go back 1 timestamp
if (i == (timesteps - 1) && userTimeStamp == stoi(userOptionLine[3]))
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getAvgPrice(entries);
}
}
}
avg = sum / stoi(userOptionLine[3]); // the average past x timestamps is the sum of entries average divided by timesteps
std::cout << "The average " << product << " " << type << " price over the last " << stoi(userOptionLine[3]) << " timesteps was " << avg << std::endl;
}
else
{
valid--;
}
}
if (valid != 1)
{
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else
{
if (timesteps == 1)
{ // if user only wants to avg current timestamp values, moves user forward only 1 timestamp as above function they are sent back once
for (int i = 0; i < 1; i++)
{
if (userTimeStamp != 1)
{
gotoNextTimeFrame("return"); // returns the user to their original timestamp
}
}
}
else
{
// this for loop returns the user's time step to wherever they stepped to
for (int i = 0; i < timesteps; i++)
{
if (userTimeStamp != 1)
{ // if user has not taken any timesteps, they can only avg the first timestep
gotoNextTimeFrame("return");
}
}
}
}
// std::cout << "Current time stamp is " << currentTime << " Timestamp: " << timeStepsTaken + 1 << std::endl;
}
}
void AdvisorMain::printPredict(std::string userOption)
{ // Predict function uses 4 steps exponential moving average to predict the next min/max ask/bid for the product
std::vector<std::string> userOptionLine = userOptionTokenise(userOption);
// variables needed for the function
int valid = 0;
for (std::string const &p : orderBook.getKnownProducts())
{ // counts the number of products in the current timeframe to be used for validation
valid++;
};
double sum = 0;
double EMA, SMA, CurrentPrice;
unsigned int timesteps = 4; // Using 4 step moving average as predictor, EMA requires the SMA of the previous step
// predict max/min product ask/bid
// 0 1 2 3
// EMA = Current price * (2/5) + SMA of previous * (3/5)
if (userOptionLine.size() != 4)
{ // user input must be a line which can be separated into 4 individual strings
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else if (timeStepsTaken < 4)
{ // Function works by using past 5 timesteps data so can only use this command on the 5th timestamp onwards
std::cout << "Predict can only be used on the 5th timestamp onwards as it uses historical data" << std::endl;
}
else
{
std::string type = userOptionLine[3];
std::string product = userOptionLine[2];
std::string minmax = userOptionLine[1];
try
{ // validation for ask/bid and min/max if they are input in the correct order of commands
if (type != "ask" && type != "bid")
{
std::cout << "Wrong line input, please check order of commands" << std::endl;
return;
}
else if (minmax != "max" && minmax != "min")
{
std::cout << "Wrong line input, please check order of commands" << std::endl;
return;
}
}
catch (const std::exception &e)
{
//
}
if (product.rfind("DOGE", 0) == 0)
{ // Changing precision when printing DOGE products to show more accurately their value rather than scientific notations
std::cout.precision(10);
std::cout << std::fixed;
}
else
{ // If user is analysing other products, change back the precision to the default
std::cout.precision(-1);
std::cout << std::defaultfloat;
}
for (std::string const &p : orderBook.getKnownProducts())
{
if ((type == "ask" || type == "bid") && product == p)
{ // matches the product
for (int i = 0; i < timesteps; i++)
{
if (minmax == "min")
{ // matches if they user wants to analyse min
if (i == 0)
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
CurrentPrice = OrderBook::getLowPrice(entries);
}
else
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getLowPrice(entries);
}
gotoPrevTimeFrame();
if (i == 3)
{ // on i = 3 iteration, gotoPrevTimeFrame() has been executed 4 times, meaning the user has went back to the 5th time stamp
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getLowPrice(entries); // gets the value of the 5th step value as it is required for SMA,
}
}
else if (minmax == "max")
{ // matches if they user wants to analyse max
if (i == 0)
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
CurrentPrice = OrderBook::getHighPrice(entries);
}
else
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getHighPrice(entries);
}
gotoPrevTimeFrame();
if (i == 3)
{
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookEntry::stringToOrderBookType(type), p, currentTime);
sum += OrderBook::getHighPrice(entries);
}
}
}
SMA = sum / 4; // formula for Simple moving average, sum of 5th to 2nd timestamps divided by 4
EMA = CurrentPrice * (2.0 / 5.0) + SMA * (3.0 / 5.0); // formula for Exponential moving average, which uses the SMA of previous step and current step price
std::cout << "The " << minmax << " " << type << " for " << product << " might be " << EMA << " for the next timestep" << std::endl;
}
else
{
valid--;
}
}
if (valid != 1)
{
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else
{
// this for loop returns the user's time step to wherever they stepped to
for (int i = 0; i < 4; i++)
{
if (timeStepsTaken >= 4)
{ // Function will not execute if users have not taken more than 4 steps
gotoNextTimeFrame("return");
}
}
}
// std::cout << "Current time stamp is " << currentTime << " Timestamp: " << timeStepsTaken + 1 << std::endl;
}
}
void AdvisorMain::printLiquidity(std::string userOption)
{ // Liquidity function takes the product's average bid-ask spread of the 10 previous steps in %
std::vector<std::string> userOptionLine = userOptionTokenise(userOption);
// variables needed for liquidty function
int valid = 0;
for (std::string const &p : orderBook.getKnownProducts())
{ // counts the number of products in the current timeframe to be used for validation
valid++;
};
double sumOfLiquidity = 0;
double avgOfLiquidity = 0;
double BidAskSpread;
double liquidity;
unsigned int timesteps = 10; // Using 10 step average of liquidity%, as some day
// liquidity product
// 0 1
// Bid ask spread = min ask � max bid
// Liquidity % = (bid ask spread / lowest ask price)* 100
if (userOptionLine.size() != 2)
{ // user input must be a line which can be separated into 2 individual strings
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else if (timeStepsTaken < timesteps)
{ // User has to be on 11th timestamp onwards to use this function
std::cout << "Liquidity can only be used on the 11th timestamp onwards as it uses historical data" << std::endl;
}
else
{
std::string product = userOptionLine[1];
if (product.rfind("DOGE", 0) == 0)
{ // Changing precision when printing DOGE products to show more accurately their value rather than scientific notations
std::cout.precision(10);
std::cout << std::fixed;
}
else
{ // If user is analysing other products, change back the precision to the default
std::cout.precision(-1);
std::cout << std::defaultfloat;
}
for (std::string const &p : orderBook.getKnownProducts())
{
if (product == p)
{ // matches user's product input to the dataset's product
for (int i = 0; i < timesteps; i++)
{
std::vector<OrderBookEntry> askEntries = orderBook.getOrders(OrderBookType::ask, p, currentTime);
std::vector<OrderBookEntry> bidEntries = orderBook.getOrders(OrderBookType::bid, p, currentTime);
BidAskSpread = OrderBook::getLowPrice(askEntries) - OrderBook::getHighPrice(bidEntries);
liquidity = (BidAskSpread / OrderBook::getLowPrice(askEntries)) * 100;
sumOfLiquidity += liquidity;
gotoPrevTimeFrame();
if (i == timesteps - 1)
{ // on the last iteration of the loop, gets the value of the 10th day
std::vector<OrderBookEntry> askEntries = orderBook.getOrders(OrderBookType::ask, p, currentTime);
std::vector<OrderBookEntry> bidEntries = orderBook.getOrders(OrderBookType::bid, p, currentTime);
BidAskSpread = OrderBook::getLowPrice(askEntries) - OrderBook::getHighPrice(bidEntries);
liquidity = (BidAskSpread / OrderBook::getLowPrice(askEntries)) * 100;
sumOfLiquidity += liquidity;
}
}
avgOfLiquidity = sumOfLiquidity / timesteps; // Formula for average of liquidity for the last 10 days
std::cout << std::setprecision(2) << "The average liquidity of " << product << " for the previous 10 steps is " << avgOfLiquidity << "%" << std::endl;
}
else
{
valid--;
}
}
if (valid != 1)
{
std::cout << "Wrong line input, type 'help <cmd>' for a valid command input" << std::endl;
}
else
{
// this for loop returns the user's time step to wherever they stepped to
for (int i = 0; i < timesteps; i++)
{
if (timeStepsTaken >= timesteps)
{ // Function will not execute if users have not taken more than 10 steps
gotoNextTimeFrame("return");
}
}
}
// std::cout << "Current time stamp is " << currentTime << " Timestamp: " << timeStepsTaken + 1 << std::endl;
}
}
void AdvisorMain::gotoNextTimeFrame(std::string userOption)
{
std::string original = userOption;
std::vector<std::string> userOptionLine = userOptionTokenise(userOption);
signed int steps; // If unsigned int is used, user inputting negative number will crash the program
if (original == "step")
{ // 'step' defaults to advancing 1 time step
currentTime = orderBook.getNextTime(currentTime);
std::cout << "Now at " << currentTime << std::endl;
timeStepsTaken++; // adds 1 to the timestepstaken
}
else if (original == "return")
{ // used for returning to timestamp after calculating commands, will not add to timestepstaken
currentTime = orderBook.getNextTime(currentTime);
// std::cout << "Now at " << currentTime << std::endl;
}
else if (userOptionLine.size() == 2)
{ // 'step <no>' users can type how many steps they want to advance, and for loop will advance x numbers of step
try
{
steps = std::stoi(userOptionLine[1]);
if (!(steps <= 0))
{
for (int i = 0; i < steps; i++)
{
currentTime = orderBook.getNextTime(currentTime);
if (i == steps - 1)
{
std::cout << "Now at " << currentTime << std::endl;
}
timeStepsTaken++;
}
}
else
{
std::cout << "Please enter a step greater than 0" << std::endl;
}
}
catch (const std::exception &e)
{ // validation
std::cout << "Invalid input. Type 'help' to display all valid commands" << std::endl;
}
}
else
{ // validation
std::cout << "Invalid input. Type 'help' to display all valid commands" << std::endl;
}
}
void AdvisorMain::gotoPrevTimeFrame() // Function to send user back 1 time step, for the different commands to get past timesteps data for calculation
{
currentTime = orderBook.getPrevTime(currentTime);
}
std::string AdvisorMain::getUserOption()
{ // Takes the user's input using cin and returns a string line
std::string userOption;
std::string line;
std::getline(std::cin, line);
try
{
userOption = std::string(line);
}
catch (const std::exception &e)
{
}
return userOption;
}
std::vector<std::string> AdvisorMain::userOptionTokenise(std::string userOption)
{ // tokenise user's input into a vector
std::vector<std::string> userOptionLine;
signed int start, end;
std::string token;
start = userOption.find_first_not_of(" ", 0);
do
{
end = userOption.find_first_of(" ", start);
if (start == userOption.length() || start == end)
break;
if (end >= 0)
token = userOption.substr(start, end - start);
else
token = userOption.substr(start, userOption.length() - start);
userOptionLine.push_back(token);
start = end + 1;
} while (end > 0);
return userOptionLine;
}
void AdvisorMain::processUserOption(std::string userOption)
{ // Processes the user's input and uses rfind to match which command the user has input
if (userOption.rfind("help", 0) == 0)
{
printHelp(userOption);
}
else if (userOption == "prod") // Displays all products
{
printProducts();
}
else if (userOption.rfind("min", 0) == 0 || userOption.rfind("max", 0) == 0) // Displays min/max ask/bid for product
{
printMinMax(userOption);
}
else if (userOption.rfind("avg", 0) == 0) // Displays avg ask/bid for product
{
printAvg(userOption);
}
else if (userOption.rfind("predict", 0) == 0) // Displays prediction for max/min product ask/bid using weighted moving avg
{
printPredict(userOption);
}
else if (userOption == "time") // Displays current time frame
{
std::cout << "Current time is " << currentTime << " Timestamp: " << timeStepsTaken + 1 << std::endl;
}
else if (userOption.rfind("step", 0) == 0) // Progresses to the next time frame
{
gotoNextTimeFrame(userOption);
}
else if (userOption.rfind("liquidity", 0) == 0)
{
printLiquidity(userOption);
}
else // If none of the valid commands are typed, invalid input and prompts user to type help
{
std::cout << "Invalid input. Type 'help' to display all valid commands" << std::endl;
}
}