From 90107c504e5b7d1bea2c93a43c7d07b640350355 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Thu, 13 Jan 2022 06:57:09 +0000
Subject: [PATCH] Removed now unneeded date library

---
 json.cpp |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/json.cpp b/json.cpp
index ea1016a..a8b2397 100644
--- a/json.cpp
+++ b/json.cpp
@@ -1,6 +1,5 @@
 #include "json.hpp"
 #include "book.hpp"
-#include "date/include/date/date.h"
 #include "protocol.hpp"
 #include "rapidjson/include/rapidjson/document.h"
 #include "rapidjson/include/rapidjson/rapidjson.h"
@@ -48,7 +47,8 @@
 	mapOrder = {{"BUY", book::Buy}, {"SELL", book::Sell}};
 
 	mapTrade = {{"BUY_AGGRESSOR", BUY_AGGRESSOR},
-	            {"SELL_AGGRESSOR", SELL_AGGRESSOR}};
+	            {"SELL_AGGRESSOR", SELL_AGGRESSOR},
+	            {"BROKER_TRADE", BROKER_TRADE}};
 
 	mapOrderSide = {{book::Buy, "BUY"}, {book::Sell, "SELL"}};
 }
@@ -64,6 +64,8 @@
 BrokerAck* brokerAck(rapidjson::Value& d);
 BrokerConfirm* brokerCon(rapidjson::Value& d);
 ErrorMessage* error(rapidjson::Value& d);
+
+std::chrono::seconds parseTime(std::string& s);
 
 std::queue<Message*> parse(std::string& str)
 {
@@ -125,12 +127,21 @@
 	return out;
 }
 
+std::chrono::seconds parseTime(std::string& s)
+{
+	return std::chrono::hours{std::stoi(s.substr(0, 4)) * 24 * 30 * 12} +
+	       std::chrono::hours{std::stoi(s.substr(5, 2)) * 24 * 30} +
+	       std::chrono::hours{std::stoi(s.substr(8, 2)) * 24} +
+	       std::chrono::hours{std::stoi(s.substr(11, 2))} +
+	       std::chrono::minutes{std::stoi(s.substr(14, 2))} +
+	       std::chrono::hours{std::stoi(s.substr(16, 5))};
+}
+
 AnnounceMessage* announce(rapidjson::Value& d)
 {
-	// std::stringstream expiryStream(d["expiry"].GetString());
+	std::string es = d["expiry"].GetString();
 	std::chrono::nanoseconds exp_time(0);
-	// expiryStream >>
-	// date::parse("%Y-%m-%f %H:%M%z", exp_time); // Parsing is broken
+	exp_time = parseTime(es);
 	return new AnnounceMessage(
 		mapTypes[d["type"].GetString()], d["product"].GetString(),
 		d["stationId"].GetInt(), d["stationName"].GetString(),
@@ -141,9 +152,9 @@
 
 SettleMessage* settle(rapidjson::Value& d)
 {
-	// std::stringstream expiryStream(d["expiry"].GetString());
 	std::chrono::nanoseconds exp_time(0);
-	// expiryStream >> date::parse("%Y-%m-%d %H:%M%z", exp_time);
+    std::string es = d["expiry"].GetString();
+    exp_time = parseTime(es);
 	return new SettleMessage(
 		mapTypes[d["type"].GetString()], d["product"].GetString(),
 		d["stationName"].GetString(), exp_time, d["price"].GetDouble(),

--
Gitblit v1.9.3