#include "TestPythonMdProviderCmd.h" #include "logging/logging.h" #include "python_md/md_sink_impl.h" #include "python_md/py_md_executor.h" #include #include #include #include using bts::md::py_interop::MdSinkImpl; using std::string; namespace bts::cmds { struct TestPythonMdProviderCmd::Args { std::string py_md_provider; std::vector module_paths; }; static void execute( std::string py_md_provider, std::vector 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()) { 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