Also moved a few logging deps from lib_spark -> system: * bts_chrono.h * bts_no_copy.h * defer.h * dispatcher.h/cpp * file_utils.h/cpp * type_name.h
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
#include "TestPythonMdProviderCmd.h"
|
|
#include "logging/logging.h"
|
|
#include "python_md/md_sink_impl.h"
|
|
#include "python_md/py_md_executor.h"
|
|
|
|
#include <pybind11/embed.h>
|
|
#include <pybind11/pybind11.h>
|
|
#include <string>
|
|
#include <thread>
|
|
|
|
using bts::md::py_interop::MdSinkImpl;
|
|
using std::string;
|
|
|
|
namespace bts::cmds {
|
|
|
|
struct TestPythonMdProviderCmd::Args {
|
|
std::string py_md_provider;
|
|
std::vector<std::string> module_paths;
|
|
};
|
|
|
|
static void execute(
|
|
std::string py_md_provider, std::vector<std::string> module_paths) {
|
|
using namespace std::chrono_literals;
|
|
MdSinkImpl sink;
|
|
sink.set_securities_callback([](const auto &securities) {
|
|
LOG(md, Info, "Received securities: {}", securities.to_string());
|
|
});
|
|
sink.set_books_callback([](const auto &books) {
|
|
LOG(md, Info, "Received books: {}", books.to_string());
|
|
});
|
|
sink.set_trades_callback([](const auto &trades) {
|
|
LOG(md, Info, "Received trades: {}", trades.to_string());
|
|
});
|
|
try {
|
|
md::py_interop::PyMdExecutor py_md_exec{
|
|
std::move(py_md_provider), std::move(module_paths), &sink};
|
|
LOG(md, Info, "Starting py md executor.");
|
|
py_md_exec.start();
|
|
LOG(md, Info, "Stopping py md executor.");
|
|
py_md_exec.stop();
|
|
int i = 0;
|
|
while (true) {
|
|
std::cout << "Sleep loop count " << ++i << std::endl;
|
|
std::this_thread::sleep_for(3s);
|
|
}
|
|
} catch (const std::exception &ex) {
|
|
LOG(md, Error, "Py md executor threw: {}", string{ex.what()});
|
|
}
|
|
}
|
|
|
|
TestPythonMdProviderCmd::TestPythonMdProviderCmd()
|
|
: CLI::App("Test python md provider plugin", "test-py-md-provider"),
|
|
args_(std::make_unique<Args>()) {
|
|
add_option(
|
|
"--provider", args_->py_md_provider,
|
|
"Python md provider plugin (py file)");
|
|
add_option(
|
|
"--module-path", args_->module_paths, "Module path for python plugin");
|
|
callback([this]() {
|
|
if (args_->py_md_provider.empty()) {
|
|
args_->py_md_provider = "md_provider_impl.MdProviderImpl";
|
|
}
|
|
if (args_->module_paths.empty()) {
|
|
args_->module_paths.push_back(".");
|
|
args_->module_paths.push_back("./python_md_providers");
|
|
}
|
|
execute(std::move(args_->py_md_provider), std::move(args_->module_paths));
|
|
});
|
|
}
|
|
|
|
TestPythonMdProviderCmd::~TestPythonMdProviderCmd() = default;
|
|
|
|
} // namespace bts::cmds
|