Fixes sim drift awy from MD source.

This commit is contained in:
Pedro Pinto committed 2019-01-02 17:05:38 +00:00
1 parent 6dfe9b3892
commit 714dfd5038
2 files changed
+10 -8

No files matched your search

@@ -95,7 +95,6 @@ convert(const FIX::ManualOrderIndicator &moi) {
struct ExchangeSimApplication::MDConsumerRec {
api::Security security;
utils::TimeStamp last_read;
Book previous_md_book;
};
struct ExchangeSimApplication::PImpl {
@@ -456,6 +455,8 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
auto book = matcher.get_book();
LOG(ExSim, Diag, "Current book {}:\n {}", sec_desc,book);
auto price_factor = pow(10, handle.security().display_factor);
const auto cmax = md::COCONUT_MAX_DEPTH;
@@ -525,7 +526,7 @@ void ExchangeSimApplication::on_new_security(api::Security const &s) {
me->md_producer_handles.insert(make_pair(sec_desc, handle));
me->md_consumer_recs.insert(
make_pair(s.glbx().security_desc(),
MDConsumerRec{s2, utils::TimeStamp::now(), Book()}));
MDConsumerRec{s2, utils::TimeStamp::now()}));
});
}
}
@@ -545,6 +546,7 @@ void ExchangeSimApplication::on_depth(
md::PriceSize asks[md::COCONUT_MAX_DEPTH],
std::array<md::PriceSize, md::COCONUT_MAX_IMPLIED_DEPTH>* implied_bids,
std::array<md::PriceSize, md::COCONUT_MAX_IMPLIED_DEPTH>* implied_asks) {
std::lock_guard<std::mutex> l(me->lock);
if (sec.has_synthetic())
@@ -556,8 +558,8 @@ void ExchangeSimApplication::on_depth(
auto it = me->md_consumer_recs.find(sec.glbx().security_desc());
bts_assert(it != me->md_consumer_recs.end());
// cache previous Book so we can update it place
Book previous_md_book = it->second.previous_md_book;
auto &matcher = me->matchers[get_sim_sec_desc(sec)];
Book previous_md_book = matcher.get_book();
// populate Book structure with new bids, asks coming from outside
Book current_md_book;
@@ -572,9 +574,6 @@ void ExchangeSimApplication::on_depth(
current_md_book.asks[a] = Quantity(asks[i].size());
}
// update the indexed Book structure with the latest values
it->second.previous_md_book = current_md_book;
// from the differences between current_md_book and previous_md_book
// we generate a set of orders that we apply to our order book
merge_with_order_book(it->second.security.glbx().security_desc(),
@@ -597,6 +596,9 @@ void ExchangeSimApplication::merge_with_order_book(std::string const &sec_desc,
auto src_book = matcher.get_book();
auto transform = compute_book_transform(src, dest);
LOG(ExSim, Diag, "Book transformation for {}\n source:\n {} dest:\n{}", sec_desc,src,dest);
for (auto const &op : transform) {
LOG(ExSim, Diag, "Adding synthetic book operation for {}. {} {} {}@{}",