diff --git a/cppcheck.cppcheck b/cppcheck.cppcheck index 82afb7661..f754eb7b3 100644 --- a/cppcheck.cppcheck +++ b/cppcheck.cppcheck @@ -1,14 +1,28 @@ cppcheck-cppcheck-build-dir - Unspecified false true false 10 - 100 + 1000 + + + + + + + + int64_t + int32_t + uint64_t + uint32_t + uint8_t + int8_t + + boost @@ -18,5 +32,9 @@ ConfigurationNotChecked toomanyconfigs unknownMacro + useStlAlgorithm + shadowFunction + missingIncludeSystem + missingInclude diff --git a/hikyuu_cpp/hikyuu/KData.cpp b/hikyuu_cpp/hikyuu/KData.cpp index daf32bbef..b0c1482fa 100644 --- a/hikyuu_cpp/hikyuu/KData.cpp +++ b/hikyuu_cpp/hikyuu/KData.cpp @@ -90,13 +90,13 @@ KData HKU_API getKData(const string& market_code, const KQuery& query) { } KData HKU_API getKData(const string& market_code, const Datetime& start, const Datetime& end, - KQuery::KType ktype, KQuery::RecoverType recoverType) { + const KQuery::KType& ktype, KQuery::RecoverType recoverType) { KQuery query(start, end, ktype, recoverType); return StockManager::instance().getStock(market_code).getKData(query); } -KData HKU_API getKData(const string& market_code, int64_t start, int64_t end, KQuery::KType ktype, - KQuery::RecoverType recoverType) { +KData HKU_API getKData(const string& market_code, int64_t start, int64_t end, + const KQuery::KType& ktype, KQuery::RecoverType recoverType) { KQuery query(start, end, ktype, recoverType); return StockManager::instance().getStock(market_code).getKData(query); } diff --git a/hikyuu_cpp/hikyuu/KData.h b/hikyuu_cpp/hikyuu/KData.h index 932ab9367..91ffabeee 100644 --- a/hikyuu_cpp/hikyuu/KData.h +++ b/hikyuu_cpp/hikyuu/KData.h @@ -134,7 +134,8 @@ KData HKU_API getKData(const string& market_code, const KQuery& query); * @ingroup StockManage */ KData HKU_API getKData(const string& market_code, const Datetime& start = Datetime::min(), - const Datetime& end = Null(), KQuery::KType ktype = KQuery::DAY, + const Datetime& end = Null(), + const KQuery::KType& ktype = KQuery::DAY, KQuery::RecoverType recoverType = KQuery::NO_RECOVER); /** @@ -147,7 +148,7 @@ KData HKU_API getKData(const string& market_code, const Datetime& start = Dateti * @ingroup StockManage */ KData HKU_API getKData(const string& market_code, int64_t start = 0, int64_t end = Null(), - KQuery::KType ktype = KQuery::DAY, + const KQuery::KType& ktype = KQuery::DAY, KQuery::RecoverType recoverType = KQuery::NO_RECOVER); inline KData::KData(const KData& x) : m_imp(x.m_imp) {} diff --git a/hikyuu_cpp/hikyuu/KQuery.cpp b/hikyuu_cpp/hikyuu/KQuery.cpp index 1c7969e0e..1aaa1bdfa 100644 --- a/hikyuu_cpp/hikyuu/KQuery.cpp +++ b/hikyuu_cpp/hikyuu/KQuery.cpp @@ -63,7 +63,7 @@ int32_t KQuery::getKTypeInMin(KType ktype) { return g_ktype2min.at(ktype); } -KQuery::KQuery(Datetime start, Datetime end, KType ktype, RecoverType recoverType) +KQuery::KQuery(Datetime start, Datetime end, const KType& ktype, RecoverType recoverType) : m_start(start == Null() ? (int64_t)start.number() : (int64_t)(start.number() * 100 + start.second())), m_end(end == Null() ? (int64_t)end.number() diff --git a/hikyuu_cpp/hikyuu/KQuery.h b/hikyuu_cpp/hikyuu/KQuery.h index 01ed32ea8..5b63dcc71 100644 --- a/hikyuu_cpp/hikyuu/KQuery.h +++ b/hikyuu_cpp/hikyuu/KQuery.h @@ -104,7 +104,7 @@ class HKU_API KQuery { * @param queryType 默认按索引方式查询 */ KQuery(int64_t start, // cppcheck-suppress [noExplicitConstructor] - int64_t end = Null(), KType dataType = DAY, + int64_t end = Null(), const KType& dataType = DAY, RecoverType recoverType = NO_RECOVER, QueryType queryType = INDEX) : m_start(start), m_end(end), @@ -122,7 +122,7 @@ class HKU_API KQuery { * @param recoverType 复权类型 */ KQuery(Datetime start, // cppcheck-suppress [noExplicitConstructor] - Datetime end = Null(), KType ktype = DAY, + Datetime end = Null(), const KType& ktype = DAY, RecoverType recoverType = NO_RECOVER); /** @@ -206,10 +206,10 @@ class HKU_API KQuery { * @ingroup StockManage* */ KQuery HKU_API KQueryByIndex(int64_t start = 0, int64_t end = Null(), - KQuery::KType dataType = KQuery::DAY, + const KQuery::KType& dataType = KQuery::DAY, KQuery::RecoverType recoverType = KQuery::NO_RECOVER); -inline KQuery KQueryByIndex(int64_t start, int64_t end, KQuery::KType dataType, +inline KQuery KQueryByIndex(int64_t start, int64_t end, const KQuery::KType& dataType, KQuery::RecoverType recoverType) { return KQuery(start, end, dataType, recoverType, KQuery::INDEX); } @@ -225,11 +225,11 @@ inline KQuery KQueryByIndex(int64_t start, int64_t end, KQuery::KType dataType, */ KQuery HKU_API KQueryByDate(const Datetime& start = Datetime::min(), const Datetime& end = Null(), - KQuery::KType dataType = KQuery::DAY, + const KQuery::KType& dataType = KQuery::DAY, KQuery::RecoverType recoverType = KQuery::NO_RECOVER); -inline KQuery KQueryByDate(const Datetime& start, const Datetime& end, KQuery::KType dataType, - KQuery::RecoverType recoverType) { +inline KQuery KQueryByDate(const Datetime& start, const Datetime& end, + const KQuery::KType& dataType, KQuery::RecoverType recoverType) { return KQuery(start, end, dataType, recoverType); } diff --git a/hikyuu_cpp/hikyuu/MarketInfo.cpp b/hikyuu_cpp/hikyuu/MarketInfo.cpp index 68f9aadde..e9f0213cf 100644 --- a/hikyuu_cpp/hikyuu/MarketInfo.cpp +++ b/hikyuu_cpp/hikyuu/MarketInfo.cpp @@ -15,9 +15,9 @@ HKU_API std::ostream& operator<<(std::ostream& os, const MarketInfo& market) { return os; } - string split(", "); - os << "MarketInfo(" << market.market() << split << market.name() << split - << market.description() << split << market.code() << split << market.lastDate() << ")"; + string sp(", "); + os << "MarketInfo(" << market.market() << sp << market.name() << sp << market.description() + << sp << market.code() << sp << market.lastDate() << ")"; return os; } @@ -28,10 +28,10 @@ string MarketInfo::toString() const { return os.str(); } - string split(", "); - os << "MarketInfo(" << m_market << split << m_name << split << m_description << split << m_code - << split << m_lastDate << split << m_openTime1.minutes() << split << m_closeTime1.minutes() - << split << m_openTime2.minutes() << split << m_closeTime2.minutes() << ")"; + string sp(", "); + os << "MarketInfo(" << m_market << sp << m_name << sp << m_description << sp << m_code << sp + << m_lastDate << sp << m_openTime1.minutes() << sp << m_closeTime1.minutes() << sp + << m_openTime2.minutes() << sp << m_closeTime2.minutes() << ")"; return os.str(); } diff --git a/hikyuu_cpp/hikyuu/Stock.cpp b/hikyuu_cpp/hikyuu/Stock.cpp index 370d2d310..8be2eb7c4 100644 --- a/hikyuu_cpp/hikyuu/Stock.cpp +++ b/hikyuu_cpp/hikyuu/Stock.cpp @@ -64,7 +64,7 @@ Stock::Data::Data() m_minTradeNumber(default_minTradeNumber), m_maxTradeNumber(default_maxTradeNumber) { const auto& ktype_list = KQuery::getAllKType(); - for (auto& ktype : ktype_list) { + for (const auto& ktype : ktype_list) { pKData[ktype] = nullptr; pMutex[ktype] = nullptr; } @@ -96,7 +96,7 @@ Stock::Data::Data(const string& market, const string& code, const string& name, m_market_code = m_market + m_code; const auto& ktype_list = KQuery::getAllKType(); - for (auto& ktype : ktype_list) { + for (const auto& ktype : ktype_list) { pMutex[ktype] = new std::shared_mutex(); pKData[ktype] = nullptr; } @@ -543,12 +543,12 @@ bool Stock::_getIndexRangeByDateFromBuffer(const KQuery& query, size_t& out_star return true; } -KRecord Stock::_getKRecordFromBuffer(size_t pos, KQuery::KType ktype) const { +KRecord Stock::_getKRecordFromBuffer(size_t pos, const KQuery::KType& ktype) const { std::shared_lock lock(*(m_data->pMutex[ktype])); return m_data->pKData[ktype]->at(pos); } -KRecord Stock::getKRecord(size_t pos, KQuery::KType kType) const { +KRecord Stock::getKRecord(size_t pos, const KQuery::KType& kType) const { HKU_IF_RETURN(!m_data, Null()); if (isBuffer(kType)) { return _getKRecordFromBuffer(pos, kType); @@ -560,7 +560,7 @@ KRecord Stock::getKRecord(size_t pos, KQuery::KType kType) const { return klist.size() > 0 ? klist[0] : Null(); } -KRecord Stock::getKRecord(const Datetime& datetime, KQuery::KType ktype) const { +KRecord Stock::getKRecord(const Datetime& datetime, const KQuery::KType& ktype) const { KRecord result; HKU_IF_RETURN(isNull(), result); diff --git a/hikyuu_cpp/hikyuu/Stock.h b/hikyuu_cpp/hikyuu/Stock.h index 7aeca433f..2790d5a20 100644 --- a/hikyuu_cpp/hikyuu/Stock.h +++ b/hikyuu_cpp/hikyuu/Stock.h @@ -145,10 +145,10 @@ class HKU_API Stock { bool getIndexRange(const KQuery& query, size_t& out_start, size_t& out_end) const; /** 获取指定索引的K线数据记录,未作越界检查 */ - KRecord getKRecord(size_t pos, KQuery::KType dataType = KQuery::DAY) const; + KRecord getKRecord(size_t pos, const KQuery::KType& dataType = KQuery::DAY) const; /** 根据数据类型(日线/周线等),获取指定日期的KRecord */ - KRecord getKRecord(const Datetime&, KQuery::KType ktype = KQuery::DAY) const; + KRecord getKRecord(const Datetime&, const KQuery::KType& ktype = KQuery::DAY) const; /** 获取K线数据 */ KData getKData(const KQuery&) const; @@ -221,7 +221,7 @@ class HKU_API Stock { // 以下函数属于基础操作添加了读锁 size_t _getCountFromBuffer(KQuery::KType ktype) const; - KRecord _getKRecordFromBuffer(size_t pos, KQuery::KType ktype) const; + KRecord _getKRecordFromBuffer(size_t pos, const KQuery::KType& ktype) const; KRecordList _getKRecordListFromBuffer(size_t start_ix, size_t end_ix, KQuery::KType ktype) const; bool _getIndexRangeByDateFromBuffer(const KQuery&, size_t&, size_t&) const; diff --git a/hikyuu_cpp/hikyuu/StockManager.cpp b/hikyuu_cpp/hikyuu/StockManager.cpp index 1613b598c..ad65f978a 100644 --- a/hikyuu_cpp/hikyuu/StockManager.cpp +++ b/hikyuu_cpp/hikyuu/StockManager.cpp @@ -115,8 +115,6 @@ void StockManager::init(const Parameter& baseInfoParam, const Parameter& blockPa m_marketInfoDict.clear(); m_stockTypeInfo.clear(); - string funcname(" [StockManager::init]"); - // 加载证券基本信息 m_baseInfoDriver = DataDriverFactory::getBaseInfoDriver(baseInfoParam); HKU_CHECK(m_baseInfoDriver, "Failed get base info driver!"); @@ -301,8 +299,8 @@ void StockManager::reload() { } for (auto& stk : can_not_parallel_stk_list) { - auto& ktype_list = KQuery::getAllKType(); - for (auto& ktype : ktype_list) { + const auto& ktype_list = KQuery::getAllKType(); + for (const auto& ktype : ktype_list) { if (stk.isBuffer(ktype)) { stk.loadKDataToBuffer(ktype); } @@ -539,12 +537,12 @@ void StockManager::loadAllHolidays() { void StockManager::loadAllStockWeights() { HKU_INFO("Loading stock weight..."); auto all_stkweight_dict = m_baseInfoDriver->getAllStockWeightList(); - std::lock_guard lock(*m_stockDict_mutex); + std::lock_guard lock1(*m_stockDict_mutex); for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) { auto weight_iter = all_stkweight_dict.find(iter->first); if (weight_iter != all_stkweight_dict.end()) { Stock& stock = iter->second; - std::lock_guard lock(stock.m_data->m_weight_mutex); + std::lock_guard lock2(stock.m_data->m_weight_mutex); stock.m_data->m_weightList.swap(weight_iter->second); } } diff --git a/hikyuu_cpp/hikyuu/StockTypeInfo.cpp b/hikyuu_cpp/hikyuu/StockTypeInfo.cpp index aa4ad86b8..b3cb4c19c 100644 --- a/hikyuu_cpp/hikyuu/StockTypeInfo.cpp +++ b/hikyuu_cpp/hikyuu/StockTypeInfo.cpp @@ -15,11 +15,11 @@ HKU_API std::ostream& operator<<(std::ostream& os, const StockTypeInfo& stockTyp return os; } - string split(", "); - os << "StockTypeInfo(" << stockTypeInfo.type() << split << stockTypeInfo.description() << split - << stockTypeInfo.tick() << split << stockTypeInfo.tickValue() << split - << stockTypeInfo.unit() << split << stockTypeInfo.precision() << split - << stockTypeInfo.minTradeNumber() << split << stockTypeInfo.maxTradeNumber() << ")"; + string sp(", "); + os << "StockTypeInfo(" << stockTypeInfo.type() << sp << stockTypeInfo.description() << sp + << stockTypeInfo.tick() << sp << stockTypeInfo.tickValue() << sp << stockTypeInfo.unit() + << sp << stockTypeInfo.precision() << sp << stockTypeInfo.minTradeNumber() << sp + << stockTypeInfo.maxTradeNumber() << ")"; return os; } @@ -30,10 +30,10 @@ string StockTypeInfo::toString() const { return os.str(); } - string split(", "); - os << "StockTypeInfo(" << m_type << split << m_description << split << m_tick << split - << m_tickValue << split << m_unit << split << m_precision << split << m_minTradeNumber - << split << m_maxTradeNumber << ")"; + string sp(", "); + os << "StockTypeInfo(" << m_type << sp << m_description << sp << m_tick << sp << m_tickValue + << sp << m_unit << sp << m_precision << sp << m_minTradeNumber << sp << m_maxTradeNumber + << ")"; return os.str(); } diff --git a/hikyuu_cpp/hikyuu/analysis/combinate.cpp b/hikyuu_cpp/hikyuu/analysis/combinate.cpp index 9704e7e18..cd79d5e0c 100644 --- a/hikyuu_cpp/hikyuu/analysis/combinate.cpp +++ b/hikyuu_cpp/hikyuu/analysis/combinate.cpp @@ -94,11 +94,11 @@ vector HKU_API combinateIndicatorAnalysisWithBlock( vector buf; for (size_t i = 0; i < count; i++) { buf.clear(); - for (size_t n = i * per_num, end = (i + 1) * per_num; n < end; n++) { - if (n >= stocks.size()) { + for (size_t j = i * per_num, end = (i + 1) * per_num; j < end; j++) { + if (j >= stocks.size()) { break; } - buf.emplace_back(stocks[n]); + buf.emplace_back(stocks[j]); } tasks.emplace_back(tg.submit([sgs, stks = std::move(buf), n_query = query, n_tm = tm->clone(), n_sys = sys->clone()]() { diff --git a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp index f0890c8f1..a004d001e 100644 --- a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp @@ -68,7 +68,7 @@ bool KDataDriver::init(const Parameter& params) { return _init(); } -size_t KDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) { +size_t KDataDriver::getCount(const string& market, const string& code, const KQuery::KType& kType) { HKU_INFO("The getCount method has not been implemented! (KDataDriver: {})", m_name); return 0; } diff --git a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h index 9805ff440..a0b06c095 100644 --- a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h @@ -77,7 +77,7 @@ class HKU_API KDataDriver { * @param kType K线类型 * @return */ - virtual size_t getCount(const string& market, const string& code, KQuery::KType kType); + virtual size_t getCount(const string& market, const string& code, const KQuery::KType& kType); /** * 获取指定日期范围对应的K线记录索引 diff --git a/hikyuu_cpp/hikyuu/data_driver/base_info/mysql/MySQLBaseInfoDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/base_info/mysql/MySQLBaseInfoDriver.cpp index be7d677ae..4915e15ec 100644 --- a/hikyuu_cpp/hikyuu/data_driver/base_info/mysql/MySQLBaseInfoDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/base_info/mysql/MySQLBaseInfoDriver.cpp @@ -251,7 +251,7 @@ std::unordered_set MySQLBaseInfoDriver::getAllHolidays() { auto con = m_pool->getConnect(); std::vector holidays; con->batchLoad(holidays); - for (auto &holiday : holidays) { + for (const auto &holiday : holidays) { try { result.insert(holiday.datetime()); } catch (std::exception &e) { diff --git a/hikyuu_cpp/hikyuu/data_driver/base_info/sqlite/SQLiteBaseInfoDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/base_info/sqlite/SQLiteBaseInfoDriver.cpp index db053d795..2a81a3cdc 100644 --- a/hikyuu_cpp/hikyuu/data_driver/base_info/sqlite/SQLiteBaseInfoDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/base_info/sqlite/SQLiteBaseInfoDriver.cpp @@ -325,7 +325,7 @@ std::unordered_set SQLiteBaseInfoDriver::getAllHolidays() { auto con = m_pool->getConnect(); std::vector holidays; con->batchLoad(holidays); - for (auto& holiday : holidays) { + for (const auto& holiday : holidays) { try { result.insert(holiday.datetime()); } catch (std::exception& e) { diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.cpp index f9da7c4ae..ec447123f 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.cpp @@ -80,7 +80,8 @@ void KDataTempCsvDriver::_get_title_column(const string& line) { } } -size_t KDataTempCsvDriver::getCount(const string& market, const string& code, KQuery::KType kType) { +size_t KDataTempCsvDriver::getCount(const string& market, const string& code, + const KQuery::KType& kType) { return getKRecordList(market, code, KQuery(0, Null(), kType)).size(); } @@ -138,7 +139,7 @@ KRecordList KDataTempCsvDriver::getKRecordList(const string& market, const strin KRecordList KDataTempCsvDriver::_getKRecordListByIndex(const string& market, const string& code, int64_t start_ix, int64_t end_ix, - KQuery::KType kType) { + const KQuery::KType& kType) { KRecordList result; string filename; diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.h b/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.h index fd21f68c9..745236d02 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.h @@ -50,7 +50,8 @@ class KDataTempCsvDriver : public KDataDriver { * @param kType K线类型 * @return */ - virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override; + virtual size_t getCount(const string& market, const string& code, + const KQuery::KType& kType) override; /** * 获取指定日期范围对应的K线记录索引 @@ -79,7 +80,7 @@ class KDataTempCsvDriver : public KDataDriver { string _get_filename(); KRecordList _getKRecordListByIndex(const string& market, const string& code, int64_t start_ix, - int64_t end_ix, KQuery::KType kType); + int64_t end_ix, const KQuery::KType& kType); private: string m_day_filename; diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp index ef81f6b10..6d98768c8 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.cpp @@ -87,7 +87,7 @@ H5KDataDriver::H5KDataDriver() : KDataDriver("hdf5"), m_h5DataType(H5::CompType( H5KDataDriver::~H5KDataDriver() {} bool H5KDataDriver::_init() { - //关闭HDF异常自动打印 + // 关闭HDF异常自动打印 H5::Exception::dontPrint(); StringList keys = m_params.getNameList(); @@ -272,7 +272,8 @@ bool H5KDataDriver::_getH5FileAndGroup(const string& market, const string& code, return true; } -size_t H5KDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) { +size_t H5KDataDriver::getCount(const string& market, const string& code, + const KQuery::KType& kType) { H5FilePtr h5file; H5::Group group; HKU_IF_RETURN(!_getH5FileAndGroup(market, code, kType, h5file, group), 0); @@ -331,10 +332,10 @@ bool H5KDataDriver::_getBaseIndexRangeByDate(const string& market, const string& H5::DataSet dataset; H5::DataSpace dataspace; - uint64_t start_number = query.startDatetime().number(); - uint64_t end_number = query.endDatetime().number(); hsize_t startpos = 0, endpos = 0; try { + uint64_t start_number = query.startDatetime().number(); + uint64_t end_number = query.endDatetime().number(); string tablename(market + code); CHECK_DATASET_EXISTS_RET(group, tablename, false); dataset = group.openDataSet(tablename); @@ -435,7 +436,8 @@ bool H5KDataDriver::_getOtherIndexRangeByDate(const string& market, const string assert(KQuery::WEEK == query.kType() || KQuery::MONTH == query.kType() || KQuery::QUARTER == query.kType() || KQuery::HALFYEAR == query.kType() || KQuery::YEAR == query.kType() || KQuery::MIN15 == query.kType() || - KQuery::MIN30 == query.kType() || KQuery::MIN60 == query.kType() || KQuery::HOUR2 == query.kType()); + KQuery::MIN30 == query.kType() || KQuery::MIN60 == query.kType() || + KQuery::HOUR2 == query.kType()); out_start = 0; out_end = 0; HKU_IF_RETURN(query.startDatetime() >= query.endDatetime(), false); @@ -558,7 +560,7 @@ KRecordList H5KDataDriver::getKRecordList(const string& market, const string& co } KRecordList H5KDataDriver::_getBaseKRecordList(const string& market, const string& code, - KQuery::KType kType, size_t start_ix, + const KQuery::KType& kType, size_t start_ix, size_t end_ix) { KRecordList result; H5FilePtr h5file; @@ -599,14 +601,14 @@ KRecordList H5KDataDriver::_getBaseKRecordList(const string& market, const strin HKU_WARN(e.what()); } catch (...) { - //忽略 + // 忽略 } return result; } KRecordList H5KDataDriver::_getIndexKRecordList(const string& market, const string& code, - KQuery::KType kType, size_t start_ix, + const KQuery::KType& kType, size_t start_ix, size_t end_ix) { KRecordList result; string tablename(format("{}{}", market, code)); @@ -678,7 +680,7 @@ KRecordList H5KDataDriver::_getIndexKRecordList(const string& market, const stri HKU_WARN("Invalid date! {}", e.what()); } catch (...) { - //忽略 + // 忽略 } return result; @@ -773,10 +775,10 @@ TimeLineList H5KDataDriver::_getTimeLine(const string& market, const string& cod H5::DataSet dataset; H5::DataSpace dataspace; - uint64_t start_number = start.number(); - uint64_t end_number = end.number(); hsize_t startpos = 0, endpos = 0; try { + uint64_t start_number = start.number(); + uint64_t end_number = end.number(); string tablename(market + code); CHECK_DATASET_EXISTS_RET(group, tablename, result); dataset = group.openDataSet(tablename); diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h index 89c37deac..15a03c011 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h @@ -38,7 +38,8 @@ class HKU_API H5KDataDriver : public KDataDriver { #endif } - virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override; + virtual size_t getCount(const string& market, const string& code, + const KQuery::KType& kType) override; virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, size_t& out_end) override; virtual KRecordList getKRecordList(const string& market, const string& code, @@ -62,10 +63,10 @@ class HKU_API H5KDataDriver : public KDataDriver { bool _getOtherIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, size_t& out_end); - KRecordList _getBaseKRecordList(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix); - KRecordList _getIndexKRecordList(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix); + KRecordList _getBaseKRecordList(const string& market, const string& code, + const KQuery::KType& kType, size_t start_ix, size_t end_ix); + KRecordList _getIndexKRecordList(const string& market, const string& code, + const KQuery::KType& kType, size_t start_ix, size_t end_ix); TimeLineList _getTimeLine(const string& market, const string& code, int64_t start, int64_t end); TimeLineList _getTimeLine(const string& market, const string& code, const Datetime& start, diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp index 0e0d088e2..0ae637383 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.cpp @@ -35,7 +35,7 @@ bool MySQLKDataDriver::_init() { } string MySQLKDataDriver ::_getTableName(const string& market, const string& code, - KQuery::KType ktype) { + const KQuery::KType& ktype) { string table = fmt::format("`{}_{}`.`{}`", market, KQuery::getKTypeName(ktype), code); to_lower(table); return table; @@ -54,7 +54,8 @@ KRecordList MySQLKDataDriver::getKRecordList(const string& market, const string& } KRecordList MySQLKDataDriver::_getKRecordList(const string& market, const string& code, - KQuery::KType kType, size_t start_ix, size_t end_ix) { + const KQuery::KType& kType, size_t start_ix, + size_t end_ix) { KRecordList result; HKU_IF_RETURN(start_ix >= end_ix, result); @@ -88,7 +89,7 @@ KRecordList MySQLKDataDriver::_getKRecordList(const string& market, const string } KRecordList MySQLKDataDriver::_getKRecordList(const string& market, const string& code, - KQuery::KType ktype, Datetime start_date, + const KQuery::KType& ktype, Datetime start_date, Datetime end_date) { KRecordList result; HKU_IF_RETURN(start_date >= end_date, result); @@ -122,7 +123,8 @@ KRecordList MySQLKDataDriver::_getKRecordList(const string& market, const string return result; } -size_t MySQLKDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) { +size_t MySQLKDataDriver::getCount(const string& market, const string& code, + const KQuery::KType& kType) { size_t result = 0; try { @@ -191,9 +193,9 @@ TimeLineList MySQLKDataDriver::_getTimeLineListByDate(const string& market, cons m_connect->transaction(); st->exec(); while (st->moveNext()) { - uint64_t date = 0; - double price = 0.0, vol = 0.0; try { + uint64_t date = 0; + double price = 0.0, vol = 0.0; st->getColumn(0, date, price, vol); result.emplace_back(Datetime(date), price, vol); } catch (const std::exception& e) { @@ -245,9 +247,9 @@ TimeLineList MySQLKDataDriver::_getTimeLineListByIndex(const string& market, con st->exec(); while (st->moveNext()) { - uint64_t date = 0; - double price = 0.0, vol = 0.0; try { + uint64_t date = 0; + double price = 0.0, vol = 0.0; st->getColumn(0, date, price, vol); result.emplace_back(Datetime(date), price, vol); } catch (const std::exception& e) { @@ -297,10 +299,10 @@ TransList MySQLKDataDriver::_getTransListByDate(const string& market, const stri m_connect->transaction(); st->exec(); while (st->moveNext()) { - uint64_t date = 0; - double price = 0.0, vol = 0.0; - int direct = 0; try { + uint64_t date = 0; + double price = 0.0, vol = 0.0; + int direct = 0; st->getColumn(0, date, price, vol, direct); result.emplace_back(Datetime(date), price, vol, static_cast(direct)); @@ -353,10 +355,10 @@ TransList MySQLKDataDriver::_getTransListByIndex(const string& market, const str st->exec(); while (st->moveNext()) { - uint64_t date = 0; - double price = 0.0, vol = 0.0; - int direct = 0; try { + uint64_t date = 0; + double price = 0.0, vol = 0.0; + int direct = 0; st->getColumn(0, date, price, vol); result.emplace_back(Datetime(date), price, vol, static_cast(direct)); diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h index 53547b93c..3aabd9abe 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h @@ -40,7 +40,8 @@ class MySQLKDataDriver : public KDataDriver { return true; } - virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override; + virtual size_t getCount(const string& market, const string& code, + const KQuery::KType& kType) override; virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, size_t& out_end) override; @@ -55,11 +56,11 @@ class MySQLKDataDriver : public KDataDriver { const KQuery& query) override; private: - string _getTableName(const string& market, const string& code, KQuery::KType ktype); - KRecordList _getKRecordList(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix); - KRecordList _getKRecordList(const string& market, const string& code, KQuery::KType ktype, - Datetime start_date, Datetime end_date); + string _getTableName(const string& market, const string& code, const KQuery::KType& ktype); + KRecordList _getKRecordList(const string& market, const string& code, + const KQuery::KType& kType, size_t start_ix, size_t end_ix); + KRecordList _getKRecordList(const string& market, const string& code, + const KQuery::KType& ktype, Datetime start_date, Datetime end_date); TimeLineList _getTimeLineListByDate(const string& market, const string& code, const KQuery& query); diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.cpp index 2724d2fa5..35f6884e1 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.cpp @@ -125,7 +125,7 @@ KRecordList SQLiteKDataDriver::getKRecordList(const string& market, const string } KRecordList SQLiteKDataDriver::_getKRecordList(const string& market, const string& code, - KQuery::KType kType, size_t start_ix, + const KQuery::KType& kType, size_t start_ix, size_t end_ix) { KRecordList result; HKU_IF_RETURN(start_ix >= end_ix, result); @@ -163,7 +163,7 @@ KRecordList SQLiteKDataDriver::_getKRecordList(const string& market, const strin return result; } KRecordList SQLiteKDataDriver::_getKRecordList(const string& market, const string& code, - KQuery::KType kType, Datetime start_date, + const KQuery::KType& kType, Datetime start_date, Datetime end_date) { KRecordList result; HKU_IF_RETURN(start_date >= end_date, result); @@ -202,7 +202,8 @@ KRecordList SQLiteKDataDriver::_getKRecordList(const string& market, const strin return result; } -size_t SQLiteKDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) { +size_t SQLiteKDataDriver::getCount(const string& market, const string& code, + const KQuery::KType& kType) { string key(format("{}_{}", market, kType)); SQLiteConnectPtr connection = m_sqlite_connection_map[key]; HKU_IF_RETURN(!connection, 0); @@ -251,8 +252,8 @@ bool SQLiteKDataDriver::getIndexRangeByDate(const string& market, const string& } KRecordList SQLiteKDataDriver::convertToNewInterval(const KRecordList& candles, - KQuery::KType from_ktype, - KQuery::KType to_ktype) { + const KQuery::KType& from_ktype, + const KQuery::KType& to_ktype) { int32_t old_intervals_per_new_candle = KQuery::getKTypeInMin(to_ktype) / KQuery::getKTypeInMin(from_ktype); KRecordList result(candles.size() / old_intervals_per_new_candle); diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.h index be30229e8..f8c0cedc8 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.h @@ -1,6 +1,6 @@ /* * SQLiteKDataDriver.h - * + * * Created on: 2023年09月14日 * Author: yangrq1018 */ @@ -33,7 +33,8 @@ class SQLiteKDataDriver : public KDataDriver { return true; } - virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override; + virtual size_t getCount(const string& market, const string& code, + const KQuery::KType& kType) override; virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, size_t& out_end) override; @@ -43,12 +44,13 @@ class SQLiteKDataDriver : public KDataDriver { private: string _getTableName(const string& market, const string& code, KQuery::KType ktype); - KRecordList _getKRecordList(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix); - KRecordList _getKRecordList(const string& market, const string& code, KQuery::KType ktype, - Datetime start_date, Datetime end_date); - static KRecordList convertToNewInterval(const KRecordList& candles, KQuery::KType from_type, - KQuery::KType to_ktype); + KRecordList _getKRecordList(const string& market, const string& code, + const KQuery::KType& kType, size_t start_ix, size_t end_ix); + KRecordList _getKRecordList(const string& market, const string& code, + const KQuery::KType& ktype, Datetime start_date, Datetime end_date); + static KRecordList convertToNewInterval(const KRecordList& candles, + const KQuery::KType& from_type, + const KQuery::KType& to_ktype); private: unordered_map m_sqlite_connection_map; // key: exchange+code diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp index 3bd220b44..230552670 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp @@ -34,7 +34,7 @@ struct TdxDayData { record.closePrice = price_t(close) * 0.01; record.transAmount = price_t(amount) * 0.0001; record.transCount = price_t(vol); - //注:指数的成交量单位是股,和HDF5数据不同,HDF是手 + // 注:指数的成交量单位是股,和HDF5数据不同,HDF是手 } }; @@ -107,7 +107,7 @@ KRecordList TdxKDataDriver::getKRecordList(const string& market, const string& c } KRecordList TdxKDataDriver::_getDayKRecordList(const string& market, const string& code, - KQuery::KType ktype, size_t start_ix, + const KQuery::KType& ktype, size_t start_ix, size_t end_ix) { KRecordList result; size_t total = getCount(market, code, ktype); @@ -135,7 +135,7 @@ KRecordList TdxKDataDriver::_getDayKRecordList(const string& market, const strin } KRecordList TdxKDataDriver::_getMinKRecordList(const string& market, const string& code, - KQuery::KType ktype, size_t start_ix, + const KQuery::KType& ktype, size_t start_ix, size_t end_ix) { assert(KQuery::MIN == ktype || KQuery::MIN5 == ktype); KRecordList result; @@ -381,7 +381,8 @@ bool TdxKDataDriver::_getMinIndexRangeByDate(const string& market, const string& return true; } -string TdxKDataDriver::_getFileName(const string& market, const string& code, KQuery::KType ktype) { +string TdxKDataDriver::_getFileName(const string& market, const string& code, + const KQuery::KType& ktype) { string filename; if (ktype == KQuery::MIN) { filename = m_dirname + "\\" + market + "\\minline\\" + market + code + ".lc1"; @@ -398,7 +399,8 @@ string TdxKDataDriver::_getFileName(const string& market, const string& code, KQ return filename; } -size_t TdxKDataDriver::getCount(const string& market, const string& code, KQuery::KType ktype) { +size_t TdxKDataDriver::getCount(const string& market, const string& code, + const KQuery::KType& ktype) { size_t count = 0; if (KQuery::DAY == ktype || KQuery::MIN5 == ktype || KQuery::MIN == ktype) { count = _getBaseCount(market, code, ktype); @@ -408,7 +410,7 @@ size_t TdxKDataDriver::getCount(const string& market, const string& code, KQuery } size_t TdxKDataDriver::_getBaseCount(const string& market, const string& code, - KQuery::KType ktype) { + const KQuery::KType& ktype) { assert(KQuery::DAY == ktype || KQuery::MIN5 == ktype || KQuery::MIN == ktype); string filename = _getFileName(market, code, ktype); HKU_IF_RETURN(filename.empty(), 0); diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.h index d398b5b55..a90aa8906 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.h @@ -32,20 +32,21 @@ class TdxKDataDriver : public KDataDriver { return true; } - virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override; + virtual size_t getCount(const string& market, const string& code, + const KQuery::KType& kType) override; virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, size_t& out_end) override; virtual KRecordList getKRecordList(const string& market, const string& code, const KQuery& query) override; private: - string _getFileName(const string& market, const string& code, KQuery::KType); - size_t _getBaseCount(const string& market, const string& code, KQuery::KType); + string _getFileName(const string& market, const string& code, const KQuery::KType&); + size_t _getBaseCount(const string& market, const string& code, const KQuery::KType&); - KRecordList _getDayKRecordList(const string& market, const string& code, KQuery::KType ktype, - size_t start_ix, size_t end_ix); - KRecordList _getMinKRecordList(const string& market, const string& code, KQuery::KType ktype, - size_t start_ix, size_t end_ix); + KRecordList _getDayKRecordList(const string& market, const string& code, + const KQuery::KType& ktype, size_t start_ix, size_t end_ix); + KRecordList _getMinKRecordList(const string& market, const string& code, + const KQuery::KType& ktype, size_t start_ix, size_t end_ix); bool _getDayIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, size_t& out_end); diff --git a/hikyuu_cpp/hikyuu/global/GlobalSpotAgent.cpp b/hikyuu_cpp/hikyuu/global/GlobalSpotAgent.cpp index 23388d706..79aa9a41d 100644 --- a/hikyuu_cpp/hikyuu/global/GlobalSpotAgent.cpp +++ b/hikyuu_cpp/hikyuu/global/GlobalSpotAgent.cpp @@ -99,7 +99,7 @@ static void updateStockDayUpData(const SpotRecord& spot, KQuery::KType ktype) { KRecordList klist = stk.getKRecordList(KQuery(spot_start_of_phase, spot_end_of_phase + TimeDelta(1), ktype)); price_t amount = 0.0, volume = 0.0; - for (auto& k : klist) { + for (const auto& k : klist) { amount += k.transAmount; volume += k.transCount; } @@ -150,7 +150,7 @@ static void updateStockMinData(const SpotRecord& spot, KQuery::KType ktype) { minute = minute - (minute - minute.startOfDay()) % gap; KRecordList klist = stk.getKRecordList(KQuery(minute, minute + gap, ktype)); price_t sum_amount = 0.0, sum_volume = 0.0; - for (auto& k : klist) { + for (const auto& k : klist) { sum_amount += k.transAmount; sum_volume += k.transCount; } diff --git a/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp b/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp index ce938f21f..56b18cf4d 100644 --- a/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp +++ b/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp @@ -129,7 +129,7 @@ void SpotAgent::parseSpotData(const void* buf, size_t buf_len) { auto* spot = spots->Get(i); auto spot_record = parseFlatSpot(spot); if (spot_record) { - for (auto& process : m_processList) { + for (const auto& process : m_processList) { m_process_task_list.push_back(m_tg.submit(ProcessTask(process, *spot_record))); } } @@ -189,7 +189,7 @@ void SpotAgent::work_thread() { HKU_INFO_IF(m_print, "received count: {}", m_batch_count); m_batch_count = 0; // 执行后处理 - for (auto& postProcess : m_postProcessList) { + for (const auto& postProcess : m_postProcessList) { postProcess(ms_start_rev_time); } m_process_task_list.clear(); diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp index 1e0736cbf..68e77ef10 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp @@ -806,7 +806,7 @@ void IndicatorImp::execute_weave() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -859,7 +859,7 @@ void IndicatorImp::execute_add() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -889,7 +889,7 @@ void IndicatorImp::execute_sub() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -927,7 +927,7 @@ void IndicatorImp::execute_mul() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -957,7 +957,7 @@ void IndicatorImp::execute_div() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1003,7 +1003,7 @@ void IndicatorImp::execute_mod() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1049,7 +1049,7 @@ void IndicatorImp::execute_eq() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1083,7 +1083,7 @@ void IndicatorImp::execute_ne() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1117,7 +1117,7 @@ void IndicatorImp::execute_gt() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1163,7 +1163,7 @@ void IndicatorImp::execute_lt() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1209,7 +1209,7 @@ void IndicatorImp::execute_ge() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1255,7 +1255,7 @@ void IndicatorImp::execute_le() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1301,7 +1301,7 @@ void IndicatorImp::execute_and() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1335,7 +1335,7 @@ void IndicatorImp::execute_or() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1370,7 +1370,7 @@ void IndicatorImp::execute_if() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1414,7 +1414,7 @@ void IndicatorImp::execute_corr() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1525,9 +1525,7 @@ void IndicatorImp::_dyn_calculate(const Indicator &ind) { // HKU_INFO("multi_thread"); size_t circleLength = minCircleLength; - if (minCircleLength * workerNum >= total) { - circleLength = minCircleLength; - } else { + if (minCircleLength * workerNum < total) { size_t tailCount = total % workerNum; circleLength = tailCount == 0 ? total / workerNum : total / workerNum + 1; } diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h index cc56c0eb3..99219ce38 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h @@ -280,14 +280,14 @@ class HKU_API IndicatorImp : public enable_shared_from_this { size_t count = size(); ar& bs::make_nvp(format("count_{}", i).c_str(), count); PriceList& values = *m_pBuffer[i]; - for (size_t i = 0; i < count; i++) { - if (std::isnan(values[i])) { + for (size_t j = 0; j < count; j++) { + if (std::isnan(values[j])) { ar& boost::serialization::make_nvp("item", nan); - } else if (std::isinf(values[i])) { - inf = values[i] > 0 ? "+inf" : "-inf"; + } else if (std::isinf(values[j])) { + inf = values[j] > 0 ? "+inf" : "-inf"; ar& boost::serialization::make_nvp("item", inf); } else { - ar& boost::serialization::make_nvp("item", values[i]); + ar& boost::serialization::make_nvp("item", values[j]); } } } diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IAma.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IAma.cpp index 50fa94169..7814f1729 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IAma.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IAma.cpp @@ -47,7 +47,7 @@ void IAma::_calculate(const Indicator& data) { price_t slowest = 2.0 / (slow_n + 1); price_t delta = fastest - slowest; - price_t prevol = 0.0, vol = 0.0, er = 1.0, c(0.0); + price_t prevol = 0.0, vol = 0.0, er = 1.0, c = 0.0; price_t ama = data[start]; size_t first_end = start + n + 1 >= total ? total : start + n + 1; _set(ama, start, 0); @@ -134,9 +134,7 @@ void IAma::_dyn_calculate(const Indicator& ind) { } size_t circleLength = minCircleLength; - if (minCircleLength * workerNum >= total) { - circleLength = minCircleLength; - } else { + if (minCircleLength * workerNum < total) { size_t tailCount = total % workerNum; circleLength = tailCount == 0 ? total / workerNum : total / workerNum + 1; } diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp index 30124ffc8..35c5f9222 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp @@ -68,10 +68,10 @@ void IHhvbars::_calculate(const Indicator& ind) { if (pre_pos < j) { pre_pos = j; max = ind[j]; - for (size_t j = pre_pos + 1; j <= i; j++) { - if (ind[j] >= max) { - max = ind[j]; - pre_pos = j; + for (size_t k = pre_pos + 1; k <= i; k++) { + if (ind[k] >= max) { + max = ind[k]; + pre_pos = k; } } diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp index 8d884c39d..1444572e3 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp @@ -70,10 +70,10 @@ void IHighLine::_calculate(const Indicator& ind) { if (pre_pos < j) { pre_pos = j; max = ind[j]; - for (size_t j = pre_pos + 1; j <= i; j++) { - if (ind[j] >= max) { - max = ind[j]; - pre_pos = j; + for (size_t k = pre_pos + 1; k <= i; k++) { + if (ind[k] >= max) { + max = ind[k]; + pre_pos = k; } } } else { diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp b/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp index 81d98fd22..45656875e 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp @@ -70,10 +70,10 @@ void ILowLine::_calculate(const Indicator& ind) { if (pre_pos < j) { pre_pos = j; min = ind[j]; - for (size_t j = pre_pos + 1; j <= i; j++) { - if (ind[j] <= min) { - min = ind[j]; - pre_pos = j; + for (size_t k = pre_pos + 1; k <= i; k++) { + if (ind[k] <= min) { + min = ind[k]; + pre_pos = k; } } } else { diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp b/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp index 24614e5af..7b2655b44 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp @@ -68,10 +68,10 @@ void ILowLineBars::_calculate(const Indicator& ind) { if (pre_pos < j) { pre_pos = j; min = ind[j]; - for (size_t j = pre_pos + 1; j <= i; j++) { - if (ind[j] <= min) { - min = ind[j]; - pre_pos = j; + for (size_t k = pre_pos + 1; k <= i; k++) { + if (ind[k] <= min) { + min = ind[k]; + pre_pos = k; } } } else { diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IMacd.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IMacd.cpp index afbf6dc6b..fb65c05c0 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IMacd.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IMacd.cpp @@ -116,9 +116,7 @@ void IMacd::_dyn_calculate(const Indicator& ind) { } size_t circleLength = minCircleLength; - if (minCircleLength * workerNum >= total) { - circleLength = minCircleLength; - } else { + if (minCircleLength * workerNum < total) { size_t tailCount = total % workerNum; circleLength = tailCount == 0 ? total / workerNum : total / workerNum + 1; } diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ISaftyLoss.cpp b/hikyuu_cpp/hikyuu/indicator/imp/ISaftyLoss.cpp index dee96661d..a9e58be19 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ISaftyLoss.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/ISaftyLoss.cpp @@ -43,11 +43,9 @@ void ISaftyLoss::_calculate(const Indicator& data) { return; } - price_t result(0.0); - size_t start = discard(); for (size_t i = start; i < total; ++i) { - result = 0.0; + price_t result = 0.0; for (size_t j = i + 1 - n2; j <= i; ++j) { price_t sum = 0.0; size_t num = 0; @@ -118,9 +116,7 @@ void ISaftyLoss::_dyn_calculate(const Indicator& ind) { } size_t circleLength = minCircleLength; - if (minCircleLength * workerNum >= total) { - circleLength = minCircleLength; - } else { + if (minCircleLength * workerNum < total) { size_t tailCount = total % workerNum; circleLength = tailCount == 0 ? total / workerNum : total / workerNum + 1; } diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ISma.cpp b/hikyuu_cpp/hikyuu/indicator/imp/ISma.cpp index 0ef7108ac..0bc6b3e68 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ISma.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/ISma.cpp @@ -85,9 +85,7 @@ void ISma::_dyn_calculate(const Indicator& ind) { } size_t circleLength = minCircleLength; - if (minCircleLength * workerNum >= total) { - circleLength = minCircleLength; - } else { + if (minCircleLength * workerNum < total) { size_t tailCount = total % workerNum; circleLength = tailCount == 0 ? total / workerNum : total / workerNum + 1; } diff --git a/hikyuu_cpp/hikyuu/strategy/StrategyBase.cpp b/hikyuu_cpp/hikyuu/strategy/StrategyBase.cpp index 403c2311b..459ef8426 100644 --- a/hikyuu_cpp/hikyuu/strategy/StrategyBase.cpp +++ b/hikyuu_cpp/hikyuu/strategy/StrategyBase.cpp @@ -95,8 +95,8 @@ void StrategyBase::run() { hkuParam.set("tmpdir", config.get("hikyuu", "tmpdir", ".")); hkuParam.set("datadir", config.get("hikyuu", "datadir", ".")); - hkuParam.set("quotation_server", config.get("hikyuu", "quotation_server", - "ipc:///tmp/hikyuu_real.ipc")); + hkuParam.set("quotation_server", + config.get("hikyuu", "quotation_server", "ipc:///tmp/hikyuu_real.ipc")); if (!config.hasSection("baseinfo")) { HKU_FATAL("Missing configure of baseinfo!"); @@ -153,8 +153,8 @@ void StrategyBase::run() { HKU_WARN_IF(m_stock_list.empty(), "[Strategy {}] stock list is empty!", m_name); if (m_stock_list.size() > 0) { - Stock& ref_stk = m_stock_list[0]; - for (auto& ktype : ktype_list) { + const Stock& ref_stk = m_stock_list[0]; + for (const auto& ktype : ktype_list) { // 由于异步初始化,此处不用通过先getCount再getKRecord的方式获取最后的KRecord KRecordList klist = ref_stk.getKRecordList(KQueryByIndex(0, Null(), ktype)); size_t count = klist.size(); @@ -208,9 +208,9 @@ void StrategyBase::_addTimer() { market_set.insert(stk.market()); } - auto& sm = StockManager::instance(); + const auto& sm = StockManager::instance(); TimeDelta openTime(0, 23, 59, 59, 999, 999), closeTime(0); - for (auto& market : market_set) { + for (const auto& market : market_set) { auto market_info = sm.getMarketInfo(market); if (market_info.openTime1() < market_info.closeTime1()) { if (market_info.openTime1() < openTime) { diff --git a/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.cpp b/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.cpp index 4483d56ee..dffda018f 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.cpp +++ b/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.cpp @@ -43,7 +43,7 @@ FundsRecord ::FundsRecord(price_t cash, price_t market_value, price_t short_mark borrow_cash(borrow_cash), borrow_asset(borrow_asset) {} -FundsRecord FundsRecord::operator+(const FundsRecord other) { +FundsRecord FundsRecord::operator+(const FundsRecord& other) const { FundsRecord result; result.cash = cash + other.cash; result.market_value = market_value + other.market_value; @@ -55,7 +55,7 @@ FundsRecord FundsRecord::operator+(const FundsRecord other) { return result; } -FundsRecord& FundsRecord::operator+=(const FundsRecord other) { +FundsRecord& FundsRecord::operator+=(const FundsRecord& other) { cash += other.cash; market_value += other.market_value; short_market_value += other.short_market_value; diff --git a/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.h b/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.h index 84ba7f2b2..e68a94b78 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.h +++ b/hikyuu_cpp/hikyuu/trade_manage/FundsRecord.h @@ -47,9 +47,9 @@ class HKU_API FundsRecord { // 当前收益 = 当前净资产 - 当前投入本值资产 // = cash + market_value - short_market_value - borrow_cash - base_cash - base_asset - FundsRecord operator+(const FundsRecord other); + FundsRecord operator+(const FundsRecord& other) const; - FundsRecord& operator+=(const FundsRecord other); + FundsRecord& operator+=(const FundsRecord& other); // 序列化支持 #if HKU_SUPPORT_SERIALIZATION diff --git a/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp b/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp index 4952a0aff..567d02445 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp +++ b/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp @@ -402,13 +402,13 @@ void Performance ::statistics(const TradeManagerPtr& tm, const Datetime& datetim PositionRecordList cur_position = tm->getPositionList(); PositionRecordList::const_iterator cur_iter; - int short_number = 0; - int short_days = 0; int total_short_days = 0; - int max_short_days = 0; - bool pre_short = false; if (tm->firstDatetime() != Null()) { + int short_number = 0; + int short_days = 0; + int max_short_days = 0; + bool pre_short = false; Datetime end_day; if (datetime == Null()) { end_day = Datetime(tm->lastDatetime().date() + bd::days(1)); diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp index b651c6a56..1c38a2980 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.cpp @@ -372,8 +372,7 @@ PositionRecord TradeManager::getPosition(const Datetime& datetime, const Stock& // 在历史交易记录中,重新计算在指定的查询日期时,该交易对象的持仓数量 double number = 0.0; - TradeRecordList::const_iterator iter = m_trade_list.begin(); - for (; iter != m_trade_list.end(); ++iter) { + for (auto iter = m_trade_list.begin(); iter != m_trade_list.end(); ++iter) { // 交易记录中的交易日期已经大于查询日期,则跳出循环 if (iter->datetime > datetime) { break; diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.cpp index ac743bdb1..1135951e8 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.cpp @@ -19,8 +19,6 @@ BoolCondition::BoolCondition(const Indicator& ind) : ConditionBase("CN_Bool"), m BoolCondition::~BoolCondition() {} -void BoolCondition::_reset() {} - ConditionPtr BoolCondition::_clone() { return make_shared(m_ind); } diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h index 384eaf2ef..3e0fa0e14 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h @@ -19,7 +19,6 @@ class BoolCondition : public ConditionBase { virtual ~BoolCondition(); virtual void _calculate() override; - virtual void _reset() override; virtual ConditionPtr _clone() override; private: diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.cpp index 8045a43b5..e9917b306 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.cpp @@ -28,8 +28,6 @@ ConditionPtr OPLineCondition::_clone() { return make_shared(m_op); } -void OPLineCondition::_reset() {} - void OPLineCondition::_calculate() { Stock stock = m_kdata.getStock(); KQuery query = m_kdata.getQuery(); diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h index befb76c3a..4f2035459 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h @@ -21,7 +21,6 @@ class OPLineCondition : public ConditionBase { virtual ~OPLineCondition(); virtual void _calculate() override; - virtual void _reset() override; virtual ConditionPtr _clone() override; private: diff --git a/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp b/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp index b6977694f..0057c0f59 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.cpp @@ -282,7 +282,7 @@ void Portfolio::run(const KQuery& query, bool force) { "AllocateFunds instance have been specified."); DatetimeList datelist = StockManager::instance().getTradingCalendar(query); - for (auto& date : datelist) { + for (const auto& date : datelist) { _runMoment(date); } m_need_calculate = false; diff --git a/hikyuu_cpp/hikyuu/trade_sys/selector/imp/SignalSelector.h b/hikyuu_cpp/hikyuu/trade_sys/selector/imp/SignalSelector.h index b8dfae349..40edf9238 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/selector/imp/SignalSelector.h +++ b/hikyuu_cpp/hikyuu/trade_sys/selector/imp/SignalSelector.h @@ -19,7 +19,7 @@ class SignalSelector : public SelectorBase { SignalSelector(); virtual ~SignalSelector(); - virtual void _reset() { + virtual void _reset() override { m_sys_dict_on_open.clear(); m_sys_dict_on_close.clear(); } diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/BandSignal.h b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/BandSignal.h index d331e1d4c..f0b862135 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/BandSignal.h +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/BandSignal.h @@ -25,7 +25,7 @@ class BandSignal : public SignalBase { private: Indicator m_ind; - price_t m_lower, m_upper; + price_t m_lower = 0.0, m_upper = 0.0; //============================================ // 序列化支持 diff --git a/hikyuu_cpp/hikyuu/utilities/Parameter.cpp b/hikyuu_cpp/hikyuu/utilities/Parameter.cpp index 0f88a7563..747fb501c 100644 --- a/hikyuu_cpp/hikyuu/utilities/Parameter.cpp +++ b/hikyuu_cpp/hikyuu/utilities/Parameter.cpp @@ -16,7 +16,6 @@ HKU_API std::ostream& operator<<(std::ostream& os, const Parameter& param) { // os.precision(4); os << "params["; string strip(", "); - string colon(": "); Parameter::param_map_t::const_iterator iter = param.m_params.begin(); for (; iter != param.m_params.end(); ++iter) { os << iter->first; diff --git a/hikyuu_cpp/hikyuu/utilities/TimerManager.h b/hikyuu_cpp/hikyuu/utilities/TimerManager.h index 7d851ce8d..81eac01c6 100644 --- a/hikyuu_cpp/hikyuu/utilities/TimerManager.h +++ b/hikyuu_cpp/hikyuu/utilities/TimerManager.h @@ -74,7 +74,7 @@ class TimerManager { std::forward_list invalid_timers; // 记录已无效的 timer for (auto iter = m_timers.begin(); iter != m_timers.end(); ++iter) { int time_id = iter->first; - Timer* timer = iter->second; + const Timer* timer = iter->second; Datetime now = Datetime::now(); // 记录已失效的 timer id diff --git a/hikyuu_cpp/hikyuu/utilities/cppdef.h b/hikyuu_cpp/hikyuu/utilities/cppdef.h index 45dd2dc93..2e5a0b8d4 100644 --- a/hikyuu_cpp/hikyuu/utilities/cppdef.h +++ b/hikyuu_cpp/hikyuu/utilities/cppdef.h @@ -20,5 +20,6 @@ #define CPP_STANDARD_11 201103L #define CPP_STANDARD_14 201402L #define CPP_STANDARD_17 201703L +#define CPP_STANDARD_20 202002L #endif // HKU_CPP_DEF_H_ diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLStatement.cpp b/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLStatement.cpp index 04f0723dc..c994aea36 100755 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLStatement.cpp +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/mysql/MySQLStatement.cpp @@ -338,7 +338,7 @@ void MySQLStatement::sub_getColumnAsDatetime(int idx, Datetime& item) { } try { - MYSQL_TIME* tm = boost::any_cast(&(m_result_buffer[idx])); + const MYSQL_TIME* tm = boost::any_cast(&(m_result_buffer[idx])); if (tm->time_type == MYSQL_TIMESTAMP_DATETIME) { long millisec = tm->second_part / 1000; long microsec = tm->second_part - millisec * 1000; diff --git a/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h b/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h index e780379cf..eac44db02 100644 --- a/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h +++ b/hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h @@ -58,7 +58,7 @@ class HKU_API MQStealThreadPool { m_queues.emplace_back(new MQStealQueue); } // 初始完毕所有线程资源后再启动线程 - for (size_t i = 0; i < m_worker_num; i++) { + for (int i = 0; i < m_worker_num; i++) { m_threads.emplace_back(&MQStealThreadPool::worker_thread, this, i); } } catch (...) { diff --git a/hikyuu_cpp/hikyuu_server/http/HttpHandle.cpp b/hikyuu_cpp/hikyuu_server/http/HttpHandle.cpp index 8c1051e76..7917d265c 100644 --- a/hikyuu_cpp/hikyuu_server/http/HttpHandle.cpp +++ b/hikyuu_cpp/hikyuu_server/http/HttpHandle.cpp @@ -31,7 +31,7 @@ void HttpHandle::operator()() { m_nng_req = (nng_http_req*)nng_aio_get_input(m_http_aio, 0); m_nng_conn = (nng_http_conn*)nng_aio_get_input(m_http_aio, 2); - for (auto& filter : m_filters) { + for (const auto& filter : m_filters) { filter(this); } diff --git a/hikyuu_pywrap/_Stock.cpp b/hikyuu_pywrap/_Stock.cpp index ee7213638..8dec404c6 100644 --- a/hikyuu_pywrap/_Stock.cpp +++ b/hikyuu_pywrap/_Stock.cpp @@ -14,8 +14,9 @@ namespace py = pybind11; // BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getIndex_overloads, getIndex, 1, 2) -KRecord (Stock::*getKRecord1)(size_t pos, KQuery::KType kType) const = &Stock::getKRecord; -KRecord (Stock::*getKRecord2)(const Datetime&, KQuery::KType kType) const = &Stock::getKRecord; +KRecord (Stock::*getKRecord1)(size_t pos, const KQuery::KType& kType) const = &Stock::getKRecord; +KRecord (Stock::*getKRecord2)(const Datetime&, + const KQuery::KType& kType) const = &Stock::getKRecord; void export_Stock(py::module& m) { py::class_(m, "Stock", "证券对象") @@ -31,8 +32,7 @@ void export_Stock(py::module& m) { .def_property_readonly("market", py::overload_cast<>(&Stock::market, py::const_), "所属市场简称,市场简称是市场的唯一标识") .def_property_readonly("code", py::overload_cast<>(&Stock::code, py::const_), "证券代码") - .def_property_readonly("market_code", - py::overload_cast<>(&Stock::market_code, py::const_), + .def_property_readonly("market_code", py::overload_cast<>(&Stock::market_code, py::const_), "市场简称+证券代码,如: sh000001") .def_property_readonly("name", py::overload_cast<>(&Stock::name, py::const_), "证券名称") .def_property_readonly("type", &Stock::type, "证券类型,参见:constant") diff --git a/hikyuu_pywrap/main.cpp b/hikyuu_pywrap/main.cpp index b5bc66fcc..c3abbe907 100644 --- a/hikyuu_pywrap/main.cpp +++ b/hikyuu_pywrap/main.cpp @@ -125,12 +125,13 @@ PYBIND11_MODULE(core, m) { m.def("get_kdata", py::overload_cast(getKData)); - m.def("get_kdata", - py::overload_cast( - getKData), - py::arg("market_code"), py::arg("start") = 0, py::arg("end") = null_int64, - py::arg("ktype") = KQuery::DAY, py::arg("recover_type") = KQuery::NO_RECOVER, - R"(根据证券代码及起止位置获取 [start, end) 范围的 K 线数据 + m.def( + "get_kdata", + py::overload_cast( + getKData), + py::arg("market_code"), py::arg("start") = 0, py::arg("end") = null_int64, + py::arg("ktype") = KQuery::DAY, py::arg("recover_type") = KQuery::NO_RECOVER, + R"(根据证券代码及起止位置获取 [start, end) 范围的 K 线数据 :param str market_code: 证券代码,如: 'sh000001' :param int start: 起始索引 @@ -139,7 +140,7 @@ PYBIND11_MODULE(core, m) { :param Query.RecoverType recover_type: 复权类型)"); m.def("get_kdata", - py::overload_cast(getKData), py::arg("market_code"), py::arg("start") = Datetime::min(), py::arg("end") = null_date, py::arg("ktype") = KQuery::DAY, py::arg("recover_type") = KQuery::NO_RECOVER, diff --git a/hikyuu_pywrap/trade_manage/_FundsRecord.cpp b/hikyuu_pywrap/trade_manage/_FundsRecord.cpp index 67b35b3b2..a9be63ac5 100644 --- a/hikyuu_pywrap/trade_manage/_FundsRecord.cpp +++ b/hikyuu_pywrap/trade_manage/_FundsRecord.cpp @@ -26,5 +26,8 @@ void export_FundsRecord(py::module& m) { .def_readwrite("borrow_cash", &FundsRecord::borrow_cash, "当前借入的资金(float),即负债") .def_readwrite("borrow_asset", &FundsRecord::borrow_asset, "当前借入证券资产价值(float)") + .def(py::self + py::self) + .def(py::self += py::self) + DEF_PICKLE(FundsRecord); } diff --git a/xmake.lua b/xmake.lua index 65757f071..288846e57 100644 --- a/xmake.lua +++ b/xmake.lua @@ -156,7 +156,7 @@ add_requires("boost " .. boost_version, { system = false, debug = is_mode("debug"), configs = { - shared = false, + shared = is_plat("windows") and true or false, multi = true, date_time = true, filesystem = true, @@ -175,15 +175,15 @@ add_requires("nlohmann_json", {system = false}) add_requires("cpp-httplib", {system = false, configs = {zlib = true, ssl = true}}) add_requires("zlib", {system = false}) -add_defines("SPDLOG_DISABLE_DEFAULT_LOGGER") -- 禁用 spdlog 默认ogger +add_defines("SPDLOG_DISABLExm_DEFAULT_LOGGER") -- 禁用 spdlog 默认ogger set_objectdir("$(buildir)/$(mode)/$(plat)/$(arch)/.objs") set_targetdir("$(buildir)/$(mode)/$(plat)/$(arch)/lib") -- modifed to use boost static library, except boost.python, serialization --- if is_plat("windows") and get_config("kind") == "shared" then --- add_defines("BOOST_ALL_DYN_LINK") --- end +if is_plat("windows") and get_config("kind") == "shared" then + add_defines("BOOST_ALL_DYN_LINK") +end -- is release now if is_mode("release") then