/
main.cpp
155 lines (132 loc) · 4.51 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* main.cpp
*
* Created on: 2011-12-4
* Author: fasiondog
*/
#include <cstdint>
#include <boost/python.hpp>
#include <hikyuu/hikyuu.h>
namespace py = boost::python;
using namespace hku;
void export_DataType();
void export_Constant();
void export_util();
void export_log();
void export_Datetime();
void export_TimeDelta();
void export_StockManager();
void export_Stock();
void export_Block();
void export_MarketInfo();
void export_StockTypeInfo();
void export_StockWeight();
void export_KQuery();
void export_KReord();
void export_TimeLineReord();
void export_TransRecord();
void export_KData();
void export_Parameter();
void export_save_load();
void export_io_redirect();
void export_data_driver_main();
void export_indicator_main();
void export_instance_main();
void export_trade_manage_main();
void export_trade_sys_main();
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,
KQuery::RecoverType recovertType = KQuery::NO_RECOVER) {
py::extract<KQuery> query_x(start);
if (query_x.check()) {
return getKData(market_code, query_x());
}
py::extract<int64_t> int_x(start);
if (int_x.check()) {
int64_t start_ix = 0, end_ix = 0;
if (end.is_none()) {
end_ix = Null<int64_t>();
} else {
py::extract<int64_t> int_y(end);
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!");
}
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();
export_DataType();
export_Constant();
export_util();
export_log();
export_Datetime();
export_TimeDelta();
export_MarketInfo();
export_StockTypeInfo();
export_StockWeight();
export_StockManager();
export_KQuery();
export_KReord();
export_TimeLineReord();
export_TransRecord();
export_KData();
export_Stock();
export_Block();
export_Parameter();
export_save_load();
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();
py::def("hikyuu_init", hikyuu_init);
py::def("get_version", getVersion, R"(getVersion()
:return: hikyuu 当前版本
:rtype: str)");
py::def("get_stock", getStock,
R"(get_stock(market_code)
根据"市场简称证券代码"获取对应的证券实例
:param str market_code: 格式:“市场简称证券代码”,如"sh000001"
:return: 对应的证券实例,如果实例不存在,则返回空实例,即Stock(),不抛出异常
:rtype: Stock)");
py::def(
"get_kdata", Py_GetKData,
(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),
R"(get_kdata(market_code[, start=0, end=None, ktype=Query.DAY, recover_type=Query.NO_RECOVER])
or get_kdata(market_code, query)
获取K线数据,其中 start 和 end 需同时为 int 或 同时为 Datetime。
:param str market_code: 格式:“市场简称证券代码”,如"sh000001"
:param int or Datetime start: 起始索引或起始日期
:param int or Datetime end: 终止索引或终止日期
:param Query query: 查询条件
:return: 满足查询条件的K线数据
:rtype: KData)");
}