Joel Grunbaum
2022-01-08 16b655e7c8cfb2e32e6bb839373f30ad63506f9a
book.hpp
@@ -1,13 +1,15 @@
#pragma once
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
namespace book
{
enum OrderSideEnum { Buy, Sell };
enum ProductTypeEnum { TEST, FUTURE, SPREAD, CALL, PUT };
@@ -16,17 +18,17 @@
  OrderSideEnum side;
  int remaining_volume;
  int filled_volume;
  std::chrono::nanoseconds timestamp;
    double timestamp;
  std::string id;
  Order(double price, OrderSideEnum side, int volume,
        std::chrono::nanoseconds timestamp, std::string id);
    Order(double price, OrderSideEnum side, int volume, double timestamp,
          std::string id);
};
struct Level {
  double price;
  int volume;
  OrderSideEnum side;
  std::chrono::nanoseconds timestamp;
    double timestamp;
  std::string id;
  Level(Order &order);
@@ -39,20 +41,9 @@
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);
    void topRemoveVolume(int volume);
    void printTop(std::size_t num = 5);
};
using AskSide = Side<std::greater<Level>>;
using BidSide = Side<std::less<Level>>;
struct Book {
  BidSide bidSide;
  AskSide askSide;
    std::vector<Level> bidSide;
    std::vector<Level> askSide;
  ProductTypeEnum productType;
  std::string product;
  std::string stationId;
@@ -63,12 +54,14 @@
  double broFee;
  Book();
  Book(ProductTypeEnum productType, std::string product, std::string stationId,
       std::string unit, std::chrono::nanoseconds expiry, double aggFee,
       double pasFee, double broFee);
    Book(ProductTypeEnum productType, std::string product,
         std::string stationId, std::string unit,
         std::chrono::nanoseconds expiry, double aggFee, double pasFee,
         double broFee);
  void ask(Order &order);
  void bid(Order &order);
    void printBook(std::size_t numOrders = 10);
};
Book testBook(int orders = 10, bool printBook = true);
} // namespace book