Add: Johns changes to sec oracle
This commit is contained in:
1 parent
85a46727be
commit
3a90ca9cb5
4 files changed
+91
No files matched your search
@@ -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);
|
||||
|
||||
@@ -23,6 +23,26 @@ class SecurityCache {
|
||||
// Load security from cache with fallback to database
|
||||
const Security *get_security(SecurityKey key);
|
||||
|
||||
/**
|
||||
* Finds the first security with matching @p venue @p type and @p name. Params that
|
||||
* are empty/unset are ignored.
|
||||
*/
|
||||
const Security *get_security(
|
||||
api::Venue venue, api::SecurityType type, const std::string &name);
|
||||
|
||||
/**
|
||||
* Finds all securities with matching @p venue @p type and @p name. Params that
|
||||
* are empty/unset are ignored.
|
||||
*/
|
||||
std::vector<const Security *> get_securities(
|
||||
api::Venue venue, api::SecurityType type, const std::string &name);
|
||||
|
||||
/**
|
||||
* Finds all securities where @p include returns true.
|
||||
*/
|
||||
std::vector<const Security *> get_securities(
|
||||
std::function<bool(const Security &)> include);
|
||||
|
||||
// Load all securities from cache, no fallback to database
|
||||
std::vector<api::Security const *> get_securities();
|
||||
|
||||
|
||||
@@ -21,6 +21,16 @@ std::vector<api::Security const *> SecurityOracle::get_securities() const {
|
||||
return _cache.get_securities();
|
||||
}
|
||||
|
||||
std::vector<api::Security const *> SecurityOracle::get_securities(
|
||||
api::Venue venue, api::SecurityType type, const std::string &name) const {
|
||||
return _cache.get_securities(venue, type, name);
|
||||
}
|
||||
|
||||
std::vector<api::Security const *> SecurityOracle::get_securities(
|
||||
std::function<bool(const api::Security &)> include) const {
|
||||
return _cache.get_securities(include);
|
||||
}
|
||||
|
||||
void SecurityOracle::troubleshoot_log_all_securities() const {
|
||||
size_t sec_no = 0;
|
||||
for (const auto s : get_securities()) {
|
||||
|
||||
@@ -20,6 +20,15 @@ class SecurityOracle {
|
||||
~SecurityOracle();
|
||||
const api::Security *get_security(SecurityKey key) const;
|
||||
const api::Security *get_security(ExchangeSecurityKey key) const;
|
||||
|
||||
/**
|
||||
* Finds all securities where @p include returns true.
|
||||
*/
|
||||
std::vector<const Security *> get_securities(
|
||||
std::function<bool(const Security &)> include) const;
|
||||
std::vector<api::Security const *> get_securities(
|
||||
api::Venue venue, api::SecurityType type, const std::string &name) const;
|
||||
|
||||
std::vector<api::Security const *> get_securities() const;
|
||||
// this iterates through all securities and simply logs them. Use it
|
||||
// ONLY for troubleshooting
|
||||
|
||||
Reference in new issue
Block a user