diff --git a/OrderBook.cc b/OrderBook.cc new file mode 100644 index 0000000..e6ea570 --- /dev/null +++ b/OrderBook.cc @@ -0,0 +1,18 @@ +#include +#include + +namespace hft +{ + +void OrderBook::intake_order(OrderID id) +{ + // consume from an input gRPC queue + // OR from a simple socket connection +} + +int main () +{ + return 0; +} + +} // End hft namespace \ No newline at end of file diff --git a/OrderBook.hh b/OrderBook.hh new file mode 100644 index 0000000..afb2a87 --- /dev/null +++ b/OrderBook.hh @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include + +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; + + /// Order: Order ID, Content + using Order = std::map; + + static constexpr uint32_t ORDER_QUEUE_INIT_SIZE{1024}; + + std::vector 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 \ No newline at end of file diff --git a/README.md b/README.md index c820ce5..14ad031 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # HFT -Order Book and HFT simulator [WIP] \ No newline at end of file +[WIP] + +Order Book and HFT simulator \ No newline at end of file diff --git a/orderbook b/orderbook new file mode 100755 index 0000000..b35e91f Binary files /dev/null and b/orderbook differ diff --git a/server.cc b/server.cc new file mode 100644 index 0000000..f5e5b8a --- /dev/null +++ b/server.cc @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +namespace net +{ + +class TCPServer +{ +private: + int status; + struct addrinfo hints; + struct addrinfo *servinfo; // Points to results + +public: + TCPServer(TCPServer&) = delete; + ~TCPServer() + { + this->stop(); + } + + void init() + { + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + if(!is_valid_struct(&hints, &servinfo)) + { + + } + } + + bool is_valid_struct(addrinfo hints, addrinfo servinfo) + { + uint8_t result = getaddrinfo(NULL, "1337", &hints, &servinfo); + return + + } + + + void stop() + { + // Maybe more. Threading stuff? + freeaddrinfo(servinfo); + } +}; +} // End net namespace \ No newline at end of file diff --git a/server.hh b/server.hh new file mode 100644 index 0000000..bf0bc3d --- /dev/null +++ b/server.hh @@ -0,0 +1,10 @@ +#include +#include +#include + +int status; +struct addrinfo hints; +struct addrinfo *servinfo; // Points to results + +memset(&hints, 0, sizeof hints); +hints.ai_family = AF_UNSPACE \ No newline at end of file