fix: Don't round ccapi book qtys to int

This commit is contained in:
John Colvin committed 2023-04-14 17:07:25 +00:00
1 parent fa26ecaf67
commit d7518cffe1
1 file changed
+4 -9
+4 -9
View File
@@ -5,6 +5,8 @@
namespace bts::md {
using bts::domain::Quantity;
bool CCApiDepthWalker::parse_field(
const std::string &name, const std::string &value) {
bts_assert(depth_ptr);
@@ -22,15 +24,8 @@ bool CCApiDepthWalker::parse_field(
if (qty_idx < depth.size()) {
double qty_dbl = stod(value);
bts_assert(qty_dbl > 0);
bts_assert(qty_dbl < std::numeric_limits<std::uint32_t>::max());
bts::domain::Quantity qty{static_cast<std::uint32_t>(qty_dbl)};
// Since we still haven't converted our [underlying] Quantity type to
// double, this hack is neccessary to prevent legitimate book levels
// from having a quantity of 0. Many places in the code assume that
// quantity == 0 means 'this level, and all those after it, are empty.'
if (qty < 1) {
qty.value() = 1;
}
bts_assert(qty_dbl < std::numeric_limits<Quantity::Value>::max());
Quantity qty{static_cast<Quantity::Value>(qty_dbl)};
depth[qty_idx].direct_quantity = qty;
depth[qty_idx].total_quantity = qty;
qty_idx++;