Fix SecurityIDRecorder for spreads which have unresolved legs.

This commit is contained in:
Eric Harding committed 2018-02-20 15:42:51 -05:00
1 parent 2a4923cbed
commit 239d641989
1 file changed
+28 -4
+28 -4
View File
@@ -89,15 +89,39 @@ void SecurityIDRecorder::do_work() {
work_db();
}
bool has_all_leg_keys(const MDProducerHandle& handle) {
if (handle.security().type == SecurityType::SECURITYTYPE_SPREAD) {
const FixedSpreadSecurityXL* pspread = static_cast<const FixedSpreadSecurityXL*>(&handle.security());
for (size_t x = 0; x < pspread->leg_count(); ++x) {
if (pspread->legs[x].key == invalid_security_key) {
return false;
}
}
}
// SyntheticFixedSecurity is guarunteed to have all of its legs
return true;
}
void SecurityIDRecorder::work_handles() {
Security security;
MDProducerHandle handle;
vector<MDProducerHandle> retry;
while (_self->pending_handle.try_pop(handle)) {
security.Clear();
convert_security(handle.security(), &security);
assign_key(security, [handle](const api::Security& security) mutable {
handle.set_key(security.id());
});
// if a spread does not have all of its legs we need to wait
if (!has_all_leg_keys(handle)) {
retry.push_back(handle);
}
else {
convert_security(handle.security(), &security);
assign_key(security, [handle](const api::Security& security) mutable {
handle.set_key(security.id());
});
}
}
for(const auto& h : retry) {
_self->pending_handle.push(h);
}
}