refactor (chore): Clean up domain::Security a bit

* Rename 'min_quantity_increment_ammount' -> 'min_quantity_increment' to fix typo
* Remove old 'min_quantity_increment' member (it wasn't referenced anywhere)
* Initialize SecurityCommon w/ reasonable defaults (skipping initialization seems
like a premature performance optimization)
* Add a few members to verbose 'to_string' result
This commit is contained in:
John Colvin committed 2023-01-04 13:35:38 -05:00
1 parent 4b60fb5141
commit 556e2ab99e
4 files changed
+30 -9

No files matched your search

+12 -1
View File
@@ -9,7 +9,7 @@
#if bts_assert_msg
#define __ASSERT_MSG(EXP, msg) bts_assert_msg(EXP, msg)
#else
#define __ASSERT_MSG(EXP, msg) \
#define __ASSERT_MSG(EXP, msg) \
do { \
if (!(EXP)) { \
std::cerr << "Assert failure: " << std::string(#EXP) << " " << msg \
@@ -89,6 +89,9 @@ class Price {
template <class Range>
static double get_mean(Range range, bool skip_nan = false);
static constexpr Price min() noexcept;
static constexpr Price max() noexcept;
Price &operator=(Price const &) = default;
Price &operator=(Price &&) noexcept = default;
@@ -379,6 +382,14 @@ inline double Price::get_mean(Range range, bool skip_nan) {
return get_mean(range.begin(), range.end(), skip_nan);
}
constexpr Price Price::min() noexcept {
return Price{std::numeric_limits<std::int64_t>::min() + 1};
}
constexpr Price Price::max() noexcept {
return Price{std::numeric_limits<std::int64_t>::max()};
}
inline double Price::_pow10() noexcept { return std::pow(10.0, exponent()); }
inline double Price::__pow10() noexcept { return std::pow(10.0, -exponent()); }
constexpr Price Price::operator-() const noexcept {
+12
View File
@@ -22,6 +22,18 @@ std::string Security::to_string(bool verbose) const {
"type", [](const auto &s) { return SecurityType_Name(s.type()); });
schema.add("symbol", [](const auto &s) { return s.symbol(); });
schema.add("venue", [](const auto &s) { return Venue_Name(s.venue()); });
schema.add("min_price_increment", [](const auto &s) {
return s.security_common.min_price_increment;
});
schema.add("min_quantity_increment", [](const auto &s) {
return s.security_common.min_quantity_increment;
});
schema.add("min_quantity", [](const auto &s) {
return s.security_common.min_quantity;
});
schema.add("max_quantity", [](const auto &s) {
return s.security_common.max_quantity;
});
if (std::holds_alternative<FutureSecurity>(security)) {
const auto &fut = std::get<FutureSecurity>(security);
schema.add("expiration", [&fut](const auto &) { return fut.expiration; });
+5 -6
View File
@@ -5,6 +5,7 @@
#include "lib/api/domain/Currency.pb.h"
#include "lib/api/domain/SecurityType.pb.h"
#include "lib/api/domain/Venue.pb.h"
#include <limits>
#include <string>
namespace bts::domain {
@@ -17,18 +18,16 @@ class SecurityCommon {
SecurityID id{};
api::domain::SecurityType type;
api::domain::Currency currency;
double display_factor{};
double cash_per_point{};
std::string symbol;
std::string group;
std::string asset;
std::string desc;
Price min_price_increment{};
double min_price_increment_ammount = 0;
Price min_price = Price::min();
Price max_price = Price::max();
double min_price_increment = 0;
double min_quantity_increment = 0;
double min_quantity = 0;
bool implied_matching = false;
std::string cme_security_type;
double max_quantity = std::numeric_limits<double>::max();
};
} // namespace bts::domain
+1 -2
View File
@@ -408,8 +408,7 @@ void CCMarketDataListener::_copy_security_common(
to.exchange = Venue::VENUE_FTX;
to.display_factor = 0.0;
to.price_break = 0.0;
to.low_tick = to.high_tick =
from.security_common.min_price_increment_ammount;
to.low_tick = to.high_tick = from.security_common.min_price_increment;
}
} // namespace bts::md