hikyuu2/hikyuu_pywrap/_KData.cpp

109 lines
3.7 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _KData.cpp
*
* Created on: 2012-9-28
* Author: fasiondog
*/
#include <hikyuu/serialization/KData_serialization.h>
#include <hikyuu/indicator/crt/KDATA.h>
2023-12-27 02:16:10 +08:00
#include "pybind_utils.h"
2015-01-07 01:26:14 +08:00
using namespace hku;
2023-12-27 02:16:10 +08:00
namespace py = pybind11;
2015-01-07 01:26:14 +08:00
2024-02-25 22:53:44 +08:00
const KRecord& (KData::*KData_getKRecord1)(size_t pos) const = &KData::getKRecord;
const KRecord& (KData::*KData_getKRecord2)(Datetime datetime) const = &KData::getKRecord;
2020-10-12 01:14:16 +08:00
2023-12-27 02:16:10 +08:00
void export_KData(py::module& m) {
py::class_<KData>(
m, "KData",
"通过 Stock.getKData 获取的K线数据由 KRecord 组成的数组,可象 list 一样进行遍历")
.def(py::init<>())
2020-07-04 00:15:54 +08:00
.def("__str__", &KData::toString)
.def("__repr__", &KData::toString)
2020-07-07 00:34:25 +08:00
2023-12-27 02:16:10 +08:00
.def_property_readonly("start_pos", &KData::startPos,
"获取在原始K线记录中对应的起始位置如果KData为空返回0")
.def_property_readonly(
2020-07-08 00:18:51 +08:00
"end_pos", &KData::endPos,
2020-07-04 23:54:02 +08:00
"获取在原始K线记录中对应范围的下一条记录的位置如果为空返回0,其他等于lastPos + 1")
2023-12-27 02:16:10 +08:00
.def_property_readonly(
"last_pos", &KData::lastPos,
"获取在原始K线记录中对应的最后一条记录的位置如果为空返回0,其他等于endPos - 1")
.def_property_readonly("open", &KData::open,
"返回包含开盘价的 Indicator 实例,相当于 OPEN(k)")
.def_property_readonly("close", &KData::close,
"返回包含收盘价的 Indicator 实例,相当于 CLOSE(k)")
.def_property_readonly("high", &KData::high,
"返回包含最高价的 Indicator 实例,相当于 HIGH(k)")
.def_property_readonly("low", &KData::low, "返回包含最低价的 Indicator 实例,相当于 LOW(k)")
.def_property_readonly("amo", &KData::amo, "返回包含成交金额的 Indicator 实例,相当于 AMO(k)")
.def_property_readonly("vol", &KData::vol, "返回包含成交量的 Indicator 实例,相当于 VOL(k)")
2020-07-04 23:54:02 +08:00
2020-07-12 20:46:34 +08:00
.def("get_datetime_list", &KData::getDatetimeList, R"(get_datetime_list(self)
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:rtype: DatetimeList)")
2020-07-04 23:54:02 +08:00
2024-02-25 22:53:44 +08:00
.def("get", KData_getKRecord1, py::return_value_policy::copy, R"(get(self, pos)
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
K线记录
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:param int pos:
:rtype: KRecord)")
2020-07-04 23:54:02 +08:00
2024-02-25 22:53:44 +08:00
.def("get_by_datetime", KData_getKRecord2, py::return_value_policy::copy,
R"(get_by_datetime(self, datetime)
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
K线记录
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:param Datetime datetime:
:rtype: KRecord)")
2020-07-04 23:54:02 +08:00
2020-07-04 00:15:54 +08:00
.def("_getPos", &KData::getPos) // python中需要将Null的情况改写为None
2022-01-25 01:28:27 +08:00
.def("_getPosInStock", &KData::getPosInStock)
2022-01-25 01:08:08 +08:00
2020-07-04 23:54:02 +08:00
.def("empty", &KData::empty, R"(empty(self)
2023-12-27 02:16:10 +08:00
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:rtype: bool)")
2020-07-04 23:54:02 +08:00
2024-02-25 22:53:44 +08:00
.def("get_query", &KData::getQuery, py::return_value_policy::copy, R"(get_query(self)
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:rtype: KQuery)")
2020-07-04 23:54:02 +08:00
2024-02-25 22:53:44 +08:00
.def("get_stock", &KData::getStock, py::return_value_policy::copy, R"(get_stock(self)
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
Stock
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:rtype: Stock)")
2020-07-04 23:54:02 +08:00
2024-04-02 12:27:20 +08:00
.def("get_kdata", &KData::getKData, R"(get_kdata(self, start_date, end_date)
KData KData KData
:param Datetime start:
:param Datetime end:
:rtype: KData)")
2020-07-04 23:54:02 +08:00
.def("tocsv", &KData::tocsv, R"(tocsv(self, filename)
2023-12-27 02:16:10 +08:00
CSV文件
2020-07-04 23:54:02 +08:00
2023-12-27 02:16:10 +08:00
:param str filename: )")
2020-07-04 00:15:54 +08:00
.def("__len__", &KData::size)
2023-12-27 02:16:10 +08:00
.def(py::self == py::self)
.def(py::self != py::self)
2023-12-27 02:16:10 +08:00
DEF_PICKLE(KData);
2015-01-07 01:26:14 +08:00
}