Files
spark/src/lib/orderman/gateways/sim/SimExecutionGatewayFactory.cpp
T

75 lines
2.4 KiB
C++

#include "SimExecutionGatewayFactory.h"
#include "SimExecutionGateway.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/logging/logging.h"
#include "lib/md/common.h"
#include "lib/utils/LockBox.h"
#include "lib/utils/bts_assert.h"
#include <chrono>
#include <memory>
#include <mutex>
namespace bts::orderman {
SimExecutionGatewayFactory *SimExecutionGatewayFactory::instance = nullptr;
std::once_flag SimExecutionGatewayFactory::flag;
SimExecutionGatewayFactory::SimExecutionGatewayFactory() : gateway_map() {
LOG(OrderMan, Info,
"SimExecutionGatewayFactory::SimExecutionGatewayFactory");
}
std::shared_ptr<SimExecutionGateway> SimExecutionGatewayFactory::get_getayeway(
api::Venue venue) {
LOG(OrderMan, Info, "SimExecutionGatewayFactory::get_getayeway venue: {}",
bts::api::Venue_Name(venue));
if (!is_sim_execution_on(venue)) {
LOG(OrderMan, Info,
"SimExecutionGatewayFactory::get_getayeway venue: {}, sim is turned "
"off",
bts::api::Venue_Name(venue));
return nullptr;
}
std::shared_ptr<SimExecutionGateway> rv = nullptr;
gateway_map.lock(
[&, venue](std::map<bts::md::Venue, std::shared_ptr<SimExecutionGateway>>
&data) {
auto it = data.find(venue);
if (it == data.end()) {
data.insert({venue, std::make_shared<SimExecutionGateway>(venue)});
it = data.find(venue);
}
rv = it->second;
});
bts_assert(rv != nullptr);
return rv;
}
SimExecutionGatewayFactory::~SimExecutionGatewayFactory() {}
// singleton getter ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SimExecutionGatewayFactory *SimExecutionGatewayFactory::get() {
std::call_once(flag, [&]() {
LOG(OrderMan, Info,
"SimExecutionGatewayFactory::init_once, initializing instance");
instance = new SimExecutionGatewayFactory();
});
bts_assert(instance != nullptr);
return instance;
}
bool SimExecutionGatewayFactory::is_sim_execution_on(api::Venue venue) {
// TODO: Arham, fix this !
return true;
const auto &sim_exec = config::get<bts::config::SimExecution>();
for (const auto &e : sim_exec.entries()) {
if (e.venue() == venue) {
return true;
}
}
return false;
}
} // namespace bts::orderman