hikyuu2/hikyuu_cpp/hikyuu/StrategyContext.h

107 lines
3.3 KiB
C++
Raw Normal View History

2021-02-11 00:47:22 +08:00
/*
* Copyright(C) 2021 hikyuu.org
*
* Create on: 2021-02-10
* Author: fasiondog
*/
#pragma once
#include "DataType.h"
2021-02-19 01:12:50 +08:00
#include "KQuery.h"
2021-02-11 00:47:22 +08:00
namespace hku {
/**
* /K线级别信息
* @ingroup Strategy
*
*/
class HKU_API StrategyContext {
2021-02-11 00:47:22 +08:00
public:
StrategyContext() = default;
virtual ~StrategyContext() = default;
2021-02-11 00:47:22 +08:00
2024-09-01 16:11:27 +08:00
/**
*
* @note ktypelist
* @param stockCodeList {"sz000001", "sz000002"}
*/
explicit StrategyContext(const vector<string>& stockCodeList);
2021-02-17 19:43:59 +08:00
/**
*
* @note ("ALL") ;
2024-09-01 16:11:27 +08:00
* K线类型列表同时影响着K线数据的优先加载顺序
* @param stockCodeList {"sh000001", "sz000001"}
* @param ktypeList K线数据列表{"day", "min"}
*/
StrategyContext(const vector<string>& stockCodeList, const vector<KQuery::KType>& ktypeList);
2024-08-25 22:11:25 +08:00
// 自定义移动构造与赋值会引起 python 中无法正常退出
// StrategyContext(const StrategyContext&) = default;
// StrategyContext(StrategyContext&& rv) = delete;
// StrategyContext& operator=(const StrategyContext&) = default;
// StrategyContext& operator=(StrategyContext&&) = delete;
2021-02-11 00:47:22 +08:00
/**
2024-09-01 16:11:27 +08:00
* stockCodeList "ALL"()
* @return true
* @return false
*/
2024-08-21 12:34:12 +08:00
bool isAll() const noexcept;
2021-02-19 01:12:50 +08:00
2024-09-01 16:11:27 +08:00
bool empty() const noexcept {
return m_stockCodeList.empty();
}
2024-08-21 12:34:12 +08:00
Datetime startDatetime() const noexcept {
2021-02-11 00:47:22 +08:00
return m_startDatetime;
}
void setStockCodeList(const vector<string>& stockList) {
_removeDuplicateCode(stockList);
}
2021-02-11 00:47:22 +08:00
const vector<string>& getStockCodeList() const noexcept {
2021-02-11 00:47:22 +08:00
return m_stockCodeList;
}
void setKTypeList(const vector<KQuery::KType>& ktypeList) {
_checkAndRemoveDuplicateKType(ktypeList);
}
2021-02-19 01:12:50 +08:00
const vector<KQuery::KType>& getKTypeList() const noexcept {
2021-02-19 01:12:50 +08:00
return m_ktypeList;
}
2021-02-17 16:08:24 +08:00
/**
*
* @note
*/
const vector<string>& getMustLoadStockCodeList() const noexcept {
return m_mustLoad;
}
/**
*
* @return vector<string>
*/
vector<string> getAllNeedLoadStockCodeList() const noexcept;
2024-09-01 16:11:27 +08:00
string str() const;
private:
void _removeDuplicateCode(const vector<string>& stockCodeList);
void _checkAndRemoveDuplicateKType(const vector<KQuery::KType>& ktypeList);
2021-02-11 00:47:22 +08:00
private:
Datetime m_startDatetime{19901219};
vector<string> m_mustLoad{"sh000001", "sh000300"}; // 默认必须加载的 stock
2021-02-11 00:47:22 +08:00
vector<string> m_stockCodeList;
2021-02-19 01:12:50 +08:00
vector<KQuery::KType> m_ktypeList;
2021-02-11 00:47:22 +08:00
};
2024-09-01 16:11:27 +08:00
HKU_API std::ostream& operator<<(std::ostream& os, const StrategyContext& context);
2021-02-11 00:47:22 +08:00
} // namespace hku