Files
spark/src/lib/md/SecurityCache.h
T

68 lines
1.9 KiB
C++

#pragma once
#include "MDConsumerHandle.h"
#include "SecurityPtr.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/md/ExchangeSecurityKey.h"
#include <memory>
namespace bts {
namespace md {
// Get security on demand
// Store security+handle
struct SecurityCacheImpl;
class SecurityCache {
std::shared_ptr<SecurityCacheImpl> _me;
public:
SecurityCache();
~SecurityCache();
// Load security from cache with fallback to database
const Security *get_security(SecurityKey key);
/**
* Finds the first security with matching @p venue and @p name. Params that are
* empty/unset are ignored.
*/
const Security *get_security(api::Venue venue, const std::string &name);
/**
* 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();
// Get the security if it's in the cache otherwise return nullptr. Does not
// query security database.
const Security *try_get_security(SecurityKey key) const;
const Security *try_get_security(ExchangeSecurityKey key) const;
// returns true if the cache was updated
bool add_live_security(const SecurityPtr &security);
void flush_to_disk();
};
} // namespace md
} // namespace bts