From 2c515f0de70ad675b5f5d25b6a496d67d8dc0463 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Mon, 10 Jan 2022 02:48:19 +0000
Subject: [PATCH] Fixed indentation

---
 book.cpp |  226 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 117 insertions(+), 109 deletions(-)

diff --git a/book.cpp b/book.cpp
index 381a7a2..4473e8c 100644
--- a/book.cpp
+++ b/book.cpp
@@ -8,167 +8,175 @@
 {
 Order::Order(double price, OrderSideEnum side, int volume, double timestamp,
              std::string id)
-    : price{price}, side{side}, remaining_volume{volume},
-      filled_volume(0), timestamp{timestamp}, id{id}
+	: price{price}, side{side}, remaining_volume{volume},
+	  filled_volume(0), timestamp{timestamp}, id{id}
 {
 }
 
 Level::Level(Order& order)
-    : price{order.price}, volume(order.remaining_volume), side{order.side},
-      timestamp{order.timestamp}, id{order.id}
+	: price{order.price}, volume(order.remaining_volume), side{order.side},
+	  timestamp{order.timestamp}, id{order.id}
 {
 }
 
 bool operator<(const Level& a, const Level& b)
 {
-    if (a.price < b.price)
-	return true;
-    else if (a.price == b.price && (a.timestamp > b.timestamp))
-	return true;
-    else
-	return false;
+	if (a.price < b.price)
+		return true;
+	else if (a.price == b.price && (a.timestamp > b.timestamp))
+		return true;
+	else
+		return false;
 }
 
 bool operator>(const Level& a, const Level& b)
 {
-    if (a.price > b.price)
-	return true;
-    else if (a.price == b.price && (a.timestamp > b.timestamp))
-	return true;
-    else
-	return false;
+	if (a.price > b.price)
+		return true;
+	else if (a.price == b.price && (a.timestamp > b.timestamp))
+		return true;
+	else
+		return false;
 }
 
 bool operator<=(const Level& a, const Level& b)
 {
-    if (a.price <= b.price)
-	return true;
-    else if (a.price == b.price && (a.timestamp >= b.timestamp))
-	return true;
-    else
-	return false;
+	if (a.price <= b.price)
+		return true;
+	else if (a.price == b.price && (a.timestamp >= b.timestamp))
+		return true;
+	else
+		return false;
 }
 
 bool operator>=(const Level& a, const Level& b)
 {
-    if (a.price >= b.price)
-	return true;
-    else if (a.price == b.price && (a.timestamp >= b.timestamp))
-	return true;
-    else
-	return false;
+	if (a.price >= b.price)
+		return true;
+	else if (a.price == b.price && (a.timestamp >= b.timestamp))
+		return true;
+	else
+		return false;
 }
 
 bool operator==(const Level& a, const Level& b)
 {
-    if (a.price == b.price && (a.timestamp == b.timestamp))
-	return true;
-    else
-	return false;
+	if (a.price == b.price && (a.timestamp == b.timestamp))
+		return true;
+	else
+		return false;
 }
 
 std::ostream& operator<<(std::ostream& out, const Level& a)
 {
-    return out << "Price: " << a.price << ", volume: " << a.volume
-               << ", time: " << a.timestamp << ", id: " << a.id;
+	return out << "Price: " << a.price << ", volume: " << a.volume
+	           << ", time: " << a.timestamp << ", id: " << a.id;
 }
 
 Book::Book()
-    : bidSide(), askSide(), productType(TEST), product("a"), stationId(7),
-      unit("c"), expiry(std::chrono::nanoseconds(0)), aggFee(1), pasFee(-1),
-      broFee(2)
+	: bidSide(), askSide(), productType(TEST), product("a"), stationId(7),
+	  unit("c"), expiry(std::chrono::nanoseconds(0)), aggFee(1), pasFee(-1),
+	  broFee(2)
 {
 }
 
-Book::Book(ProductTypeEnum productType, std::string product,
-           int stationId, std::string unit,
-           std::chrono::nanoseconds expiry, double aggFee, double pasFee,
-           double broFee)
-    : bidSide{}, askSide{}, productType{productType}, product(product),
-      stationId(stationId), unit(unit), expiry(expiry), aggFee(aggFee),
-      pasFee(pasFee), broFee(broFee)
+Book::Book(ProductTypeEnum productType, std::string product, int stationId,
+           std::string unit, std::chrono::nanoseconds expiry, double aggFee,
+           double pasFee, double broFee)
+	: bidSide{}, askSide{}, productType{productType}, product(product),
+	  stationId(stationId), unit(unit), expiry(expiry), aggFee(aggFee),
+	  pasFee(pasFee), broFee(broFee)
 {
 }
 
 void Book::ask(Order& order)
 {
-    while (this->bidSide.size() && this->bidSide[0].price >= order.price) {
-	if (this->bidSide[0].volume > order.remaining_volume) {
-	    int temp = this->bidSide[0].volume;
-	    order.filled_volume += temp;
-	    this->bidSide.front().volume -= order.remaining_volume;
-	    order.remaining_volume -= temp;
-	    break;
-	} else {
-	    order.remaining_volume -= this->bidSide[0].volume;
-	    order.filled_volume += this->bidSide[0].volume;
-	    this->bidSide.erase(this->bidSide.begin());
-	    std::make_heap(this->bidSide.begin(), this->bidSide.end(),
-	                   std::less<Level>());
+	while (this->bidSide.size() && this->bidSide[0].price >= order.price) {
+		if (this->bidSide[0].volume > order.remaining_volume) {
+			int temp = this->bidSide[0].volume;
+			order.filled_volume += temp;
+			this->bidSide.front().volume -= order.remaining_volume;
+			order.remaining_volume -= temp;
+			break;
+		} else {
+			order.remaining_volume -= this->bidSide[0].volume;
+			order.filled_volume += this->bidSide[0].volume;
+			this->bidSide.erase(this->bidSide.begin());
+			std::make_heap(this->bidSide.begin(), this->bidSide.end(),
+			               std::less<Level>());
+		}
 	}
-    }
-    if (order.remaining_volume > 0) {
-	this->askSide.emplace(this->askSide.begin(), order);
-	std::make_heap(this->askSide.begin(), this->askSide.end(),
-	               std::greater<Level>());
-    }
+	if (order.remaining_volume > 0) {
+		this->askSide.emplace_back(order);
+		std::make_heap(this->askSide.begin(), this->askSide.end(),
+		               std::greater<Level>());
+	}
 }
 
 void Book::bid(Order& order)
 {
-    while (this->askSide.size() && this->askSide[0].price <= order.price) {
-	if (this->askSide[0].volume > order.remaining_volume) {
-	    int temp = this->askSide.front().volume;
-	    order.filled_volume += temp;
-	    this->askSide.front().volume -= order.remaining_volume;
-	    order.remaining_volume -= temp;
-	    break;
-	} else {
-	    order.remaining_volume -= this->askSide[0].volume;
-	    order.filled_volume += this->askSide[0].volume;
-	    this->askSide.erase(this->askSide.begin());
-	    std::make_heap(this->askSide.begin(), this->askSide.end(),
-	                   std::greater<Level>());
+	while (this->askSide.size() && this->askSide[0].price <= order.price) {
+		if (this->askSide[0].volume > order.remaining_volume) {
+			int temp = this->askSide.front().volume;
+			order.filled_volume += temp;
+			this->askSide.front().volume -= order.remaining_volume;
+			order.remaining_volume -= temp;
+			break;
+		} else {
+			order.remaining_volume -= this->askSide[0].volume;
+			order.filled_volume += this->askSide[0].volume;
+			this->askSide.erase(this->askSide.begin());
+			std::make_heap(this->askSide.begin(), this->askSide.end(),
+			               std::greater<Level>());
+		}
 	}
-    }
-    if (order.remaining_volume > 0) {
-	this->bidSide.emplace(this->bidSide.begin(), order);
-	std::make_heap(this->bidSide.begin(), this->bidSide.end(),
-	               std::less<Level>());
-    }
+	if (order.remaining_volume > 0) {
+		this->bidSide.emplace_back(order);
+		std::make_heap(this->bidSide.begin(), this->bidSide.end(),
+		               std::less<Level>());
+	}
 }
 
 void Book::printBook(std::size_t numOrders)
 {
-    std::cout << "Sell side: " << this->askSide.size() << std::endl;
-    std::vector<Level> askCopy(this->askSide);
-    std::size_t count = 0;
-    std::sort(askCopy.begin(), askCopy.end());
-    for (auto i = askCopy.rbegin(); i != askCopy.rend() && count < numOrders; i++, count++) {
-        std::cout << *i << std::endl;
-    }
-    std::cout << "Buy side: " << this->bidSide.size() << std::endl;
-    std::vector<Level> bidCopy(this->bidSide);
-    count = 0;
-    std::sort(bidCopy.begin(), bidCopy.end());
-    for (auto i = bidCopy.rbegin(); i != bidCopy.rend() && count < numOrders; i++, count++) {
-        std::cout << *i << std::endl;
-    }
-    }
+	std::cout << "Sell side: " << this->askSide.size() << std::endl;
+	std::vector<Level> askCopy(this->askSide);
+	std::size_t count = 0;
+	std::sort(askCopy.begin(), askCopy.end());
+	std::reverse(askCopy.begin(), askCopy.end());
+	uint64_t volume = 0;
+	double price = askCopy.front().price;
+	for (auto i : askCopy) {
+		std::cout << i << std::endl;
+		count++;
+		if (count > numOrders) break;
+	}
+	std::cout << "Buy side: " << this->bidSide.size() << std::endl;
+	std::vector<Level> bidCopy(this->bidSide);
+	count = 0;
+	std::sort(bidCopy.begin(), bidCopy.end());
+	std::reverse(bidCopy.begin(), bidCopy.end());
+	price = bidCopy.front().price;
+	for (auto i : bidCopy) {
+		std::cout << i << std::endl;
+		count++;
+		if (count > numOrders) break;
+	}
+}
 
 Book testBook(int orders, bool printBook)
 {
-    Book b = Book();
-    double time(1);
-    for (int i = 1; i < orders; i++) {
-	Order t(i, Buy, 10, time++, "a");
-	b.bid(t);
-    }
-    for (int i = orders + 1; i < 2 * orders; i++) {
-	Order t(i, Sell, 10, time++, "b");
-	b.ask(t);
-    }
-    if (printBook) b.printBook(orders - 1);
-    return b;
+	Book b = Book();
+	double time(1);
+	for (int i = 1; i < orders; i++) {
+		Order t(i, Buy, 10, time++, "a");
+		b.bid(t);
+	}
+	for (int i = orders + 1; i < 2 * orders; i++) {
+		Order t(i, Sell, 10, time++, "b");
+		b.ask(t);
+	}
+	if (printBook) b.printBook(orders - 1);
+	return b;
 }
 } // namespace book

--
Gitblit v1.9.3