hikyuu2/hikyuu_pywrap/trade_sys/_Slippage.cpp
2021-02-13 00:02:58 +08:00

134 lines
4.3 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.

/*
* _Slippage.cpp
*
* Created on: 2013-3-21
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/slippage/SlippageBase.h>
#include <hikyuu/trade_sys/slippage/build_in.h>
#include "../_Parameter.h"
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
class SlippageWrap : public SlippageBase, public wrapper<SlippageBase> {
public:
SlippageWrap() : SlippageBase() {}
SlippageWrap(const string& name) : SlippageBase(name) {}
virtual ~SlippageWrap() {}
void _reset() {
if (override func = get_override("_reset")) {
func();
} else {
SlippageBase::_reset();
}
}
void default_reset() {
this->SlippageBase::_reset();
}
SlippagePtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
this->get_override("_calculate");
}
price_t getRealBuyPrice(const Datetime& datetime, price_t price) {
return this->get_override("get_real_buy_price")(datetime, price);
}
price_t getRealSellPrice(const Datetime& datetime, price_t price) {
return this->get_override("get_real_sell_price")(datetime, price);
}
};
string (SlippageBase::*sp_get_name)() const = &SlippageBase::name;
void (SlippageBase::*sp_set_name)(const string&) = &SlippageBase::name;
void export_Slippage() {
class_<SlippageWrap, boost::noncopyable>("SlippageBase", R"(移滑价差算法基类
- getRealBuyPrice :
- getRealSellPrice :
- _calculate :
- _clone :
- _reset : )",
init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", sp_get_name, sp_set_name, "名称")
.add_property("to", &SlippageBase::getTO, &SlippageBase::setTO, "设置或获取交易对象")
.def("get_param", &SlippageBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &SlippageBase::setParam<object>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &SlippageBase::haveParam, "是否存在指定参数")
.def("get_real_buy_price", pure_virtual(&SlippageBase::getRealBuyPrice),
R"(get_real_buy_price(self, datetime, price)
:param Datetime datetime:
:param float price:
:return:
:rtype: float)")
.def("get_real_sell_price", pure_virtual(&SlippageBase::getRealSellPrice),
R"(get_real_sell_price(self, datetime, price)
:param Datetime datetime:
:param float price:
:return:
:rtype: float)")
.def("reset", &SlippageBase::reset, "复位操作")
.def("clone", &SlippageBase::clone, "克隆操作")
.def("_calculate", pure_virtual(&SlippageBase::_calculate), "【重载接口】子类计算接口")
.def("_reset", &SlippageBase::_reset, &SlippageWrap::default_reset,
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&SlippageBase::_clone), "【重载接口】子类克隆接口");
register_ptr_to_python<SlippagePtr>();
def("SP_FixedPercent", SP_FixedPercent, (arg("p") = 0.001), R"(SP_FixedPercent([p=0.001])
= * (1 + p) = * (1 - p)
:param float p:
:return: )");
def("SP_FixedValue", SP_FixedValue, (arg("value") = 0.01), R"(SP_FixedValuet([p=0.001])
= + = -
:param float p:
:return: )");
}