hikyuu2/hikyuu_pywrap/trade_sys/_Condition.cpp
2024-05-13 05:23:37 +08:00

147 lines
5.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* _Condition.cpp
*
* Created on: 2013-3-10
* Author: fasiondog
*/
#include <hikyuu/trade_sys/condition/build_in.h>
#include <hikyuu/trade_sys/condition/imp/AndCondition.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
class PyConditionBase : public ConditionBase {
PY_CLONE(PyConditionBase, ConditionBase)
public:
using ConditionBase::ConditionBase;
PyConditionBase(const ConditionBase& base) : ConditionBase(base) {}
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, ConditionBase, _calculate, );
}
void _reset() override {
PYBIND11_OVERLOAD(void, ConditionBase, _reset, );
}
};
void export_Condition(py::module& m) {
py::class_<ConditionBase, ConditionPtr, PyConditionBase>(
m, "ConditionBase", py::dynamic_attr(),
R"(系统有效条件基类自定义系统有效条件接口:
- _calculate :
- _clone :
- _reset : )")
.def(py::init<>())
.def(py::init<const ConditionBase&>())
.def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
.def("__str__", to_py_str<ConditionBase>)
.def("__repr__", to_py_str<ConditionBase>)
.def_property("name", py::overload_cast<>(&ConditionBase::name, py::const_),
py::overload_cast<const string&>(&ConditionBase::name),
py::return_value_policy::copy, "名称")
.def_property("to", &ConditionBase::getTO, &ConditionBase::setTO, "设置或获取交易对象")
.def_property("tm", &ConditionBase::getTM, &ConditionBase::setTM, "设置或获取交易管理账户")
.def_property("sg", &ConditionBase::getSG, &ConditionBase::setSG, "设置或获取交易信号指示器")
.def("get_param", &ConditionBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &ConditionBase::setParam<boost::any>, R"(set_param(self, name, value)
: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)")
.def("_add_valid", &ConditionBase::_addValid, py::arg("datetime"), py::arg("value") = 1.0,
R"(_add_valid(self, datetime)
_calculate中调用
:param Datetime datetime: )")
.def("_calculate", &ConditionBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &ConditionBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
.def("__len__", &ConditionBase::size)
.def("__getitem__",
[](const ConditionPtr& self, int64_t i) {
size_t total = self->size();
int64_t pos = i < 0 ? total + i : i;
return self->at(pos);
})
.def("__and__",
[](const ConditionPtr& self, const ConditionPtr& other) { return self & other; })
.def("__or__",
[](const ConditionPtr& self, const ConditionPtr& other) { return self | other; })
.def("__add__",
[](const ConditionPtr& self, const ConditionPtr& other) { return self + other; })
.def("__sub__",
[](const ConditionPtr& self, const ConditionPtr& other) { return self - other; })
.def("__mul__",
[](const ConditionPtr& self, const ConditionPtr& other) { return self * other; })
.def("__truediv__",
[](const ConditionPtr& self, const ConditionPtr& other) { return self / other; })
DEF_PICKLE(ConditionPtr);
m.def("CN_OPLine", CN_OPLine, R"(CN_OPLine(ind)
使线ind值线ind时
:param Indicator ind: Indicator实例
:return:
:rtype: ConditionBase)");
m.def("CN_Bool", CN_Bool, R"(CN_Bool(ind)
, >0
:param Indicator ind: bool型指标 KData
:return:
:rtype: ConditionBase)");
}