hikyuu2/hikyuu_pywrap/trade_sys/_Slippage.cpp

85 lines
2.5 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _Slippage.cpp
*
* Created on: 2013-3-21
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/slippage/SlippageBase.h>
2016-05-07 02:21:07 +08:00
#include <hikyuu/trade_sys/slippage/build_in.h>
#include "../_Parameter.h"
#include "../pickle_support.h"
2015-01-07 01:26:14 +08:00
using namespace boost::python;
using namespace hku;
class SlippageWrap : public SlippageBase, public wrapper<SlippageBase> {
public:
2016-05-07 02:21:07 +08:00
SlippageWrap() : SlippageBase() {}
2015-01-07 01:26:14 +08:00
SlippageWrap(const string& name): SlippageBase(name) {}
virtual ~SlippageWrap() {}
void _reset() {
2016-05-07 02:21:07 +08:00
if (override func = get_override("_reset")) {
func();
2017-04-13 02:03:02 +08:00
} else {
SlippageBase::_reset();
2016-05-07 02:21:07 +08:00
}
}
void default_reset() {
this->SlippageBase::_reset();
2015-01-07 01:26:14 +08:00
}
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("getRealBuyPrice")(datetime, price);
}
price_t getRealSellPrice(const Datetime& datetime, price_t price) {
return this->get_override("getRealSellPrice")(datetime, price);
}
};
2017-06-17 16:59:15 +08:00
string (SlippageBase::*sp_get_name)() const = &SlippageBase::name;
void (SlippageBase::*sp_set_name)(const string&) = &SlippageBase::name;
2016-05-07 02:21:07 +08:00
2015-01-07 01:26:14 +08:00
void export_Slippage() {
2016-05-07 02:21:07 +08:00
class_<SlippageWrap, boost::noncopyable>("SlippageBase", init<>())
.def(init<const string&>())
2015-01-07 01:26:14 +08:00
.def(self_ns::str(self))
2017-06-17 16:59:15 +08:00
.add_property("name", sp_get_name, sp_set_name)
2016-05-07 02:21:07 +08:00
.def("getParam", &SlippageBase::getParam<boost::any>)
.def("setParam", &SlippageBase::setParam<object>)
2019-06-05 21:44:17 +08:00
.def("haveParam", &SlippageBase::haveParam)
2015-01-07 01:26:14 +08:00
.def("setTO", &SlippageBase::setTO)
2016-05-07 02:21:07 +08:00
.def("getTO", &SlippageBase::getTO)
2015-01-07 01:26:14 +08:00
.def("getRealBuyPrice", pure_virtual(&SlippageBase::getRealBuyPrice))
.def("getRealSellPrice", pure_virtual(&SlippageBase::getRealSellPrice))
.def("reset", &SlippageBase::reset)
.def("clone", &SlippageBase::clone)
.def("_calculate", pure_virtual(&SlippageBase::_calculate))
2016-05-07 02:21:07 +08:00
.def("_reset", &SlippageBase::_reset, &SlippageWrap::default_reset)
2015-01-07 01:26:14 +08:00
.def("_clone", pure_virtual(&SlippageBase::_clone))
;
register_ptr_to_python<SlippagePtr>();
2016-05-07 02:21:07 +08:00
2016-07-09 22:37:42 +08:00
def("SL_FixedPercent", SP_FixedPercent, (arg("p") = 0.001));
def("SL_FixedValue", SP_FixedValue, (arg("value") = 0.01));
2015-01-07 01:26:14 +08:00
}