hikyuu2/hikyuu_pywrap/_StrategyContext.cpp

40 lines
1.4 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
*/
#include <hikyuu/StrategyContext.h>
2023-12-26 18:25:50 +08:00
#include "pybind_utils.h"
2021-02-11 00:47:22 +08:00
2023-12-26 18:25:50 +08:00
namespace py = pybind11;
2021-02-11 00:47:22 +08:00
using namespace hku;
Datetime (StrategyContext::*get_start_datetime)() const = &StrategyContext::startDatetime;
void (StrategyContext::*set_start_datetime)(const Datetime&) = &StrategyContext::startDatetime;
void (StrategyContext::*set_stock_list)(const vector<string>&) = &StrategyContext::setStockCodeList;
2023-12-30 14:25:48 +08:00
void setStockList(StrategyContext* self, const py::sequence& seq) {
2023-12-26 18:25:50 +08:00
vector<string> stk_list = python_list_to_vector<string>(seq);
2021-02-19 01:12:50 +08:00
self->setStockCodeList(std::move(stk_list));
}
2023-12-30 14:25:48 +08:00
void setKTypeList(StrategyContext* self, const py::sequence& seq) {
2023-12-26 18:25:50 +08:00
vector<string> stk_list = python_list_to_vector<string>(seq);
2021-02-19 01:12:50 +08:00
self->setKTypeList(stk_list);
2021-02-11 00:47:22 +08:00
}
2023-12-26 18:25:50 +08:00
void export_StrategeContext(py::module& m) {
py::class_<StrategyContext>(m, "StrategyContext", "策略上下文")
.def(py::init<>())
.def_property("start_datetime", get_start_datetime, set_start_datetime, "起始日期")
.def_property("stock_list",
py::overload_cast<>(&StrategyContext::getStockCodeList, py::const_),
2023-12-27 02:16:10 +08:00
setStockList, "股票代码列表")
.def_property("ktype_list",
py::overload_cast<>(&StrategyContext::getKTypeList, py::const_),
2023-12-27 02:16:10 +08:00
setKTypeList, "需要的K线类型");
2021-02-11 00:47:22 +08:00
}