Joel Grunbaum
2022-01-07 127d5af6f934b162c98a40ce414b98415d899cea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#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 };
 
struct Order {
  double price;
  OrderSideEnum side;
  int remaining_volume;
  int filled_volume;
  std::chrono::nanoseconds timestamp;
  std::string id;
  Order(double price, OrderSideEnum side, int volume,
        std::chrono::nanoseconds timestamp, std::string id);
};
 
struct Level {
  double price;
  int volume;
  OrderSideEnum side;
  std::chrono::nanoseconds timestamp;
  std::string id;
 
  Level(Order &order);
};
 
bool operator>(const Level &a, const Level &b);
bool operator<(const Level &a, const Level &b);
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);
    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;
  ProductTypeEnum productType;
  std::string product;
  std::string stationId;
  std::string unit;
  std::chrono::nanoseconds expiry;
  double aggFee;
  double pasFee;
  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);
  void ask(Order &order);
  void bid(Order &order);
    void printBook(std::size_t numOrders = 10);
};
 
Book testBook(int orders = 10, bool printBook = true);