initial server setup
This commit is contained in:
parent
ece18b0dfc
commit
ff8754ad37
18
OrderBook.cc
Normal file
18
OrderBook.cc
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <OrderBook.hh>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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
|
74
OrderBook.hh
Normal file
74
OrderBook.hh
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#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
|
@ -1,3 +1,5 @@
|
|||||||
# HFT
|
# HFT
|
||||||
|
|
||||||
Order Book and HFT simulator [WIP]
|
[WIP]
|
||||||
|
|
||||||
|
Order Book and HFT simulator
|
49
server.cc
Normal file
49
server.cc
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <cstring>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user