diff --git a/hikyuu_cpp/hikyuu/StockManager.cpp b/hikyuu_cpp/hikyuu/StockManager.cpp index 1d25b72b..88d1ded9 100644 --- a/hikyuu_cpp/hikyuu/StockManager.cpp +++ b/hikyuu_cpp/hikyuu/StockManager.cpp @@ -480,6 +480,7 @@ void StockManager::loadAllHolidays() { } void StockManager::loadAllStockWeights() { + HKU_IF_RETURN(!m_hikyuuParam.tryGet("load_stock_weight", true), void()); HKU_INFO("Loading stock weight..."); if (m_context.isAll()) { auto all_stkweight_dict = m_baseInfoDriver->getAllStockWeightList(); @@ -511,10 +512,12 @@ void StockManager::loadAllZhBond10() { } void StockManager::loadHistoryFinanceField() { - auto fields = m_baseInfoDriver->getHistoryFinanceField(); - for (const auto& field : fields) { - m_field_ix_to_name[field.first - 1] = field.second; - m_field_name_to_ix[field.second] = field.first - 1; + if (m_hikyuuParam.tryGet("load_history_finance", true)) { + auto fields = m_baseInfoDriver->getHistoryFinanceField(); + for (const auto& field : fields) { + m_field_ix_to_name[field.first - 1] = field.second; + m_field_name_to_ix[field.second] = field.first - 1; + } } } @@ -531,10 +534,12 @@ vector> StockManager::getHistoryFinanceAllFields() con } void StockManager::loadHistoryFinance() { - auto* tg = getGlobalTaskGroup(); - std::lock_guard lock1(*m_stockDict_mutex); - for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) { - tg->submit([=]() { iter->second.getHistoryFinance(); }); + if (m_hikyuuParam.tryGet("load_history_finance", true)) { + auto* tg = getGlobalTaskGroup(); + std::lock_guard lock1(*m_stockDict_mutex); + for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) { + tg->submit([=]() { iter->second.getHistoryFinance(); }); + } } } diff --git a/hikyuu_cpp/hikyuu/global/GlobalTaskGroup.cpp b/hikyuu_cpp/hikyuu/global/GlobalTaskGroup.cpp index d7b7a1f3..746452d5 100644 --- a/hikyuu_cpp/hikyuu/global/GlobalTaskGroup.cpp +++ b/hikyuu_cpp/hikyuu/global/GlobalTaskGroup.cpp @@ -10,6 +10,7 @@ #include "hikyuu/GlobalInitializer.h" #include "hikyuu/utilities/Log.h" #include "GlobalTaskGroup.h" +#include "hikyuu/StockManager.h" namespace hku { @@ -18,13 +19,17 @@ static TaskGroup* g_threadPool; TaskGroup* getGlobalTaskGroup() { static std::once_flag oc; std::call_once(oc, [&]() { - auto cpu_num = std::thread::hardware_concurrency(); - if (cpu_num >= 4) { - cpu_num -= 2; - } else if (cpu_num > 1) { - cpu_num--; - } - g_threadPool = new TaskGroup(cpu_num); + // auto cpu_num = std::thread::hardware_concurrency(); + // if (cpu_num >= 4) { + // cpu_num -= 2; + // } else if (cpu_num > 1) { + // cpu_num--; + // } + const auto& param = StockManager::instance().getHikyuuParameter(); + size_t worker_num = + param.tryGet("commont_thread_pool_num", std::thread::hardware_concurrency()); + HKU_INFO("work_num: {}", worker_num); + g_threadPool = new TaskGroup(worker_num); }); return g_threadPool; } diff --git a/hikyuu_cpp/hikyuu/hikyuu.cpp b/hikyuu_cpp/hikyuu/hikyuu.cpp index e8cbb723..478c9776 100644 --- a/hikyuu_cpp/hikyuu/hikyuu.cpp +++ b/hikyuu_cpp/hikyuu/hikyuu.cpp @@ -46,6 +46,20 @@ void HKU_API getConfigFromIni(const string& config_file_name, Parameter& basePar hkuParam.set("datadir", config.get("hikyuu", "datadir", ".")); hkuParam.set("quotation_server", config.get("hikyuu", "quotation_server", "ipc:///tmp/hikyuu_real.ipc")); + // 加载权息数据 + hkuParam.set("load_stock_weight", config.getBool("hikyuu", "load_stock_weight", "True")); + + // 加载历史财务数据 + hkuParam.set("load_history_finance", + config.getBool("hikyuu", "load_history_finance", "True")); + + // 公共线程池线程数量 + size_t cpu_num = 2 * std::thread::hardware_concurrency(); + if (cpu_num > 30) { + cpu_num = 30; + } + hkuParam.set("commont_thread_pool_num", config.getInt("hikyuu", "commont_thread_pool_num", + fmt::format("{}", cpu_num))); IniParser::StringListPtr option = config.getOptionList("baseinfo"); for (auto iter = option->begin(); iter != option->end(); ++iter) { diff --git a/hikyuu_cpp/hikyuu/hikyuu.h b/hikyuu_cpp/hikyuu/hikyuu.h index f08808c5..27cb874a 100644 --- a/hikyuu_cpp/hikyuu/hikyuu.h +++ b/hikyuu_cpp/hikyuu/hikyuu.h @@ -35,6 +35,15 @@ namespace hku { void HKU_API hikyuu_init(const string& config_file_name, bool ignore_preload = false, const StrategyContext& context = StrategyContext({"all"})); +/** + * @brief 尝试从 ini 文件获取配置参数 + * @param config_file_name ini 文件名 + * @param baseParam [out] + * @param blockParam [out] + * @param kdataParam [out] + * @param preloadParam [out] + * @param hkuParam [out] + */ void HKU_API getConfigFromIni(const string& config_file_name, Parameter& baseParam, Parameter& blockParam, Parameter& kdataParam, Parameter& preloadParam, Parameter& hkuParam); diff --git a/hikyuu_cpp/hikyuu/strategy/Strategy.h b/hikyuu_cpp/hikyuu/strategy/Strategy.h index 756d491a..e59fa451 100644 --- a/hikyuu_cpp/hikyuu/strategy/Strategy.h +++ b/hikyuu_cpp/hikyuu/strategy/Strategy.h @@ -28,6 +28,7 @@ namespace hku { */ class HKU_API Strategy { CLASS_LOGGER_IMP(Strategy) + PARAMETER_SUPPORT public: Strategy();