Update included all implementations for version 0.1

This commit is contained in:
Lev
2021-07-05 21:27:45 -05:00
parent 86fc0d8f78
commit 827b5419b8
9 changed files with 530 additions and 125 deletions

View File

@ -86,6 +86,11 @@ std::string OrderBook::getNextTime(std::string timestamp)
{
next_timestamp = orders[0].timestamp;
}
// break the loop by comparing the argument timestamp with the timestamp found
if (timestamp > next_timestamp)
{
return "END";
}
return next_timestamp;
}
@ -95,6 +100,26 @@ void OrderBook::insertOrder(OrderBookEntry &order)
std::sort(orders.begin(), orders.end(), OrderBookEntry::compareByTimestamp);
}
// Remove order from the order book
void OrderBook::removeOrder(OrderBookEntry &order)
{
for(int i=0; i<orders.size(); ++i)
{
if (orders[i].username == order.username &&
orders[i].timestamp == order.timestamp &&
orders[i].orderType == order.orderType &&
orders[i].product == order.product &&
orders[i].price == order.price &&
orders[i].amount == order.amount
)
{
orders.erase(orders.begin() + i);
--i;
}
}
return;
}
std::vector<OrderBookEntry> OrderBook::matchAsksToBids(std::string product, std::string timestamp)
{
// asks = orderbook.asks
@ -201,4 +226,4 @@ std::vector<OrderBookEntry> OrderBook::matchAsksToBids(std::string product, std:
}
}
return sales;
}
}