#include "Run.h" #include "spark/api/public/ServiceContext.h" #include "spark/config/config.h" #include "spark/config/protos/ports.pb.h" #include "spark/config/protos/quickbus_cfg.pb.h" #include "spark/logging/logging.h" #include "spark/md/MBOProcessor.h" #include "spark/md/MBOServiceServer.h" #include "spark/md/MDClient.h" #include "spark/md/SyntheticSecurityService.h" #include "spark/md/relay/QueryServer.h" #include "spark/md/service/MarketDataServiceServer.h" #include "spark/metrics/metrics.h" #include "spark/metrics/system_metrics.h" #include "spark/orderman/OrderServiceServer.h" #include "spark/orderman/events/TradeSummarySignalDispatcher.h" #include "spark/orderman/order_factory/DynamicOrderRegistry.h" #include "spark/persistence/PersistenceServiceServer.h" #include "spark/plugin/SparkServices.h" #include "spark/plugin/plugin.h" #include "spark/quickbus/core/Quickbus.h" #include "spark/tracing/PerfLog.h" #include "spark/utils/Dispatcher.h" #include "md/cmds/Run.h" #include "sparkd/algo/AlgoDefinitionServiceServer.h" #include "sparkd/analytics/AnalyticsServiceServer.h" #include "sparkd/http/WebServer.h" #include "sparkd/md/MarketDataAuxiliaryServiceServer.h" #include "sparkd/md/recording/MDRecorder.h" #include "sparkd/position/MarginServiceServer.h" #include "sparkd/position/PositionServiceServer.h" #include "sparkd/position/import/BasePositionServiceServer.h" #include "sparkd/position/import/MoneyFileServiceServer.h" #include "sparkd/subprocess/SubProcessRunner.h" #include "sparkd/support/ErrorReportService.h" #include "sparkd/support/ShellLatencyServer.h" #include "sparkd/user/AdminServiceServer.h" #include "sparkd/user/AuthServiceServer.h" namespace bts::cmds { static void execute() { using namespace bts; LOG(Gen, Warn, "------------------------------------ Sparkd launched " "--------------------------------"); auto qb_cfg = config::get().node(); auto &ports = config::get(); qb_cfg.set_my_port(ports.qbus_port()); qbus::Quickbus quickbus( qb_cfg, qbus::QuickbusThreadOptions::DEFERRED_START); api::ServiceContext sc(&quickbus); trace::PerfLog perf_log; metrics::MetricsContainer stats; metrics::publish_system_metrics(stats); http::SparkWebServer webserver(sc, stats, perf_log, ports.config_port()); persistence::PersistenceServiceServer settings_saver(sc, "settings"); user::AuthServiceServer login_server(sc); bts::md::MBOProcessor mbo_processor; bts::md::TradeSummarySignalDispatcher tss_dispatcher; md::cmds::Run::run(); api::synthetic::SyntheticSecurityService synthetic_service(sc); bts::md::MDClient mdclient( &utils::Dispatcher::background(), &synthetic_service, &mbo_processor.reader()); bts::md::QueryServerPtr md_query_server( bts::md::run_query_server(sc, mdclient, stats)); bts::md::MBOServiceServer mboserver( sc, utils::Dispatcher::background(), mdclient); bts::md::MarketDataService mdserver(mdclient, sc, stats); // initialize order plugins orderman::DynamicOrderRegistry dyn_order_registry; SparkServices plugin_services(dyn_order_registry); plugin::init_plugins(plugin_services); // finished initializing order plugins orderman::OrderServiceServer order_service_server( sc, mdclient, dyn_order_registry, stats, perf_log, tss_dispatcher); support::ErrorReportServer error_report_service(sc); admin::AdminServiceServer admin_service(sc); bts::md::auxiliary::MarketDataAuxiliaryServiceServer md_aux_server(sc); bts::api::orderman::algo::AlgoDefinitionServiceServer algo_definition_server( sc); bts::analytics::AnalyticsServiceServer analytics_server(sc); position::BasePositionServiceServer base_pos_server(sc); position::MoneyFileServiceServer money_file_server(sc); position::PositionServiceServer position_service(sc, mdclient); position::MarginServiceServer margin_service(sc, mdclient); metrics::ShellLatencyServer shell_latency_service( sc, stats, utils::Dispatcher::background()); bts::md::recording::MDRecorder::start_recording(mdclient); auto bg_health = std::make_shared("spark_background_thread"); utils::DispatcherTimer timer(utils::Dispatcher::background(), 5000, [=]() { bg_health->increment(); }); timer.start(); utils::DispatcherTimer timer2(utils::Dispatcher::background(), 1000, [&]() { perf_log.store_log_entries(); }); timer2.start(); stats.publish(bg_health); subprocess::run_all(); quickbus.run(); } Run::Run() : CLI::App("Run default sparkd services", "run") { callback(execute); } } // namespace bts::cmds