diff --git a/hikyuu_cpp/hikyuu/Stock.cpp b/hikyuu_cpp/hikyuu/Stock.cpp index bee6b7ea..8a9f13ce 100644 --- a/hikyuu_cpp/hikyuu/Stock.cpp +++ b/hikyuu_cpp/hikyuu/Stock.cpp @@ -276,8 +276,16 @@ void Stock::loadKDataToBuffer(KQuery::KType inkType) { if (m_kdataDriver) { m_data->pKData[kType] = new KRecordList; m_data->pMutex[kType] = new std::shared_mutex(); + const auto& param = StockManager::instance().getPreloadParameter(); + string preload_type = fmt::format("{}_max", kType); + to_lower(preload_type); + int max_num = param.tryGet(preload_type, 5120); + HKU_ERROR_IF_RETURN(max_num < 0, void(), "Invalid preload {} param: {}", preload_type, + max_num); + size_t total = m_kdataDriver->getCount(m_data->m_market, m_data->m_code, kType); + int start = total <= max_num ? 0 : total - max_num; *(m_data->pKData[kType]) = m_kdataDriver->getKRecordList( - m_data->m_market, m_data->m_code, KQuery(0, Null(), kType)); + m_data->m_market, m_data->m_code, KQuery(start, Null(), kType)); } } } diff --git a/hikyuu_cpp/hikyuu/StockManager.cpp b/hikyuu_cpp/hikyuu/StockManager.cpp index 153b7216..7036f426 100644 --- a/hikyuu_cpp/hikyuu/StockManager.cpp +++ b/hikyuu_cpp/hikyuu/StockManager.cpp @@ -282,8 +282,13 @@ Stock StockManager::addTempCsvStock(const string& code, const string& day_filena KDataTempCsvDriver* p = new KDataTempCsvDriver(day_filename, min_filename); result.setKDataDriver(KDataDriverPtr(p)); - result.loadKDataToBuffer(KQuery::DAY); - result.loadKDataToBuffer(KQuery::MIN); + const auto& preload_param = getPreloadParameter(); + if (preload_param.tryGet("day", true)) { + result.loadKDataToBuffer(KQuery::DAY); + } + if (preload_param.tryGet("min", false)) { + result.loadKDataToBuffer(KQuery::MIN); + } return loadStock(result) ? result : Null(); } diff --git a/hikyuu_cpp/hikyuu/hikyuu.cpp b/hikyuu_cpp/hikyuu/hikyuu.cpp index 547f2c38..2543d240 100644 --- a/hikyuu_cpp/hikyuu/hikyuu.cpp +++ b/hikyuu_cpp/hikyuu/hikyuu.cpp @@ -9,6 +9,7 @@ #define NOMINMAX #endif +#include #include #include "utilities/IniParser.h" #include "hikyuu.h" @@ -62,8 +63,14 @@ void hikyuu_init(const string& config_file_name, bool ignore_preload) { } option = config.getOptionList("preload"); + for (auto iter = option->begin(); iter != option->end(); ++iter) { - preloadParam.set(*iter, ignore_preload ? false : config.getBool("preload", *iter)); + try { + preloadParam.set(*iter, + ignore_preload ? false : config.getBool("preload", *iter)); + } catch (...) { + preloadParam.set(*iter, ignore_preload ? false : config.getInt("preload", *iter)); + } } StockManager& sm = StockManager::instance(); diff --git a/test_data/hikyuu_linux.ini b/test_data/hikyuu_linux.ini index d440aaa9..ca559810 100644 --- a/test_data/hikyuu_linux.ini +++ b/test_data/hikyuu_linux.ini @@ -12,12 +12,29 @@ dir = ./test_data/block self = self.ini [preload] -day = 1 -week = 0 -month = 0 -quarter = 0 -halfyear = 0 -year = 0 +day = True +week = False +month = False +quarter = False +halfyear = False +year = False +min = False +min5 = False +min15 = False +min30 = False +min60 = False +day_max = 100000 +week_max = 100000 +month_max = 100000 +quarter_max = 100000 +halfyear_max = 100000 +year_max = 100000 +min_max = 5120 +min5_max = 5120 +min15_max = 5120 +min30_max = 5120 +min60_max = 5120 + [baseinfo] type = sqlite3 diff --git a/test_data/hikyuu_win.ini b/test_data/hikyuu_win.ini index e6e0fc2e..5ed0c1fa 100644 --- a/test_data/hikyuu_win.ini +++ b/test_data/hikyuu_win.ini @@ -12,12 +12,28 @@ dir = .\\test_data\\block self = self.ini [preload] -day = 1 -week = 0 -month = 0 -quarter = 0 -halfyear = 0 -year = 0 +day = True +week = False +month = False +quarter = False +halfyear = False +year = False +min = False +min5 = False +min15 = False +min30 = False +min60 = False +day_max = 100000 +week_max = 100000 +month_max = 100000 +quarter_max = 100000 +halfyear_max = 100000 +year_max = 100000 +min_max = 5120 +min5_max = 5120 +min15_max = 5120 +min30_max = 5120 +min60_max = 5120 [baseinfo] type = sqlite3