Update added the canFulfillOrder function

This commit is contained in:
Lev
2021-06-12 22:32:57 -05:00
parent ae736454ec
commit c0552cb3b7
4 changed files with 20 additions and 9 deletions

View File

@ -83,7 +83,16 @@ void MerkelMain::enterAsk()
tokens[0], tokens[0],
OrderBookType::ask OrderBookType::ask
); );
orderBook.insertOrder(obe); if(wallet.canFulfillOrder(obe))
{
std::cout << "Wallet looks good. " << std::endl;
orderBook.insertOrder(obe);
}
else
{
std::cout << "Wallet has insufficient asks" << std::endl;
}
}catch (const std::exception& e) }catch (const std::exception& e)
{ {
std::cout << " MerkelMain::enterAsk Bad input " << std::endl; std::cout << " MerkelMain::enterAsk Bad input " << std::endl;

View File

@ -1,5 +1,6 @@
#include "Wallet.h" #include "Wallet.h"
#include "CSVReader.h" #include "CSVReader.h"
#include <iostream>
Wallet::Wallet() Wallet::Wallet()
{ {
@ -78,6 +79,7 @@ bool Wallet::canFulfillOrder(OrderBookEntry order)
{ {
double amount = order.amount; double amount = order.amount;
std::string currency = currs[0]; std::string currency = currs[0];
std::cout << "Wallet::canFulfillrder " << currency << ":" <<amount << std::endl;
return containsCurrency(currency, amount); return containsCurrency(currency, amount);
} }
if(order.orderType == OrderBookType::bid) if(order.orderType == OrderBookType::bid)

View File

@ -8,15 +8,15 @@
int main() int main()
{ {
//MerkelMain app{}; MerkelMain app{};
//app.init(); app.init();
Wallet wallet; // Wallet wallet;
wallet.insertCurrency("BTC", 10); // wallet.insertCurrency("BTC", 10);
wallet.insertCurrency("USDT", 100.83); // wallet.insertCurrency("USDT", 100.83);
std::cout << wallet.toString() << std::endl; // std::cout << wallet.toString() << std::endl;
//std::cout << "Wallet has BTC " << wallet.containsCurrency("USDT", 100.50) << std::endl; //std::cout << "Wallet has BTC " << wallet.containsCurrency("USDT", 100.50) << std::endl;
wallet.removeCurrency("USDT", 10); // wallet.removeCurrency("USDT", 10);
std::cout << wallet.toString() << std::endl; // std::cout << wallet.toString() << std::endl;
//CSVReader::readCSV("20200317.csv"); //CSVReader::readCSV("20200317.csv");
} }