fixed ice entitlements

This commit is contained in:
Kevin Darby committed 2019-09-16 15:53:50 -04:00
1 parent e6ab7d825a
commit bf8323e79b
6 files changed
+102 -60

No files matched your search

+43 -45
View File
@@ -78,7 +78,8 @@ struct MDConsumerGroup {
symbol(symbol),
platform(platform_for_exchange(symbol.exchange())),
channel(consumer.get_channel(symbol)),
handles()
handles(),
mic()
{
set_consumer(consumer);
@@ -118,9 +119,34 @@ struct MDConsumerGroup {
bts_assert_d(handle.is_initialized());
bts_assert(handle.get_usersymbol() == symbol);
DatedHandle h = { TimeStamp::now(), handle };
handles->push_back(h);
handles->push_back(h);
if(this->mic == "")
set_mic(h);
}
void set_mic(const DatedHandle& h)
{
if(channel.exchange() == api::VENUE_ICE || channel.exchange() == api::VENUE_SIMICE)
{
this->mic = h.handle.get_normalized_security().ice().mic_code();
}
else if(channel.exchange() == api::VENUE_GLBX || channel.exchange() == api::VENUE_SIM)
{
const auto& cme_symb_mics = config::get<config::CmeSymbolMics>().cme_mic();
for(auto mic=cme_symb_mics.begin();mic!=cme_symb_mics.end();mic++)
{
const auto& micsym = mic->first;
if(micsym == symbol.symbol())
{
this->mic = api::CMEMics_Name(mic->second);
break;
}
}
}
else
bts_assert_msg(false, "unknown venue in QueryServer");
}
UserSymbol symbol;
Platform platform;
MDConsumerChannel channel;
@@ -128,7 +154,7 @@ struct MDConsumerGroup {
// Can add to handles without invalidating readers (no lock needed)
// When we recover we swap a new vector into this unique_ptr and delayed-delete
shared_ptr<ConcurrentAppendCollection<DatedHandle>> handles;
std::string mic;
};
void convert(PriceSize ps, PriceSizeMessage* pps) {
@@ -222,13 +248,14 @@ public:
void fill(const SecurityChannel& chan, MDConsumerGroup& group, ChannelReply* reply,
const Entitlements* entitlements, bool bypass_entitlement) const {
bts_assert(reply);
bool entitled = bypass_entitlement || chan.exchange() == api::VENUE_BTS ||
(chan.exchange() == api::VENUE_GLBX && entitlements && entitlements->count(chan.symbol()));
reply->mutable_channel()->CopyFrom(chan);
reply->set_platform(group.platform);
reply->mutable_channel()->set_time(TimeStamp::now().to_uint64());
reply->mutable_channel()->set_entitled(entitled);
bool entitled = bypass_entitlement;
if(entitlements && !entitled)
entitled = entitlements->count(group.mic);
reply->mutable_channel()->set_entitled(entitled);
auto flags = (MDRequest::Flags)chan.flags();
// Get a copy of handles. If recovery happens during this call
@@ -251,12 +278,6 @@ public:
auto security = handle.get_normalized_security();
pupd->mutable_security()->CopyFrom(security);
snapshot = true;
if(!entitled && (chan.exchange() == api::VENUE_ICE || chan.exchange() == api::VENUE_SIMICE))
{
entitled = entitlements && entitlements->count("ICE:" + security.ice().mic_code());
if(entitled)
reply->mutable_channel()->set_entitled(entitled);
}
}
//if we are not entitled AND this is the first request since we lost our entitlement, zero out books
if (!entitled && chan.entitled() ) {
@@ -548,44 +569,21 @@ QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, MDClient& c
container->admin_client.subscribe_md_entitlement_data().subscribe([=](const api::admin::Md_entitlement_dataUpdate& update) {
const auto& all_updates = update.all();
utils::Dispatcher::background().post([all_updates, container]()
{
const auto& cme_symb_mics = config::get<config::CmeSymbolMics>().cme_mic();
{
auto entitlements = std::make_shared<std::unordered_map<uint32_t, Entitlements>>();
for (const auto& row : all_updates)
{
if (row && row->enabled())
{
for(auto mic=cme_symb_mics.begin();mic!=cme_symb_mics.end();mic++)
{
if(api::CMEMics_Name(mic->second) == row->mic())
{
const auto& symbol = mic->first;
auto iter = entitlements->find(row->user_id());
if (iter == entitlements->end()) {
Entitlements ents;
ents.insert(symbol);
ents.insert("SIM:" + symbol);
entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents)));
}
else {
iter->second.insert(symbol);
iter->second.insert("SIM:" + symbol);
}
}
}
api::ICEMics icemic;
if(api::ICEMics_Parse(row->mic(), &icemic)) //this is an ice mic, just put the mic in the set and resolve later
{
auto iter = entitlements->find(row->user_id());
if (iter == entitlements->end()) {
Entitlements ents;
ents.insert("ICE:" + row->mic());
entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents)));
}
else {
iter->second.insert("ICE:" + row->mic());
}
auto iter = entitlements->find(row->user_id());
if (iter == entitlements->end()) {
Entitlements ents;
ents.insert(row->mic());
entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents)));
}
else {
iter->second.insert(row->mic());
}
}
}
container->relay.update_entitlements(entitlements);