hikyuu2/hikyuu_pywrap/trade_sys/_Environment.cpp

106 lines
3.2 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _Environment.cpp
*
* Created on: 2013-3-2
* Author: fasiondog
*/
/*
* _TradeRecord.cpp
*
* Created on: 2013-2-25
* Author: fasiondog
*/
#include <hikyuu/trade_sys/environment/EnvironmentBase.h>
2016-05-19 01:06:00 +08:00
#include <hikyuu/trade_sys/environment/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 PyEnvironmentBase : public EnvironmentBase {
PY_CLONE(PyEnvironmentBase, EnvironmentBase)
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
public:
using EnvironmentBase::EnvironmentBase;
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, EnvironmentBase, _calculate, );
2015-01-07 01:26:14 +08:00
}
2023-12-27 17:02:11 +08:00
void _reset() override {
PYBIND11_OVERLOAD(void, EnvironmentBase, _reset, );
2016-05-18 02:03:29 +08:00
}
2015-01-07 01:26:14 +08:00
};
2023-12-27 17:02:11 +08:00
void export_Environment(py::module& m) {
py::class_<EnvironmentBase, EnvironmentPtr, PyEnvironmentBase>(
m, "EnvironmentBase",
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&>())
.def("__str__", to_py_str<EnvironmentBase>)
.def("__repr__", to_py_str<EnvironmentBase>)
2020-07-13 23:52:35 +08:00
2023-12-27 17:02:11 +08:00
.def_property("name", py::overload_cast<void>(&EnvironmentBase::name, py::const_),
py::overload_cast<const string&>(&EnvironmentBase::name),
py::return_value_policy::copy, "名称")
.def_property("query", &EnvironmentBase::getQuery, &EnvironmentBase::setQuery,
py::return_value_policy::copy, "设置或获取查询条件")
2020-07-13 23:52:35 +08:00
.def("get_param", &EnvironmentBase::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", &EnvironmentBase::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("haveParam", &EnvironmentBase::haveParam, "是否存在指定参数")
.def("is_valid", &EnvironmentBase::isValid, R"(is_valid(self, datetime)
:param Datetime datetime:
:return: True | False )")
.def("_add_valid", &EnvironmentBase::_addValid, R"(_add_valid(self, datetime)
_calculate中调用
:param Datetime datetime: )")
.def("reset", &EnvironmentBase::reset, "复位操作")
.def("clone", &EnvironmentBase::clone, "克隆操作")
2023-12-27 17:02:11 +08:00
.def("_reset", &EnvironmentBase::_reset, "【重载接口】子类复位接口,用于复位内部私有变量")
.def("_calculate", &EnvironmentBase::_calculate, "【重载接口】子类计算接口")
2020-07-13 23:52:35 +08:00
2023-12-27 17:02:11 +08:00
DEF_PICKLE(EnvironmentPtr);
2016-05-19 01:06:00 +08:00
2023-12-27 17:02:11 +08:00
m.def("EV_TwoLine", EV_TwoLine, py::arg("fast"), py::arg("slow"), py::arg("market") = "SH",
R"(EV_TwoLine(fast, slow[, market = 'SH'])
2015-01-07 01:26:14 +08:00
2020-07-13 23:52:35 +08:00
线线线
2015-01-07 01:26:14 +08:00
2020-07-13 23:52:35 +08:00
:param Indicator fast: 线
:param Indicator slow: 线
:param string market: )");
}