Improved exchage simulator.
This commit is contained in:
1 parent
2f6c665c5c
commit
3da33aba84
2 files changed
+24
-17
No files matched your search
@@ -463,15 +463,14 @@ void ExchangeSimApplication::merge_with_md_book() {
|
||||
auto &ts = kvp.second.last_read;
|
||||
|
||||
if (sec.has_synthetic()) {
|
||||
//
|
||||
}
|
||||
else if (me->do_merge_with_md) {
|
||||
//
|
||||
} else if (me->do_merge_with_md) {
|
||||
|
||||
md::PriceSize bids[md::COCONUT_MAX_DEPTH], asks[md::COCONUT_MAX_DEPTH];
|
||||
|
||||
if (handle.get_depth(ts, md::COCONUT_MAX_DEPTH, bids, asks) ==
|
||||
md::HandleReadResult::SUCCESS) {
|
||||
Book &previous_md_book = kvp.second.previous_md_book;
|
||||
Book previous_md_book = kvp.second.previous_md_book;
|
||||
Book current_md_book;
|
||||
for (size_t i = 0; i < md::COCONUT_MAX_DEPTH; i++) {
|
||||
auto b = securities::encode_exchange_price(
|
||||
@@ -481,29 +480,29 @@ void ExchangeSimApplication::merge_with_md_book() {
|
||||
sec, Price(asks[i].price()));
|
||||
current_md_book.asks[a] = Quantity(asks[i].size());
|
||||
}
|
||||
Book target_book;
|
||||
for (auto b : current_md_book.bids)
|
||||
if (previous_md_book.bids[b.first] != b.second)
|
||||
target_book.bids[b.first] = b.second;
|
||||
|
||||
for (auto a : current_md_book.asks)
|
||||
if (previous_md_book.asks[a.first] != a.second)
|
||||
target_book.asks[a.first] = a.second;
|
||||
kvp.second.previous_md_book = current_md_book;
|
||||
LOG(ExSim, Info, "Target book for {}:\n{}", kvp.first, target_book);
|
||||
merge_with_md_book(kvp.first, target_book);
|
||||
LOG(ExSim, Info, "Target book for {}:\n{}\n", kvp.first,
|
||||
previous_md_book, current_md_book);
|
||||
merge_with_md_book(kvp.first, previous_md_book, current_md_book);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExchangeSimApplication::merge_with_md_book(std::string const &sec_desc,
|
||||
Book const &target_book) {
|
||||
Book const &src,
|
||||
Book const &dest) {
|
||||
auto &matcher = me->matchers[sec_desc];
|
||||
auto src_book = matcher.get_book();
|
||||
auto transform = compute_book_transform(src_book, target_book);
|
||||
auto transform = compute_book_transform(src, dest);
|
||||
|
||||
for (auto const &op : transform) {
|
||||
|
||||
LOG(ExSim, Info, "Adding sim order for {}. {} {}@{}", sec_desc,
|
||||
op.side == api::SIDE_BUY ? std::string("Buy") : std::string("Sell"),
|
||||
op.quantity.value(), op.price.value());
|
||||
|
||||
ex_sim::Order order;
|
||||
order.clordid = fmt::format("synth-{}", me->m_generator.genOrderID());
|
||||
order.sec_desc = sec_desc;
|
||||
@@ -526,8 +525,16 @@ void ExchangeSimApplication::merge_with_md_book(std::string const &sec_desc,
|
||||
std::vector<Order> updates;
|
||||
matcher.add(order, &updates);
|
||||
for (auto const &o : updates)
|
||||
if (o.account != "SYNTH")
|
||||
if (o.account != "SYNTH") {
|
||||
LOG(ExSim, Info,
|
||||
"Generating fill in response to md change for {}: {} {}@{}",
|
||||
sec_desc,
|
||||
o.side == api::SIDE_BUY ? std::string("Buy")
|
||||
: std::string("Sell"),
|
||||
o.open_quantity.value(), o.price.value());
|
||||
fillOrder(o);
|
||||
}
|
||||
|
||||
update_md(sec_desc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
std::unique_ptr<PImpl> me;
|
||||
struct MDConsumerRec;
|
||||
void on_new_security(api::Security const&sec, md::MDConsumerHandle handle);
|
||||
void merge_with_md_book(std::string const &sec_desc, Book const&target_book);
|
||||
void merge_with_md_book(std::string const &sec_desc, Book const&previous,Book const¤t);
|
||||
void update_md(std::string const&sec_desc);
|
||||
};
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user