Simulted Exchange base classes added
This commit is contained in:
1 parent
118ca7248d
commit
cda3d18838
6 files changed
+208
-8
No files matched your search
+11
-4
@@ -5,6 +5,7 @@
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/md/MDClient.h"
|
||||
#include "lib/md/MDProducer.h"
|
||||
#include "lib/orderman/CancelOrderMsg.h"
|
||||
#include "lib/orderman/CancelReplaceOrderMsg.h"
|
||||
#include "lib/orderman/CreateOrderMsg.h"
|
||||
@@ -34,8 +35,7 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace bts::orderman {
|
||||
|
||||
struct SimExecutionGateway::PImpl {
|
||||
PImpl(md::SecurityOracle o, bts::md::MDClient &md_client)
|
||||
@@ -54,6 +54,7 @@ struct SimExecutionGateway::PImpl {
|
||||
TimeStamp connection_time;
|
||||
md::SecurityOracle sec_oracle;
|
||||
bts::md::MDClient &md_client;
|
||||
bts::md::MDProducer *md_producer = nullptr;
|
||||
std::vector<OrderMsg> buffered_msgs = {};
|
||||
unsigned long exchange_oid = 0;
|
||||
std::vector<ExecutionReport> exe_reports = {};
|
||||
@@ -197,5 +198,11 @@ OnExchangeOpenOrdersState &SimExecutionGateway::on_exchange_open_orders() {
|
||||
return me->on_exchange_open_orders;
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
void SimExecutionGateway::set_producer(
|
||||
bts::api::Venue, bts::md::MDProducer &md_producer) {
|
||||
me->md_producer = &md_producer;
|
||||
}
|
||||
|
||||
void SimExecutionGateway::do_work() {}
|
||||
|
||||
} // namespace bts::orderman
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "IExecutionGateway.h"
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/md/MDClient.h"
|
||||
#include "lib/md/MDProducer.h"
|
||||
#include "lib/orderman/gateways/IExecutionGateway.h"
|
||||
|
||||
namespace bts::md {
|
||||
class MDClient;
|
||||
@@ -13,8 +13,6 @@ class MDProducer;
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
// Wrapper around EM's order gateway. There are fix overtones to this, that are
|
||||
// ignored
|
||||
class SimExecutionGateway : public IExecutionGateway {
|
||||
public:
|
||||
SimExecutionGateway(md::SecurityOracle, bts::md::MDClient &md_client);
|
||||
@@ -34,10 +32,12 @@ class SimExecutionGateway : public IExecutionGateway {
|
||||
OnExchangeOpenOrdersState &on_exchange_open_orders() override;
|
||||
|
||||
void set_producer(bts::api::Venue venue, bts::md::MDProducer &md_producer);
|
||||
void do_work();
|
||||
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
PImpl *me;
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "SimExecutionGatewayFactory.h"
|
||||
#include "SimExecutionGateway.h"
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/md/MDClient.h"
|
||||
#include "lib/md/common.h"
|
||||
#include "lib/utils/LockBox.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
SimExecutionGatewayFactory *SimExecutionGatewayFactory::instance = nullptr;
|
||||
std::once_flag SimExecutionGatewayFactory::flag;
|
||||
|
||||
SimExecutionGatewayFactory::SimExecutionGatewayFactory(
|
||||
bts::md::MDClient &md_client)
|
||||
: md_client(md_client), gateway_map() {
|
||||
LOG(OrderMan, Info,
|
||||
"SimExecutionGatewayFactory::SimExecutionGatewayFactory n_secs: {}",
|
||||
md_client.oracle().get_securities().size());
|
||||
}
|
||||
|
||||
std::shared_ptr<SimExecutionGateway> SimExecutionGatewayFactory::get_getayeway(
|
||||
api::Venue venue) {
|
||||
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>(
|
||||
md_client.oracle(), md_client)});
|
||||
it = data.find(venue);
|
||||
}
|
||||
rv = it->second;
|
||||
});
|
||||
bts_assert(rv != nullptr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
SimExecutionGatewayFactory::~SimExecutionGatewayFactory() {}
|
||||
|
||||
// singleton getter ///////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SimExecutionGatewayFactory::init_once(bts::md::MDClient &md_client) {
|
||||
std::call_once(
|
||||
flag, [&]() { instance = new SimExecutionGatewayFactory(md_client); });
|
||||
}
|
||||
SimExecutionGatewayFactory *SimExecutionGatewayFactory::get() {
|
||||
bts_assert(instance != nullptr);
|
||||
return instance;
|
||||
}
|
||||
|
||||
} // namespace bts::orderman
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/orderman/gateways/IExecutionGateway.h"
|
||||
#include "lib/utils/LockBox.h"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace bts::md {
|
||||
class MDClient;
|
||||
} // namespace bts::md
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
class SimExecutionGateway;
|
||||
|
||||
class SimExecutionGatewayFactory {
|
||||
private:
|
||||
bts::md::MDClient &md_client;
|
||||
bts::utils::LockBox<
|
||||
std::map<bts::md::Venue, std::shared_ptr<SimExecutionGateway>>>
|
||||
gateway_map;
|
||||
|
||||
private:
|
||||
SimExecutionGatewayFactory(bts::md::MDClient &md_client);
|
||||
|
||||
public:
|
||||
std::shared_ptr<SimExecutionGateway> get_getayeway(api::Venue);
|
||||
~SimExecutionGatewayFactory();
|
||||
// static //////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
static std::once_flag flag;
|
||||
static SimExecutionGatewayFactory *instance;
|
||||
|
||||
public:
|
||||
// this has to be called once before all usages
|
||||
static void init_once(bts::md::MDClient &);
|
||||
static SimExecutionGatewayFactory *get();
|
||||
};
|
||||
|
||||
} // namespace bts::orderman
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "SimExecutionGatewayUniqueWrapper.h"
|
||||
#include "SimExecutionGateway.h"
|
||||
#include "SimExecutionGatewayFactory.h"
|
||||
#include <memory>
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
struct SimExecutionGatewayUniqueWrapper::PImpl {
|
||||
std::shared_ptr<SimExecutionGateway> gateway;
|
||||
PImpl(std::shared_ptr<SimExecutionGateway> gateway_ptr)
|
||||
: gateway(gateway_ptr) {}
|
||||
};
|
||||
|
||||
SimExecutionGatewayUniqueWrapper::SimExecutionGatewayUniqueWrapper(
|
||||
bts::api::Venue venue)
|
||||
: me(new PImpl(SimExecutionGatewayFactory::get()->get_getayeway(venue))) {}
|
||||
|
||||
SimExecutionGatewayUniqueWrapper::~SimExecutionGatewayUniqueWrapper() {}
|
||||
// all these functions
|
||||
void SimExecutionGatewayUniqueWrapper::start() { me->gateway->start(); }
|
||||
void SimExecutionGatewayUniqueWrapper::dispatch_incoming_fix_messages() {
|
||||
me->gateway->dispatch_incoming_fix_messages();
|
||||
}
|
||||
void SimExecutionGatewayUniqueWrapper::on_securities(
|
||||
const mercury::Update<NewSecuritiesEvent> &u) {
|
||||
me->gateway->on_securities(u);
|
||||
}
|
||||
void SimExecutionGatewayUniqueWrapper::on_admin_data(
|
||||
const mercury::Update<NewAdminDataEvent> &u) {
|
||||
me->gateway->on_admin_data(u);
|
||||
}
|
||||
void SimExecutionGatewayUniqueWrapper::send_fix(
|
||||
const jetfix::OutFIXPtr &fix, trace::CorID trace) {
|
||||
me->gateway->send_fix(fix, trace);
|
||||
}
|
||||
void SimExecutionGatewayUniqueWrapper::send_msgs(
|
||||
std::vector<OrderMsg> const &msgs, trace::CorID cid) {
|
||||
me->gateway->send_msgs(msgs, cid);
|
||||
}
|
||||
|
||||
OnExeReport &SimExecutionGatewayUniqueWrapper::on_exe_report() {
|
||||
return me->gateway->on_exe_report();
|
||||
}
|
||||
OnGwStatusChange &SimExecutionGatewayUniqueWrapper::on_gw_status_change() {
|
||||
return me->gateway->on_gw_status_change();
|
||||
}
|
||||
OnCancelReject &SimExecutionGatewayUniqueWrapper::on_cancel_reject() {
|
||||
return me->gateway->on_cancel_reject();
|
||||
}
|
||||
OnExchangePositionState &
|
||||
SimExecutionGatewayUniqueWrapper::on_exchange_position_state() {
|
||||
return me->gateway->on_exchange_position_state();
|
||||
}
|
||||
OnExchangeOpenOrdersState &
|
||||
SimExecutionGatewayUniqueWrapper::on_exchange_open_orders() {
|
||||
return me->gateway->on_exchange_open_orders();
|
||||
}
|
||||
} // namespace bts::orderman
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "lib/orderman/gateways/IExecutionGateway.h"
|
||||
|
||||
namespace bts::orderman {
|
||||
|
||||
// Since ExecutionGatewyaFactory only returns std::unique_ptr<IExecutionGateway>
|
||||
// and we did not want to change that, this wrapper merely wraps around
|
||||
// SimExecutionGateway (which could not be wrapped in a unique_ptr)
|
||||
class SimExecutionGatewayUniqueWrapper : public IExecutionGateway {
|
||||
public:
|
||||
SimExecutionGatewayUniqueWrapper(bts::api::Venue venue);
|
||||
virtual ~SimExecutionGatewayUniqueWrapper();
|
||||
|
||||
void start() override;
|
||||
void dispatch_incoming_fix_messages() override;
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &) override;
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &) override;
|
||||
void send_fix(const jetfix::OutFIXPtr &fix, trace::CorID trace) override;
|
||||
void send_msgs(std::vector<OrderMsg> const &, trace::CorID) override;
|
||||
|
||||
OnExeReport &on_exe_report() override;
|
||||
OnGwStatusChange &on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
OnExchangePositionState &on_exchange_position_state() override;
|
||||
OnExchangeOpenOrdersState &on_exchange_open_orders() override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
PImpl *me;
|
||||
};
|
||||
|
||||
} // namespace bts::orderman
|
||||
Reference in new issue
Block a user