quantity fix
This commit is contained in:
1 parent
a1d62e552c
commit
5a87288aaa
1 file changed
+27
-4
@@ -326,10 +326,25 @@ std::string build_security_desc(
|
||||
short_pool_id);
|
||||
}
|
||||
|
||||
domain::BookLevel to_book_level(const ConnectorBookLevel& source) {
|
||||
double quantity_scale_from_decimals(std::uint8_t decimals) {
|
||||
double scale = 1.0;
|
||||
for (std::uint8_t i = 0; i < decimals; ++i) {
|
||||
scale *= 10.0;
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
domain::BookLevel to_book_level(
|
||||
const ConnectorBookLevel& source,
|
||||
double quantity_scale) {
|
||||
domain::BookLevel level;
|
||||
level.price = domain::Price::from_double(source.price);
|
||||
level.total_quantity = domain::Quantity(static_cast<float>(source.quantity));
|
||||
const auto normalized_quantity =
|
||||
quantity_scale > 0.0
|
||||
? static_cast<double>(source.quantity) / quantity_scale
|
||||
: static_cast<double>(source.quantity);
|
||||
level.total_quantity =
|
||||
domain::Quantity(static_cast<float>(normalized_quantity));
|
||||
level.direct_quantity = level.total_quantity;
|
||||
level.n_orders = 0;
|
||||
return level;
|
||||
@@ -500,6 +515,8 @@ class ListenerAdapter final : public ::rakurai::dex_connector::dex_listener {
|
||||
}
|
||||
|
||||
pool_to_security_id_[pool_id] = it->second->id();
|
||||
pool_quantity_scales_[pool_id] =
|
||||
quantity_scale_from_decimals(security->token_a.decimals);
|
||||
emitted.push_back(it->second.get());
|
||||
}
|
||||
|
||||
@@ -549,16 +566,21 @@ class ListenerAdapter final : public ::rakurai::dex_connector::dex_listener {
|
||||
pool_key);
|
||||
return;
|
||||
}
|
||||
const auto quantity_scale_it = pool_quantity_scales_.find(pool_key);
|
||||
const auto quantity_scale =
|
||||
quantity_scale_it != pool_quantity_scales_.end()
|
||||
? quantity_scale_it->second
|
||||
: 1.0;
|
||||
|
||||
auto book = domain::Book::empty(it->second);
|
||||
const auto bid_depth = std::min<std::size_t>(depth_limit_, bids.size());
|
||||
const auto ask_depth = std::min<std::size_t>(depth_limit_, asks.size());
|
||||
|
||||
for (std::size_t i = 0; i < bid_depth; ++i) {
|
||||
book.bids()[i] = to_book_level(bids[i]);
|
||||
book.bids()[i] = to_book_level(bids[i], quantity_scale);
|
||||
}
|
||||
for (std::size_t i = 0; i < ask_depth; ++i) {
|
||||
book.asks()[i] = to_book_level(asks[i]);
|
||||
book.asks()[i] = to_book_level(asks[i], quantity_scale);
|
||||
}
|
||||
|
||||
listener_->on_book(book);
|
||||
@@ -601,6 +623,7 @@ class ListenerAdapter final : public ::rakurai::dex_connector::dex_listener {
|
||||
persistence::SqliteStore pool_alias_store_{"rakurai_pool_alias"};
|
||||
std::unordered_map<std::string, std::unique_ptr<domain::Security>> securities_;
|
||||
std::unordered_map<std::string, domain::SecurityID> pool_to_security_id_;
|
||||
std::unordered_map<std::string, double> pool_quantity_scales_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in new issue
Block a user