Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
exchange_registry.cpp
Go to the documentation of this file.
2
3using namespace slick::sim;
4using namespace slick::sim::exch;
5
6ExchangeRegistry &ExchangeRegistry::instance() {
7 // Construct on the first registration call to avoid depending on the order
8 // of namespace-scope initialisation across translation units.
9 static ExchangeRegistry registry;
10 return registry;
11}
12
13bool ExchangeRegistry::add(std::string_view key, Venue venue, Factory factory) {
14 entries_.push_back(Entry{std::string(key), venue, factory});
15 return true;
16}
17
18ExchangeRegistry::Factory ExchangeRegistry::find(std::string_view key) const noexcept {
19 for (const auto &entry : entries_) {
20 // The same comparison to_venue uses, so a config key resolves identically
21 // whether it is being turned into a Venue or into a factory.
22 if (detail::iequals(entry.key, key)) {
23 return entry.factory;
24 }
25 }
26 return nullptr;
27}
28
29std::vector<std::string> ExchangeRegistry::keys() const {
30 std::vector<std::string> out;
31 out.reserve(entries_.size());
32 for (const auto &entry : entries_) {
33 out.push_back(entry.key);
34 }
35 return out;
36}
Factory find(std::string_view key) const noexcept
nullptr when no adapter for this key was built into the binary.
std::vector< std::unique_ptr< Exchange > >(*)(const nlohmann::json &config) Factory
A plain function pointer, not std::function - no allocation, no <functional>.
std::vector< std::string > keys() const
Registered keys, in registration order - for the startup banner and for the error message on an unkno...
static ExchangeRegistry & instance()
bool add(std::string_view key, Venue venue, Factory factory)
key is matched case-insensitively, the same way to_venue matches a venue name.
bool iequals(std::string_view a, std::string_view b) noexcept
ASCII case-insensitive compare, used for every venue-name lookup.
Definition types.hpp:117
Helpers for a venue whose one config entry describes several independent exchange instances,...
Definition exchange.hpp:30