| | |
| | | std::ostream& operator<<(std::ostream& out, const Level& a) |
| | | { |
| | | return out << "Price: " << a.price << ", volume: " << a.volume |
| | | << ", time: " << a.timestamp << ", id: " << a.id; |
| | | << ", time: " << a.timestamp << ", id: " << a.id; |
| | | } |
| | | |
| | | Book::Book() |
| | |
| | | double pasFee, double broFee) |
| | | : bidSide{}, askSide{}, productType{productType}, product(product), |
| | | stationId(stationId), unit(unit), expiry(expiry), aggFee(aggFee), |
| | | pasFee(pasFee), broFee(broFee) |
| | | pasFee(pasFee), broFee(broFee), bomPrice(0) |
| | | { |
| | | } |
| | | |
| | | void Book::ask(Order& order) |
| | | { |
| | | auto a = |
| | | this->askSide.emplace(order.id, order); |
| | | if (!a.second) { |
| | | std::cout << order.id << "already exists" << std::endl; |
| | | } |
| | | Level a(order); |
| | | auto b = std::lower_bound(this->askSide.begin(), this->askSide.end(), a); |
| | | this->askSide.insert(b, a); |
| | | } |
| | | |
| | | void Book::bid(Order& order) |
| | | { |
| | | auto a = |
| | | this->bidSide.emplace(order.id, order); |
| | | if (!a.second) { |
| | | std::cout << order.id << "already exists" << std::endl; |
| | | } |
| | | Level a(order); |
| | | auto b = std::upper_bound(this->bidSide.begin(), this->bidSide.end(), a); |
| | | this->bidSide.insert(b, a); |
| | | } |
| | | |
| | | void Book::printBook(std::size_t numOrders) |
| | | { |
| | | std::cout << "Sell side: " << this->askSide.size() << std::endl; |
| | | std::vector<Level> askCopy; |
| | | for (auto i : this->askSide) askCopy.push_back(i.second); |
| | | std::size_t count = 0; |
| | | std::sort(askCopy.begin(), askCopy.end()); |
| | | for (auto i = askCopy.rbegin(); i != askCopy.rend(); i++) { |
| | | std::size_t count = 0; |
| | | for (auto i = this->askSide.rbegin(); i != this->askSide.rend(); i++) { |
| | | std::cout << *i << std::endl; |
| | | count++; |
| | | if (count > numOrders) break; |
| | | } |
| | | std::cout << "Buy side: " << this->bidSide.size() << std::endl; |
| | | std::vector<Level> bidCopy; |
| | | for (auto i : this->bidSide) bidCopy.push_back(i.second); |
| | | count = 0; |
| | | std::sort(bidCopy.begin(), bidCopy.end()); |
| | | for (auto i = bidCopy.rbegin(); i != bidCopy.rend(); i++) { |
| | | for (auto i = this->bidSide.rbegin(); i != bidSide.rend(); i++) { |
| | | std::cout << *i << std::endl; |
| | | count++; |
| | | if (count > numOrders) break; |