SPARK-608, Generating our own book.

This commit is contained in:
Pedro Pinto committed 2018-03-06 14:28:58 -05:00
1 parent fab0388ae1
commit 970bf44751
4 files changed
+143 -88

No files matched your search

@@ -7,6 +7,7 @@
#include "lib/md/get_symbols.h"
#include "lib/utils/datetime.h"
#include "lib/domain_model/Security.h"
#include "lib/md/Shm/MDStructure.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <quickfix/fix42/ExecutionReport.h>
@@ -71,7 +72,7 @@ void ExchangeSimApplication::onMessage(const FIX42::NewOrderSingle &message,
(long)orderQty, convert(moi));
processOrder(order);
m_orderMatcher.display();
update_md(sec_desc);
} catch (std::exception &e) {
rejectOrder(senderCompID, senderSubID, targetCompID, clOrdID, sec_desc,
side, account, e.what());
@@ -114,7 +115,7 @@ void ExchangeSimApplication::onMessage(
fillOrder(orders.front());
orders.pop();
}
m_orderMatcher.display();
update_md(sec_desc);
} catch (std::exception &e) {
rejectOrder(senderCompID, senderSubID, targetCompID, clOrdID, sec_desc,
side, account, e.what());
@@ -134,7 +135,7 @@ void ExchangeSimApplication::onMessage(const FIX42::OrderCancelRequest &message,
LOG(ExSim, Info, "Got order cancellation for: {}", origClOrdID.getString());
try {
processCancel(origClOrdID, sec_desc, convert(side));
m_orderMatcher.display();
update_md(sec_desc);
} catch (std::exception &) {
}
}
@@ -316,20 +317,46 @@ ExchangeSimApplication::ExchangeSimApplication() :
producer(co2::PLATFORM_SIM),
handles()
{
// std::set<md::UserSymbol> symbols;
// md::get_system_md_symbols(symbols);
// md::db::load_securities(symbols, [this](const api::Security &s) {
// if (s.exchange() == api::VENUE_GLBX) {
// auto new_s = s;
// *new_s.mutable_glbx()->mutable_security_desc() = std::string("sim:") + s.glbx().security_desc();
// *new_s.mutable_symbol() = std::string("sim:") + s.symbol();
// md::FixedSecurity fs;
// md::convert_security(new_s, fs, true);
// md::MDProducerHandle handle = producer.add_security(fs);
// auto sec_desc = securities::descriptor(s);
// handles.insert(make_pair(sec_desc,handle));
// }
// });
std::set<md::UserSymbol> symbols;
md::get_system_md_symbols(symbols);
md::db::load_securities(symbols, [this](const api::Security &s) {
if (s.exchange() == api::VENUE_GLBX) {
md::with_security_like(s,[this,s] (auto &fs) {
auto new_s = s;
*new_s.mutable_glbx()->mutable_security_desc() = std::string("sim:") + s.glbx().security_desc();
*new_s.mutable_symbol() = std::string("sim:") + s.symbol();
md::convert_security(new_s, fs, true);
md::MDProducerHandle handle = producer.add_security(fs);
auto sec_desc = securities::descriptor(s);
handles.insert(make_pair(sec_desc,handle));
});
}});
}
void ExchangeSimApplication::update_md(std::string const&sec_desc)
{
auto it = handles.find(sec_desc);
if (it != handles.end()) {
auto &handle = it->second;
auto book = m_orderMatcher.get_book(sec_desc);
auto n_bids = book.bids.size();
for (uint i = 0; i < std::min(md::COCONUT_MAX_DEPTH,(uint32_t) n_bids); i++) {
auto psz = md::PriceSize::from_double<7> (book.bids[i].price, book.bids[i].size);
LOG(ExSim, Info, "Updating market data for {}. Depth: {} : Buy {}@{}",
sec_desc,i,book.bids[i].price,book.bids[i].size);
handle.update_bid (utils::TimeStamp::now(), psz,i);
}
auto n_asks = book.asks.size();
for (uint i = 0; i < std::min(md::COCONUT_MAX_DEPTH,(uint32_t) n_asks); i++) {
auto psz = md::PriceSize::from_double<7> (book.asks[i].price, book.asks[i].size);
LOG(ExSim, Info, "Updating market data for {}. Depth: {} : Sell {}@{}",
sec_desc,i,book.asks[i].price,book.asks[i].size);
handle.update_ask (utils::TimeStamp::now(), psz,i);
}
}
}
GCC_DIAG_RESTORE()