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
@@ -153,6 +153,7 @@ string dump_entry(const ColdEntry& entry) {
|
||||
if (has_value(entry.last_trade)) res << "'last_trade': " << dump(entry.last_trade) << ", ";
|
||||
if (entry.total_volume > 0) res << "'total_volume': " << entry.total_volume << ", ";
|
||||
if (entry.last_trade_time > 0) res << "'last_trade_time_ll': " << entry.last_trade_time << ", ";
|
||||
// Reminder: settlement price is in hot
|
||||
if (entry.misc.settlement_date.year > 0) res << "'settlement_date': " << dump(entry.misc.settlement_date) << ", ";
|
||||
if (!(entry.misc.previous_settlement_price.is_nan())) res << "'previous_settlement_price': " << entry.misc.previous_settlement_price.price() << ", ";
|
||||
if (entry.misc.previous_settlement_date.year > 0) res << "'previous_settlement_date': " << dump(entry.misc.previous_settlement_date) << ", ";
|
||||
|
||||
@@ -46,6 +46,7 @@ message SecurityChannel {
|
||||
int64 trade_cursor = 6;
|
||||
int64 rfq_cursor = 7;
|
||||
uint64 segment_id = 8;
|
||||
bool entitled = 9;
|
||||
}
|
||||
|
||||
message MDRequest {
|
||||
@@ -62,8 +63,8 @@ message MDRequest {
|
||||
IMPLIED = 0x40;
|
||||
}
|
||||
string host = 2;
|
||||
// bytes token = 3;
|
||||
reserved 3;
|
||||
// bytes token = 3;
|
||||
reserved 3;
|
||||
}
|
||||
|
||||
message ChannelUpdate {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +269,7 @@ public:
|
||||
req.exchange() == reply.channel().exchange() &&
|
||||
req.symbol() == reply.channel().symbol()) {
|
||||
|
||||
req.set_entitled(reply.channel().entitled());
|
||||
req.set_time(reply.channel().time());
|
||||
req.set_trade_cursor(reply.channel().trade_cursor());
|
||||
req.set_rfq_cursor(reply.channel().rfq_cursor());
|
||||
|
||||
@@ -1298,6 +1298,7 @@ struct Co2RelayTests {
|
||||
chan->set_symbol(symbol);
|
||||
chan->set_exchange(VENUE_BTS);
|
||||
chan->set_flags(co2::MDRequest::BBO | co2::MDRequest::SECURITY);
|
||||
chan->set_entitled(true);
|
||||
}
|
||||
|
||||
// This request should include everything
|
||||
|
||||
Reference in new issue
Block a user