feat: Add support for python md plugins
This commit is contained in:
1 parent
2b62668df8
commit
2e9b4c78f3
46 files changed
+2265
-11
No files matched your search
@@ -0,0 +1,73 @@
|
||||
#include "TestPythonMdProviderCmd.h"
|
||||
#include "python_md/md_sink_impl.h"
|
||||
#include "python_md/py_md_executor.h"
|
||||
#include "spark/logging/logging.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
|
||||
Reference in new issue
Block a user