From 128c6d51ec8c70e230dc86b100cb887ba3f0378d Mon Sep 17 00:00:00 2001 From: Joel Grunbaum <joelgrun@gmail.com> Date: Thu, 20 Jan 2022 07:00:50 +0000 Subject: [PATCH] Secrets to macros and c string concat at compile time --- protocol.cpp | 110 +++++++++++++++++++++++++++++------------------------- 1 files changed, 59 insertions(+), 51 deletions(-) diff --git a/protocol.cpp b/protocol.cpp index f1083c0..f3c637a 100644 --- a/protocol.cpp +++ b/protocol.cpp @@ -16,12 +16,14 @@ #include <string> #include <unordered_map> +using namespace std::literals; + namespace protocol { static std::unordered_map<json::MessageTypes, book::ProductTypeEnum> mapAnnounce; -std::string server = std::string(HOST) + ":" + std::string(PORT); -httplib::Client cli("http://" + server); +#define SERVER HOST ":" PORT +httplib::Client cli("http://" SERVER); std::unique_ptr<easywsclient::WebSocket> ws; double lastime = 0; @@ -40,7 +42,6 @@ // std::ifstream sampleFile("../data.test"); // std::stringstream ss; // ss << sampleFile.rdbuf(); - httplib::Client cli("http://" + server); auto res = cli.Get("/recover"); std::string l; // l = ss.str(); @@ -61,8 +62,8 @@ void createWebSocket() { ws = std::unique_ptr<easywsclient::WebSocket>( - easywsclient::WebSocket::pointer(easywsclient::WebSocket::from_url( - "ws://" + server + "/information"))); + easywsclient::WebSocket::pointer( + easywsclient::WebSocket::from_url("ws://" SERVER "/information"))); ws->poll(); } @@ -175,57 +176,61 @@ json::DeletedMessage* message) { if (message->side == book::Buy) { - for (auto i = bs[message->product].bidSide.begin(); i != bs[message->product].bidSide.end(); i++) { - if (i->id == message->id) { - bs[message->product].bidSide.erase(i); - break; - } - } + for (auto i = bs[message->product].bidSide.begin(); + i != bs[message->product].bidSide.end(); i++) { + if (i->id == message->id) { + bs[message->product].bidSide.erase(i); + break; + } + } } else { - for (auto i = bs[message->product].askSide.begin(); i != bs[message->product].askSide.end(); i++) { - if (i->id == message->id) { - bs[message->product].askSide.erase(i); - break; - } - } + for (auto i = bs[message->product].askSide.begin(); + i != bs[message->product].askSide.end(); i++) { + if (i->id == message->id) { + bs[message->product].askSide.erase(i); + break; + } + } } } void tradeOrder(std::unordered_map<std::string, book::Book>& bs, json::TradeMessage* message) { - if (message->tradeType == json::BUY_AGGRESSOR) { - if (message->passiveOrderRemaining > 0) { - for (auto& i : bs[message->product].askSide) { - if (i.id == message->passiveOrder) { - i.volume = message->passiveOrderRemaining; - break; - } - } - } else { - for (auto i = bs[message->product].askSide.begin(); i != bs[message->product].askSide.end(); i++) { - if (i->id == message->passiveOrder) { - bs[message->product].askSide.erase(i); - break; - } - } - } - } else if (message->tradeType == json::SELL_AGGRESSOR) { - if (message->passiveOrderRemaining > 0) { - for (auto& i : bs[message->product].bidSide) { - if (i.id == message->passiveOrder) { - i.volume = message->passiveOrderRemaining; - break; - } - } - } else { - for (auto i = bs[message->product].bidSide.begin(); i != bs[message->product].bidSide.end(); i++) { - if (i->id == message->passiveOrder) { - bs[message->product].bidSide.erase(i); - break; - } - } - } - } + if (message->tradeType == json::BUY_AGGRESSOR) { + if (message->passiveOrderRemaining > 0) { + for (auto& i : bs[message->product].askSide) { + if (i.id == message->passiveOrder) { + i.volume = message->passiveOrderRemaining; + break; + } + } + } else { + for (auto i = bs[message->product].askSide.begin(); + i != bs[message->product].askSide.end(); i++) { + if (i->id == message->passiveOrder) { + bs[message->product].askSide.erase(i); + break; + } + } + } + } else if (message->tradeType == json::SELL_AGGRESSOR) { + if (message->passiveOrderRemaining > 0) { + for (auto& i : bs[message->product].bidSide) { + if (i.id == message->passiveOrder) { + i.volume = message->passiveOrderRemaining; + break; + } + } + } else { + for (auto i = bs[message->product].bidSide.begin(); + i != bs[message->product].bidSide.end(); i++) { + if (i->id == message->passiveOrder) { + bs[message->product].bidSide.erase(i); + break; + } + } + } + } } void broker(std::unordered_map<std::string, book::Book>& bs, @@ -238,7 +243,10 @@ httplib::MultipartFormDataItems a = {{"message", message, "", ""}, {"username", USER, "", ""}, {"password", PASS, "", ""}}; - auto res = cli.Post("/execution", a); + auto res = + cli.Post("/execution", + "message=" + message + "&username=" USER "&password=" PASS, + "application/x-www-form-urlencoded"); std::string b = res->body; std::queue<json::Message*> c = json::parse(b); return c.front(); -- Gitblit v1.9.3