mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
Merge branch 'feature/order' of https://github.com/fasiondog/hikyuu into feature/stg
This commit is contained in:
commit
03cb9e63c3
@ -22,6 +22,9 @@ public:
|
||||
explicit StrategyContext(vector<string>&& stockCodeList)
|
||||
: m_stockCodeList(std::move(stockCodeList)) {}
|
||||
|
||||
StrategyContext(const vector<string>& stockCodeList, const vector<KQuery::KType>& ktypeList)
|
||||
: m_stockCodeList(stockCodeList), m_ktypeList(ktypeList) {}
|
||||
|
||||
virtual ~StrategyContext() = default;
|
||||
|
||||
bool isAll() const noexcept;
|
||||
|
@ -57,6 +57,11 @@ Strategy::Strategy(const vector<string>& codeList, const vector<KQuery::KType>&
|
||||
m_context.setKTypeList(ktypeList);
|
||||
}
|
||||
|
||||
Strategy::Strategy(const StrategyContext& context, const string& name, const string& config_file)
|
||||
: Strategy(name, config_file) {
|
||||
m_context = m_context;
|
||||
}
|
||||
|
||||
Strategy::~Strategy() {
|
||||
ms_keep_running = false;
|
||||
CLS_INFO("Quit Strategy {}!", m_name);
|
||||
@ -74,6 +79,17 @@ void Strategy::_init() {
|
||||
|
||||
// 初始化
|
||||
hikyuu_init(m_config_file, false, m_context);
|
||||
|
||||
// 对上下文中的K线类型和其预加载参数进行检查,并给出警告
|
||||
const auto& ktypes = m_context.getKTypeList();
|
||||
const auto& preload_params = sm.getPreloadParameter();
|
||||
for (const auto& ktype : ktypes) {
|
||||
std::string low_ktype = ktype;
|
||||
to_lower(low_ktype);
|
||||
HKU_ERROR_IF(!preload_params.tryGet(low_ktype, false),
|
||||
"The K-line type in the context is not configured to be preloaded!");
|
||||
}
|
||||
|
||||
} else {
|
||||
m_context = sm.getStrategyContext();
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
explicit Strategy(const string& name, const string& config_file = "");
|
||||
Strategy(const vector<string>& codeList, const vector<KQuery::KType>& ktypeList,
|
||||
const string& name = "Strategy", const string& config_file = "");
|
||||
explicit Strategy(const StrategyContext& context, const string& name = "Strategy",
|
||||
const string& config_file = "");
|
||||
|
||||
virtual ~Strategy();
|
||||
|
||||
|
@ -29,11 +29,12 @@ void setKTypeList(StrategyContext* self, const py::sequence& seq) {
|
||||
void export_StrategeContext(py::module& m) {
|
||||
py::class_<StrategyContext>(m, "StrategyContext", "策略上下文")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const vector<string>&, const vector<KQuery::KType>&>(), py::arg("stock_list"),
|
||||
py::arg("ktype_list"))
|
||||
.def_property("start_datetime", get_start_datetime, set_start_datetime, "起始日期")
|
||||
.def_property("stock_list",
|
||||
py::overload_cast<>(&StrategyContext::getStockCodeList, py::const_),
|
||||
setStockList, "股票代码列表")
|
||||
.def_property("ktype_list",
|
||||
py::overload_cast<>(&StrategyContext::getKTypeList, py::const_),
|
||||
.def_property("ktype_list", py::overload_cast<>(&StrategyContext::getKTypeList, py::const_),
|
||||
setKTypeList, "需要的K线类型");
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ void export_Strategy(py::module& m) {
|
||||
const std::string&>(),
|
||||
py::arg("code_list"), py::arg("ktype_list"), py::arg("name") = "Strategy",
|
||||
py::arg("config") = "")
|
||||
.def(py::init<const StrategyContext&, const string&, const string&>(), py::arg("context"),
|
||||
py::arg("name") = "Strategy", py::arg("config") = "")
|
||||
.def_property("name", py::overload_cast<>(&Strategy::name, py::const_),
|
||||
py::overload_cast<const string&>(&Strategy::name),
|
||||
py::return_value_policy::copy, "策略名称")
|
||||
|
Loading…
Reference in New Issue
Block a user