Update used the new stringsToOBE to parse user input

This commit is contained in:
Lev
2021-06-11 14:00:10 -05:00
parent f00082fdac
commit eb61d51464
2 changed files with 28 additions and 22 deletions

View File

@ -7,15 +7,13 @@
MerkelMain::MerkelMain()
{
}
void MerkelMain::init()
{
int input;
currentTime = orderBook.getEarliestTime();
while(true)
while (true)
{
printMenu();
input = getUserOption();
@ -31,11 +29,11 @@ void MerkelMain::printMenu()
std::cout << "2: Print exchange stats" << std::endl;
// 3 make an offer
std::cout << "3: Make an ask " << std::endl;
// 4 make a bid
// 4 make a bid
std::cout << "4: Make a bid " << std::endl;
// 5 print wallet
std::cout << "5: Print wallet " << std::endl;
// 6 continue
// 6 continue
std::cout << "6: Continue " << std::endl;
std::cout << "============== " << std::endl;
std::cout << "Current time is " << currentTime << std::endl;
@ -48,13 +46,13 @@ void MerkelMain::printHelp()
void MerkelMain::printMarketStats()
{
for(std::string const p : orderBook.getKnownProducts())
for (std::string const p : orderBook.getKnownProducts())
{
std::cout << "Product: " << p << std::endl;
std::cout << "Product: " << p << std::endl;
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookType::ask, p, currentTime);
std::cout << "Asks for product " << p << " are " << entries.size() << std::endl;
std::cout << "Max ask for " << p << " is " << orderBook.getHighPrice(entries) << std::endl;
std::cout << "Min ask for " << p << " is " << orderBook.getLowPrice(entries) << std::endl;
std::cout << "Max ask for " << p << " is " << orderBook.getHighPrice(entries) << std::endl;
std::cout << "Min ask for " << p << " is " << orderBook.getLowPrice(entries) << std::endl;
}
// std::cout << "OrderBook contains : " << orders.size() << " entries" << std::endl;
// unsigned int bids = 0;
@ -68,8 +66,8 @@ void MerkelMain::printMarketStats()
// if (e.orderType == OrderBookType::bid)
// {
// bids ++;
// }
// }
// }
// }
// std::cout << "OrderBook asks: " << asks << " bids:" << bids << std::endl;
}
@ -78,7 +76,16 @@ void MerkelMain::enterAsk()
std::cout << "Make an ask - enter the amount (product, price, amount. e.g. 'ETH/BTC, 200, 0.5)': " << std::endl;
std::string input;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::getline(std::cin, input);
std::getline(std::cin, input);
std::vector<std::string> tokens = CSVReader::tokenise(input, ',');
if(tokens.size() != 3)
{
std::cout << "Bad input!" << input << std::endl;
}
else
{
OrderBookEntry obe = CSVReader::stringsToOBE(tokens[1], tokens[2], currentTime, tokens[0], OrderBookType::ask);
}
std::cout << "You typed: " << input << std::endl;
}
@ -91,13 +98,13 @@ void MerkelMain::printWallet()
{
std::cout << "Your wallet is empty. " << std::endl;
}
void MerkelMain::gotoNextTimeframe()
{
std::cout << "Going to next time frame. " << std::endl;
currentTime = orderBook.getNextTime(currentTime);
}
int MerkelMain::getUserOption()
{
int userOption;
@ -114,29 +121,28 @@ void MerkelMain::processUserOption(int userOption)
{
std::cout << "Invalid choice. Choose 1-6" << std::endl;
}
if (userOption == 1)
if (userOption == 1)
{
printHelp();
}
if (userOption == 2)
if (userOption == 2)
{
printMarketStats();
}
if (userOption == 3)
if (userOption == 3)
{
enterAsk();
}
if (userOption == 4)
if (userOption == 4)
{
enterBid();
}
if (userOption == 5)
if (userOption == 5)
{
printWallet();
}
if (userOption == 6)
if (userOption == 6)
{
gotoNextTimeframe();
}
}
}