4#include <slick/stream_buffer_multiplexer.hpp>
5#include <nlohmann/json.hpp>
14using json = nlohmann::json;
27 using Factory = std::shared_ptr<IBroker> (*)(
29 slick::stream_buffer_multiplexer& event_mux,
30 slick::queue<uint8_t>& control_queue,
31 slick::queue<uint8_t>& md_request_queue,
32 slick::queue<uint8_t>& order_request_queue);
39 bool add(std::string_view key,
Factory factory);
48 std::shared_ptr<IBroker>
create(std::string_view key,
const json& config,
49 slick::stream_buffer_multiplexer& event_mux,
50 slick::queue<uint8_t>& control_queue,
51 slick::queue<uint8_t>& md_request_queue,
52 slick::queue<uint8_t>& order_request_queue,
53 std::string& error)
const;
57 std::vector<std::string>
keys()
const;
60 BrokerRegistry() =
default;
66 std::vector<Entry> entries_;
79#define SLICK_TRADER_REGISTER_BROKER(key, BrokerType) \
81 ::std::shared_ptr<::slick::trader::IBroker> slick_trader_make_##BrokerType( \
82 const ::nlohmann::json& config, \
83 ::slick::stream_buffer_multiplexer& event_mux, \
84 ::slick::queue<uint8_t>& control_queue, \
85 ::slick::queue<uint8_t>& md_request_queue, \
86 ::slick::queue<uint8_t>& order_request_queue) { \
87 return ::std::make_shared<BrokerType>( \
88 config, event_mux, control_queue, md_request_queue, order_request_queue); \
90 [[maybe_unused]] const bool slick_trader_registered_##BrokerType = \
91 ::slick::trader::BrokerRegistry::instance().add(key, &slick_trader_make_##BrokerType); \
93 static_assert(true, "require a trailing semicolon")
static BrokerRegistry & instance()
std::shared_ptr< IBroker >(*)( const json &config, slick::stream_buffer_multiplexer &event_mux, slick::queue< uint8_t > &control_queue, slick::queue< uint8_t > &md_request_queue, slick::queue< uint8_t > &order_request_queue) Factory
A plain function pointer, not std::function - no allocation, no <functional>.
Factory find(std::string_view key) const noexcept
nullptr when no adapter for this key was built into the binary.
bool add(std::string_view key, Factory factory)
key is matched case-insensitively.
std::vector< std::string > keys() const
Registered keys, lowercased, in registration order - for the startup log and for the error on an unkn...
std::shared_ptr< IBroker > create(std::string_view key, const json &config, slick::stream_buffer_multiplexer &event_mux, slick::queue< uint8_t > &control_queue, slick::queue< uint8_t > &md_request_queue, slick::queue< uint8_t > &order_request_queue, std::string &error) const
Builds the broker registered under key.