99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "Price.h"
|
|
#include "Quantity.h"
|
|
#include "lib/core/FMT_IMPL.h"
|
|
#include "lib/domain/SecurityID.h"
|
|
#include "lib/io/JsonReader.h"
|
|
#include "lib/md/IntPrice.h"
|
|
#include "lib/md/protos/co2.pb.h"
|
|
|
|
#include <fmt/format.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <ostream>
|
|
|
|
namespace bts::domain {
|
|
|
|
class SecurityMarketDataStatistics {
|
|
public:
|
|
SecurityID security_id;
|
|
Price low;
|
|
Price high;
|
|
Price open;
|
|
Price settle;
|
|
Quantity volume = Quantity(0);
|
|
SecurityMarketDataStatistics() {}
|
|
SecurityMarketDataStatistics(
|
|
uint32_t sec_key, const bts::co2::MiscMessage &misc_msg)
|
|
: security_id(SecurityID(sec_key)),
|
|
low(Price::from_double(misc_msg.session_low())),
|
|
high(Price::from_double(misc_msg.session_high())),
|
|
open(Price::from_double(misc_msg.open_price())),
|
|
settle(Price::from_double(bts::md::IntPrice(
|
|
misc_msg.settlement().mantissa(),
|
|
misc_msg.settlement().exponent())
|
|
.price())) {}
|
|
};
|
|
|
|
void from_json(const nlohmann::json &j, SecurityMarketDataStatistics &s);
|
|
void to_json(nlohmann::json &j, const SecurityMarketDataStatistics &s);
|
|
|
|
std::ostream &operator<<(
|
|
std::ostream &out, const SecurityMarketDataStatistics &s);
|
|
|
|
//////////////////////////////////////////////////
|
|
// Definition
|
|
//////////////////////////////////////////////////
|
|
|
|
inline void from_json(
|
|
const nlohmann::json &j, SecurityMarketDataStatistics &s) {
|
|
io::JsonReader jr{&j};
|
|
// clang-format off
|
|
bool success = jr.read("sid", s.security_id) &&
|
|
jr.read("low", s.low) &&
|
|
jr.read("high", s.high) &&
|
|
jr.read("open", s.open) &&
|
|
jr.read("settle", s.settle) &&
|
|
jr.read("volume", s.volume);
|
|
// clang-format on
|
|
if (!success) {
|
|
const auto j_str = j.dump(2);
|
|
LOG(md, Error,
|
|
"Failed to parse json to SecurityMarketDataStatistics:\n{}", j_str);
|
|
}
|
|
}
|
|
|
|
inline void to_json(nlohmann::json &j, const SecurityMarketDataStatistics &s) {
|
|
// clang-format off
|
|
j = nlohmann::json{
|
|
{"sid", s.security_id},
|
|
{"low", s.low},
|
|
{"high", s.high},
|
|
{"open", s.open},
|
|
{"settle", s.settle},
|
|
{"volume", s.volume}};
|
|
// clang-format on
|
|
}
|
|
} // namespace bts::domain
|
|
|
|
FMT_IMPL(
|
|
bts::domain::SecurityMarketDataStatistics,
|
|
s,
|
|
"id: {}; low: {}; high: {}; open: {}; settle: {}; volume: {}",
|
|
s.security_id,
|
|
s.low,
|
|
s.high,
|
|
s.open,
|
|
s.settle,
|
|
s.volume);
|
|
|
|
namespace bts::domain {
|
|
|
|
inline std::ostream &operator<<(
|
|
std::ostream &out, const SecurityMarketDataStatistics &s) {
|
|
out << fmt::format("{}", s);
|
|
return out;
|
|
}
|
|
|
|
} // namespace bts::domain
|