From 127d5af6f934b162c98a40ce414b98415d899cea Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Fri, 07 Jan 2022 10:43:34 +0000
Subject: [PATCH] finished book

---
 book.hpp |   29 +++++++----------------------
 1 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/book.hpp b/book.hpp
index a167b32..9e3a89c 100644
--- a/book.hpp
+++ b/book.hpp
@@ -1,10 +1,12 @@
 #pragma once
 
 #include <chrono>
+#include <cstddef>
 #include <iostream>
 #include <queue>
 #include <string>
 #include <vector>
+#include <algorithm>
 
 enum OrderSideEnum { Buy, Sell };
 enum ProductTypeEnum { TEST, FUTURE, SPREAD, CALL, PUT };
@@ -35,31 +37,14 @@
 bool operator>=(const Level &a, const Level &b);
 bool operator<=(const Level &a, const Level &b);
 bool operator==(const Level &a, const Level &b);
+std::ostream& operator<<(std::ostream& out, const Level& a);
 
 template <class T>
 struct Side : public std::priority_queue<Level, std::vector<Level>, T> {
 public:
-  void deleteLevel(std::string orderId) {
-    for (auto i = this->c.begin(); i != this->c.end();) {
-      if (*i.id == orderId) {
-        this->c.erase(i);
-        std::make_heap(this->c.begin(), this->c.end(), this->comp);
-      }
-    }
-  }
-
-  void topRemoveVolume(int volume) { this->c[0].volume -= volume; }
-
-  void printTop(int num = 5) {
-    std::sort(this->c.begin(), this->c.end(), this->comp);
-    for (int i = 0; i < num && i < this->size(); i++) {
-      std::cout << "Price: " << this->c[i].price
-                << ", volume: " << this->c[i].volume
-                << ", time: " << this->c[i].timestamp.count()
-                << ", id: " << this->c[i].id << std::endl;
-    }
-    std::make_heap(this->c.begin(), this->c.end(), this->comp);
-  }
+    void deleteLevel(std::string orderId);
+    void topRemoveVolume(int volume);
+    void printTop(std::size_t num = 5);
 };
 
 using AskSide = Side<std::greater<Level>>;
@@ -83,7 +68,7 @@
        double pasFee, double broFee);
   void ask(Order &order);
   void bid(Order &order);
-  void printBook();
+    void printBook(std::size_t numOrders = 10);
 };
 
 Book testBook(int orders = 10, bool printBook = true);

--
Gitblit v1.9.3