hikyuu2/hikyuu_pywrap/main.cpp

156 lines
4.6 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* main.cpp
*
* Created on: 2011-12-4
* Author: fasiondog
*/
2020-06-26 21:39:53 +08:00
#include <cstdint>
2015-01-07 01:26:14 +08:00
#include <boost/python.hpp>
#include <hikyuu/hikyuu.h>
2020-06-26 21:39:53 +08:00
namespace py = boost::python;
using namespace hku;
2015-01-07 01:26:14 +08:00
void export_DataType();
void export_Constant();
void export_util();
2019-02-11 15:20:43 +08:00
void export_log();
2015-01-07 01:26:14 +08:00
void export_Datetime();
2019-12-15 01:25:00 +08:00
void export_TimeDelta();
2015-01-07 01:26:14 +08:00
void export_StockManager();
void export_Stock();
2016-04-03 00:08:31 +08:00
void export_Block();
2015-01-07 01:26:14 +08:00
void export_MarketInfo();
void export_StockTypeInfo();
void export_StockWeight();
void export_KQuery();
void export_KReord();
2019-02-08 22:41:20 +08:00
void export_TimeLineReord();
2019-02-11 21:13:06 +08:00
void export_TransRecord();
2015-01-07 01:26:14 +08:00
void export_KData();
void export_Parameter();
void export_save_load();
void export_io_redirect();
2015-01-07 01:26:14 +08:00
2020-06-25 15:59:37 +08:00
void export_data_driver_main();
void export_indicator_main();
void export_instance_main();
void export_trade_manage_main();
void export_trade_sys_main();
2020-06-26 21:39:53 +08:00
KData Py_GetKData(const string& market_code, py::object start = py::long_(0),
py::object end = py::long_(Null<int64_t>()), KQuery::KType ktype = KQuery::DAY,
2020-06-26 21:39:53 +08:00
KQuery::RecoverType recovertType = KQuery::NO_RECOVER) {
2020-07-07 00:34:25 +08:00
py::extract<KQuery> query_x(start);
if (query_x.check()) {
return getKData(market_code, query_x());
}
py::extract<int64_t> int_x(start);
2020-06-26 21:39:53 +08:00
if (int_x.check()) {
int64_t start_ix = 0, end_ix = 0;
2020-06-26 21:39:53 +08:00
if (end.is_none()) {
end_ix = Null<int64_t>();
2020-06-26 21:39:53 +08:00
} else {
py::extract<int64_t> int_y(end);
2020-06-26 21:39:53 +08:00
if (!int_y.check()) {
HKU_THROW_EXCEPTION(
std::invalid_argument,
"The input parameters start and end must be of the same type (Datetime or int)!");
}
end_ix = int_y();
}
start_ix = int_x();
return getKData(market_code, start_ix, end_ix, ktype, recovertType);
}
py::extract<Datetime> date_x(start);
if (!date_x.check()) {
HKU_THROW_EXCEPTION(std::invalid_argument,
"The type of input parameter start must be Datetime or int!");
}
2020-06-25 18:22:51 +08:00
2020-06-26 21:39:53 +08:00
Datetime start_date, end_date;
if (end.is_none()) {
end_date = Null<Datetime>();
} else {
py::extract<Datetime> date_y(end);
if (!date_y.check()) {
HKU_THROW_EXCEPTION(
std::invalid_argument,
"The input parameters start and end must be of the same type (Datetime or int)!");
}
end_date = date_y();
}
start_date = date_x();
return getKData(market_code, start_date, end_date, ktype, recovertType);
}
BOOST_PYTHON_MODULE(core) {
py::docstring_options doc_options;
doc_options.disable_signatures();
2015-01-07 01:26:14 +08:00
export_DataType();
export_Constant();
export_util();
2019-02-11 15:20:43 +08:00
export_log();
2015-01-07 01:26:14 +08:00
export_Datetime();
2019-12-15 01:25:00 +08:00
export_TimeDelta();
2015-01-07 01:26:14 +08:00
export_MarketInfo();
export_StockTypeInfo();
export_StockWeight();
export_StockManager();
export_KQuery();
export_KReord();
2019-02-08 22:41:20 +08:00
export_TimeLineReord();
2019-02-11 21:13:06 +08:00
export_TransRecord();
2015-01-07 01:26:14 +08:00
export_KData();
export_Stock();
2016-04-03 00:08:31 +08:00
export_Block();
2015-01-07 01:26:14 +08:00
export_Parameter();
export_save_load();
2020-06-25 15:59:37 +08:00
export_data_driver_main();
export_indicator_main();
export_instance_main();
export_trade_sys_main();
export_trade_manage_main(); // must after export_trade_sys_main
export_io_redirect();
2020-06-26 21:39:53 +08:00
py::def("hikyuu_init", hikyuu_init, (py::arg("filename"), py::arg("ignore_preload") = false));
2020-07-06 00:41:32 +08:00
py::def("get_version", getVersion, R"(getVersion()
2020-06-26 21:39:53 +08:00
:return: hikyuu
:rtype: str)");
2020-07-06 00:41:32 +08:00
py::def("get_stock", getStock,
R"(get_stock(market_code)
2020-06-26 21:39:53 +08:00
"市场简称证券代码"
:param str market_code: "sh000001"
:return: Stock()
:rtype: Stock)");
py::def(
2020-07-07 00:34:25 +08:00
"get_kdata", Py_GetKData,
2020-06-26 21:39:53 +08:00
(py::arg("market_code"), py::arg("start") = py::long_(0), py::arg("end") = py::object(),
py::arg("ktype") = KQuery::DAY, py::arg("recover_type") = KQuery::NO_RECOVER),
2020-07-06 00:41:32 +08:00
R"(get_kdata(market_code[, start=0, end=None, ktype=Query.DAY, recover_type=Query.NO_RECOVER])
2020-06-26 21:39:53 +08:00
2020-07-07 00:34:25 +08:00
or get_kdata(market_code, query)
2020-06-26 21:39:53 +08:00
K线数据 start end int Datetime
:param str market_code: "sh000001"
:param int or Datetime start:
:param int or Datetime end:
2020-07-07 00:34:25 +08:00
:param Query query:
2020-06-26 21:39:53 +08:00
:return: K线数据
:rtype: KData)");
2015-01-07 01:26:14 +08:00
}