Add: Johns changes to sec oracle

This commit is contained in:
Mohammad Arham committed 2024-12-17 14:47:37 +00:00
1 parent 85a46727be
commit 3a90ca9cb5
4 files changed
+91

No files matched your search

+52
View File
@@ -1,6 +1,7 @@
#include "SecurityCache.h"
#include "SecurityDB.h"
#include "lib/domain_model/Security.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/logging/logging.h"
#include "lib/utils/Dispatcher.h"
#include "lib/utils/LockBox.h"
@@ -86,6 +87,57 @@ const Security *SecurityCache::get_security(SecurityKey key) {
return result;
}
const Security *SecurityCache::get_security(
api::Venue venue, api::SecurityType type, const std::string &name) {
const Security *result = nullptr;
_me->cache.lock([&result, venue, type, name](auto &cache) {
for (auto const &p : cache) {
if ((type == api::SECURITYTYPE_UNSET ||
type == securities::security_type(p.second->Contract_case())) &&
(venue == api::VENUE_UNSET && venue == p.second->exchange()) &&
(name.empty() || name == securities::descriptor(*p.second))) {
result = p.second.get();
break;
}
}
});
return result;
}
std::vector<const Security *> SecurityCache::get_securities(
api::Venue venue, api::SecurityType type, const std::string &name) {
std::vector<api::Security const *> result;
_me->cache.lock([&result, venue, type, name](auto &cache) {
const bool all_types = type == api::SECURITYTYPE_UNSET;
const bool all_venues = venue == api::VENUE_UNSET;
const bool all_names = name.empty();
for (auto const &p : cache) {
const auto &s = *p.second;
if ((all_types ||
type == securities::security_type(s.Contract_case())) &&
(all_venues || venue == s.exchange()) &&
(all_names || name == securities::descriptor(s))) {
result.push_back(p.second.get());
}
}
});
return result;
}
std::vector<const Security *> SecurityCache::get_securities(
std::function<bool(const Security &)> include) {
std::vector<api::Security const *> result;
_me->cache.lock([&result, include](auto &cache) {
for (auto const &p : cache) {
auto &s = *p.second;
if (include(s)) {
result.push_back(&s);
}
}
});
return result;
}
std::vector<api::Security const *> SecurityCache::get_securities() {
std::vector<api::Security const *> result;
result.reserve(100000);