Update completed implementation

This commit is contained in:
Lev
2021-06-13 13:46:04 -05:00
parent 7a913d8d4b
commit d74223f92a
6 changed files with 36 additions and 11 deletions

View File

@ -89,4 +89,30 @@ bool Wallet::canFulfillOrder(OrderBookEntry order)
return containsCurrency(currency, amount);
}
return false;
}
void Wallet::processSale(OrderBookEntry& sale)
{
std::vector<std::string> currs = CSVReader::tokenise(sale.product, '/');
// ask
if(sale.orderType == OrderBookType::asksale)
{
double outAmount = sale.amount;
std::string outCurrency = currs[0];
double incAmount = sale.amount * sale.price;
std::string incCurrency = currs[1];
currencies[incCurrency] += incAmount;
currencies[outCurrency] -= outAmount;
}
if(sale.orderType == OrderBookType::bidsale)
{
double incAmount = sale.amount;
std::string incCurrency = currs[0];
double outAmount = sale.amount * sale.price;
std::string outCurrency = currs[1];
currencies[incCurrency] += incAmount;
currencies[outCurrency] -= outAmount;
}
}