-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOrderBook.h
101 lines (88 loc) · 3.11 KB
/
OrderBook.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include "OrderBookEntry.h"
#include "CSVReader.h"
#include <string>
#include <vector>
class OrderBook
{
public:
/**
* Construct, reading a csv data file
*
* @param filename
*/
OrderBook(std::string filename);
/**
* Get the list of known products.
*
* @return std::vector<std::string>
*/
std::vector<std::string> getKnownProducts();
/**
* Retrieves the earliest timestamp in the OrderBook.
*
* @return the earliest timestamp
*/
std::string getEarliestTime();
/**
* Inserts an order into the order book and sorts the orders by timestamp.
*
* @param order The order to be inserted into the order book.
*/
void insertOrder(OrderBookEntry& order);
/**
* Matches asks to bids in the order book for a specific product and timestamp.
*
* @param product the product to match asks and bids for
* @param timestamp the timestamp to match asks and bids for
*
* @return a vector of order book entries representing the sales
*/
std::vector<OrderBookEntry> matchAsksToBids(std::string product, std::string timestamp);
/**
* Retrieves the next time based on the given timestamp in then OrderBook
* If there is no next timestamp, wraps around to the start
*
* @param timestamp the input timestamp
*
* @return the next time
*/
std::string getNextTime(std::string timestamp);
/**
* Retrieves a list of orders based on the specified criteria.
*
* @param type The type of order book to retrieve from.
* @param product The specific product to retrieve orders for.
* @param timestamp The timestamp at which the orders were placed.
* @return A vector of OrderBookEntry objects that match the specified criteria.
*/
std::vector<OrderBookEntry> getOrders(OrderBookType type,
std::string product,
std::string timestamp);
/**
* Get the highest price from the given list of order book entries.
*
* @param orders The list of order book entries
*
* @return The highest price
*/
static double getHighPrice(std::vector<OrderBookEntry>& orders);
/**
* Returns the lowest price from the given list of order book entries.
*
* @param orders the list of order book entries
*
* @return the lowest price
*/
static double getLowPrice(std::vector<OrderBookEntry>& orders);
/**
* Calculate the total volume of orders in given list of order book entries.
*
* @param orders the vector of OrderBookEntry objects
*
* @return the total volume
*/
static double getTotalVolume(std::vector<OrderBookEntry>& orders);
private:
std::vector<OrderBookEntry> orders;
};