hikyuu2/hikyuu_pywrap/trade_sys/_Condition.cpp

116 lines
3.8 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _Condition.cpp
*
* Created on: 2013-3-10
* Author: fasiondog
*/
2016-05-10 01:33:39 +08:00
#include <hikyuu/trade_sys/condition/build_in.h>
2023-12-27 17:02:11 +08:00
#include "../pybind_utils.h"
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
namespace py = pybind11;
2015-01-07 01:26:14 +08:00
using namespace hku;
2023-12-27 17:02:11 +08:00
class PyConditionBase : public ConditionBase {
PY_CLONE(PyConditionBase, ConditionBase)
2016-05-10 01:33:39 +08:00
2023-12-27 17:02:11 +08:00
public:
using ConditionBase::ConditionBase;
2016-05-10 01:33:39 +08:00
2023-12-27 17:02:11 +08:00
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, ConditionBase, _calculate, );
2015-01-07 01:26:14 +08:00
}
2023-12-27 17:02:11 +08:00
void _reset() override {
PYBIND11_OVERLOAD(void, ConditionBase, _reset, );
2015-01-07 01:26:14 +08:00
}
};
2023-12-27 17:02:11 +08:00
void export_Condition(py::module& m) {
py::class_<ConditionBase, ConditionPtr, PyConditionBase>(
m, "ConditionBase",
R"(系统有效条件基类自定义系统有效条件接口:
2020-07-13 23:52:35 +08:00
- _calculate :
- _clone :
2023-12-27 17:02:11 +08:00
- _reset : )")
.def(py::init<>())
.def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
.def("__str__", to_py_str<ConditionBase>)
.def("__repr__", to_py_str<ConditionBase>)
2020-07-13 23:52:35 +08:00
.def_property("name", py::overload_cast<>(&ConditionBase::name, py::const_),
2023-12-27 17:02:11 +08:00
py::overload_cast<const string&>(&ConditionBase::name),
py::return_value_policy::copy, "名称")
2020-07-13 23:52:35 +08:00
2023-12-27 17:02:11 +08:00
.def_property("to", &ConditionBase::getTO, &ConditionBase::setTO, "设置或获取交易对象")
.def_property("tm", &ConditionBase::getTM, &ConditionBase::setTM, "设置或获取交易管理账户")
.def_property("sg", &ConditionBase::getSG, &ConditionBase::setSG, "设置或获取交易信号指示器")
2020-07-13 23:52:35 +08:00
.def("get_param", &ConditionBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
2023-12-27 17:02:11 +08:00
.def("set_param", &ConditionBase::setParam<boost::any>, R"(set_param(self, name, value)
2020-07-13 23:52:35 +08:00
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &ConditionBase::haveParam, "是否存在指定参数")
.def("is_valid", &ConditionBase::isValid, R"(is_valid(self, datetime)
:param Datetime datetime:
:return: True | False )")
.def("reset", &ConditionBase::reset, "复位操作")
.def("clone", &ConditionBase::clone, "克隆操作")
.def("get_datetime_list", &ConditionBase::getDatetimeList, R"(get_datetime_list(self)
)")
.def("get_values", &ConditionBase::getValues, R"(get_values(self)
01)")
2020-07-13 23:52:35 +08:00
.def("_add_valid", &ConditionBase::_addValid, R"(_add_valid(self, datetime)
_calculate中调用
:param Datetime datetime: )")
2023-12-27 17:02:11 +08:00
.def("_calculate", &ConditionBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &ConditionBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
2020-07-13 23:52:35 +08:00
2023-12-27 17:02:11 +08:00
DEF_PICKLE(ConditionPtr);
2016-05-10 01:33:39 +08:00
2023-12-27 17:02:11 +08:00
m.def("CN_OPLine", CN_OPLine, R"(CN_OPLine(ind)
2020-07-13 23:52:35 +08:00
使线ind值线ind时
:param Indicator ind: Indicator实例
:return:
:rtype: ConditionBase)");
2023-12-27 17:02:11 +08:00
m.def("CN_Bool", CN_Bool, R"(CN_Bool(ind)
, >0
:param Indicator ind: bool型指标 KData
:return:
:rtype: ConditionBase)");
2015-01-07 01:26:14 +08:00
}