SPARK-1934 - Settlement will fail to send to client when first request is not entitled
This commit is contained in:
1 parent
cbbd678112
commit
034aaa5b98
5 files changed
+76
-69
No files matched your search
@@ -230,6 +230,7 @@ public:
|
||||
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);
|
||||
auto flags = (MDRequest::Flags)chan.flags();
|
||||
|
||||
// Get a copy of handles. If recovery happens during this call
|
||||
@@ -252,78 +253,81 @@ public:
|
||||
snapshot = true;
|
||||
}
|
||||
if (entitled) {
|
||||
if (HASFLAG(flags, MDRequest::BBO) || HASFLAG(flags, MDRequest::DIRECT)) {
|
||||
std::array<PriceSize, COCONUT_MAX_DEPTH> bids, asks;
|
||||
// If we are entitled now but this is the first request where we are ensure we send all values
|
||||
if(!chan.entitled()) snapshot = true;
|
||||
|
||||
if (HASFLAG(flags, MDRequest::BBO) || HASFLAG(flags, MDRequest::DIRECT)) {
|
||||
std::array<PriceSize, COCONUT_MAX_DEPTH> bids, asks;
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
size_t copy_depth = HASFLAG(flags, MDRequest::DIRECT) ? COCONUT_MAX_DEPTH : 1;
|
||||
auto result = handle.get_direct_book(time, copy_depth, bids.data(), asks.data());
|
||||
if (result == HandleReadResult::SUCCESS) {
|
||||
auto* p = pupd->mutable_direct();
|
||||
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
PriceSize b = bids[x];
|
||||
if (b != NO_MARKET) {
|
||||
convert(b, p->add_bids());
|
||||
}
|
||||
PriceSize a = asks[x];
|
||||
if (a != NO_MARKET) {
|
||||
convert(a, p->add_asks());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (result == HandleReadResult::BUSY) {
|
||||
LOG(md,Info, "Busy read on handle {}. Retry on next request", instrument.handle.key());
|
||||
// If we get a busy reading BBO (which happens 1-2x per day for a single relay client)
|
||||
// We move the timestamp back so the next request will try to read this value again.
|
||||
// ALTERNATIVE: We could spin until the value was not busy but it could be that the writer
|
||||
// was context switched out and we will have to wait multiple ms to unblock the request.
|
||||
// This fix assumes it is better to send the update now with 1 stale value than to block the call
|
||||
// and allow all the values to be stale until this one can be read.
|
||||
reply->mutable_channel()->set_time(chan.time());
|
||||
}
|
||||
}
|
||||
if ((HASFLAG(flags, MDRequest::IMPLIED) || HASFLAG(flags, MDRequest::BBO)) && !handle.is_synthetic()) {
|
||||
std::array<PriceSize, COCONUT_MAX_IMPLIED_DEPTH> bids, asks;
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
size_t copy_depth = HASFLAG(flags, MDRequest::DIRECT) ? COCONUT_MAX_DEPTH : 1;
|
||||
auto result = handle.get_direct_book(time, copy_depth, bids.data(), asks.data());
|
||||
if (result == HandleReadResult::SUCCESS) {
|
||||
auto* p = pupd->mutable_direct();
|
||||
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
PriceSize b = bids[x];
|
||||
if (b != NO_MARKET) {
|
||||
convert(b, p->add_bids());
|
||||
}
|
||||
PriceSize a = asks[x];
|
||||
if (a != NO_MARKET) {
|
||||
convert(a, p->add_asks());
|
||||
size_t copy_depth = HASFLAG(flags, MDRequest::IMPLIED) ? COCONUT_MAX_IMPLIED_DEPTH : 1;
|
||||
auto result = handle.get_implied_book(time, copy_depth, bids.data(), asks.data());
|
||||
if (result == HandleReadResult::SUCCESS) {
|
||||
auto* p = pupd->mutable_implied();
|
||||
for (size_t x = 0; x < COCONUT_MAX_IMPLIED_DEPTH; ++x) {
|
||||
PriceSize b = bids[x];
|
||||
if (b != NO_MARKET) {
|
||||
convert(b, p->add_bids());
|
||||
}
|
||||
PriceSize a = asks[x];
|
||||
if (a != NO_MARKET) {
|
||||
convert(a, p->add_asks());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (result == HandleReadResult::BUSY) {
|
||||
LOG(md,Info, "Busy read on handle {}. Retry on next request", instrument.handle.key());
|
||||
// If we get a busy reading BBO (which happens 1-2x per day for a single relay client)
|
||||
// We move the timestamp back so the next request will try to read this value again.
|
||||
// ALTERNATIVE: We could spin until the value was not busy but it could be that the writer
|
||||
// was context switched out and we will have to wait multiple ms to unblock the request.
|
||||
// This fix assumes it is better to send the update now with 1 stale value than to block the call
|
||||
// and allow all the values to be stale until this one can be read.
|
||||
reply->mutable_channel()->set_time(chan.time());
|
||||
}
|
||||
}
|
||||
if ((HASFLAG(flags, MDRequest::IMPLIED) || HASFLAG(flags, MDRequest::BBO)) && !handle.is_synthetic()) {
|
||||
std::array<PriceSize, COCONUT_MAX_IMPLIED_DEPTH> bids, asks;
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
size_t copy_depth = HASFLAG(flags, MDRequest::IMPLIED) ? COCONUT_MAX_IMPLIED_DEPTH : 1;
|
||||
auto result = handle.get_implied_book(time, copy_depth, bids.data(), asks.data());
|
||||
if (result == HandleReadResult::SUCCESS) {
|
||||
auto* p = pupd->mutable_implied();
|
||||
for (size_t x = 0; x < COCONUT_MAX_IMPLIED_DEPTH; ++x) {
|
||||
PriceSize b = bids[x];
|
||||
if (b != NO_MARKET) {
|
||||
convert(b, p->add_bids());
|
||||
}
|
||||
PriceSize a = asks[x];
|
||||
if (a != NO_MARKET) {
|
||||
convert(a, p->add_asks());
|
||||
}
|
||||
else if (result == HandleReadResult::BUSY) {
|
||||
LOG(md,Info, "Busy read on handle (implied) {}. Retry on next request", instrument.handle.key());
|
||||
reply->mutable_channel()->set_time(chan.time());
|
||||
}
|
||||
}
|
||||
else if (result == HandleReadResult::BUSY) {
|
||||
LOG(md,Info, "Busy read on handle (implied) {}. Retry on next request", instrument.handle.key());
|
||||
reply->mutable_channel()->set_time(chan.time());
|
||||
if (HASFLAG(flags, MDRequest::LAST_TRADE)) {
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
PriceSize price;
|
||||
datetime::LLDateTime trade_time;
|
||||
size_t volume;
|
||||
if (handle.get_last_trade(time, price, trade_time, &volume)) {
|
||||
auto* trade = pupd->mutable_last_trade();
|
||||
trade->set_key(handle.key());
|
||||
trade->set_time(trade_time);
|
||||
trade->set_total_volume(volume);
|
||||
set_price(price, trade);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (HASFLAG(flags, MDRequest::LAST_TRADE)) {
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
PriceSize price;
|
||||
datetime::LLDateTime trade_time;
|
||||
size_t volume;
|
||||
if (handle.get_last_trade(time, price, trade_time, &volume)) {
|
||||
auto* trade = pupd->mutable_last_trade();
|
||||
trade->set_key(handle.key());
|
||||
trade->set_time(trade_time);
|
||||
trade->set_total_volume(volume);
|
||||
set_price(price, trade);
|
||||
if (HASFLAG(flags, MDRequest::MISC)) {
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
if (handle.misc_timestamp() > time) {
|
||||
copy_misc(handle.settlement_price(), handle.misc(), pupd->mutable_misc());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (HASFLAG(flags, MDRequest::MISC)) {
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
if (handle.misc_timestamp() > time) {
|
||||
copy_misc(handle.settlement_price(), handle.misc(), pupd->mutable_misc());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pupd->has_direct() ||
|
||||
pupd->has_implied() ||
|
||||
pupd->has_last_trade() ||
|
||||
@@ -359,9 +363,8 @@ public:
|
||||
if (groupiter != _groups.end()) {
|
||||
auto& group = groupiter->second;
|
||||
bool is_entitled = bypass_entitlement ||
|
||||
/*ch.exchange() == api::VENUE_SIM || */
|
||||
ch.exchange() == api::VENUE_BTS ||
|
||||
(entitlements && entitlements->count(ch.symbol()));
|
||||
ch.exchange() == api::VENUE_BTS ||
|
||||
(entitlements && entitlements->count(ch.symbol()));
|
||||
fill(ch, *group, reply->add_channels(), is_entitled);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user