74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
|
#include <memory>
|
||
|
#include <thread>
|
||
|
#include <map>
|
||
|
#include <tuple>
|
||
|
#include <vector>
|
||
|
#include <algorithm>
|
||
|
|
||
|
namespace hft
|
||
|
{
|
||
|
|
||
|
|
||
|
class OrderBook
|
||
|
{
|
||
|
|
||
|
enum OrderType : uint8_t
|
||
|
{
|
||
|
BID = 0,
|
||
|
ASK
|
||
|
};
|
||
|
private:
|
||
|
using OrderID = uint32_t;
|
||
|
using Price = uint32_t;
|
||
|
using Quantity = uint32_t;
|
||
|
|
||
|
/// Content: Ask/buy, price, quantity
|
||
|
using Content = std::tuple<OrderType, Price, Quantity>;
|
||
|
|
||
|
/// Order: Order ID, Content
|
||
|
using Order = std::map<OrderID, Content>;
|
||
|
|
||
|
static constexpr uint32_t ORDER_QUEUE_INIT_SIZE{1024};
|
||
|
|
||
|
std::vector<Order> orders;
|
||
|
|
||
|
bool running{false};
|
||
|
|
||
|
public:
|
||
|
/// Default ctor
|
||
|
OrderBook() : orders{ORDER_QUEUE_INIT_SIZE}
|
||
|
{}
|
||
|
|
||
|
/// No copy ctor
|
||
|
OrderBook(OrderBook&) = delete;
|
||
|
|
||
|
/// No copy assignment
|
||
|
OrderBook operator=(OrderBook&) = delete;
|
||
|
|
||
|
/// Move ctor
|
||
|
/// @todo Finish implementation, or perhaps it is smarter to use compiler default
|
||
|
// OrderBook(OrderBook&& other)
|
||
|
// {
|
||
|
// std::copy(other.orders.begin(), other.orders.end(), orders.begin());
|
||
|
// }
|
||
|
|
||
|
/// Move assignment
|
||
|
/// @todo Implement. Or maybe not
|
||
|
// OrderBook operator=(OrderBook&& other)
|
||
|
// {}
|
||
|
|
||
|
/// @brief Adds an order to the order book queue.
|
||
|
/// @param
|
||
|
/// @param
|
||
|
/// @param
|
||
|
void intake_order(OrderID id);
|
||
|
|
||
|
/// @brief
|
||
|
/// @param
|
||
|
void process_order(OrderID);
|
||
|
|
||
|
/// @brief Looks for match until order is filled
|
||
|
void process();
|
||
|
};
|
||
|
|
||
|
} // End hft namespace
|