hikyuu2/hikyuu_pywrap/_Stock.cpp
2023-12-27 02:16:10 +08:00

188 lines
6.9 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.

/*
* _Stock.cpp
*
* Created on: 2011-12-4
* Author: fasiondog
*/
#include <hikyuu/serialization/Stock_serialization.h>
#include <hikyuu/KData.h>
#include "pybind_utils.h"
using namespace hku;
namespace py = pybind11;
// BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getIndex_overloads, getIndex, 1, 2)
KRecord (Stock::*getKRecord1)(size_t pos, KQuery::KType kType) const = &Stock::getKRecord;
KRecord (Stock::*getKRecord2)(const Datetime&, KQuery::KType kType) const = &Stock::getKRecord;
void export_Stock(py::module& m) {
py::class_<Stock>(m, "Stock", "证券对象")
.def(py::init<>())
.def(py::init<const string&, const string&, const string&>(), py::arg("market"),
py::arg("code"), py::arg("name"))
.def(py::init<const Stock&>())
.def("__str__", &Stock::toString)
.def("__repr__", &Stock::toString)
.def_property_readonly("id", &Stock::id, "内部id")
.def_property_readonly("market", py::overload_cast<void>(&Stock::market, py::const_),
"所属市场简称,市场简称是市场的唯一标识")
.def_property_readonly("code", py::overload_cast<void>(&Stock::code, py::const_), "证券代码")
.def_property_readonly("market_code",
py::overload_cast<void>(&Stock::market_code, py::const_),
"市场简称+证券代码,如: sh000001")
.def_property_readonly("name", py::overload_cast<void>(&Stock::name, py::const_), "证券名称")
.def_property_readonly("type", &Stock::type, "证券类型参见constant")
.def_property_readonly("valid", &Stock::valid, "该证券当前是否有效")
.def_property_readonly("start_datetime", &Stock::startDatetime, "证券起始日期")
.def_property_readonly("last_datetime", &Stock::lastDatetime, "证券最后日期")
.def_property_readonly("tick", &Stock::tick, "最小跳动量")
.def_property_readonly("tick_value", &Stock::tickValue, "最小跳动量价值")
.def_property_readonly("unit", &Stock::unit, "每单位价值 = tickValue / tick")
.def_property_readonly("precision", &Stock::precision, "价格精度")
.def_property_readonly("atom", &Stock::atom, "最小交易数量同min_tradeNumber")
.def_property_readonly("min_trade_number", &Stock::minTradeNumber, "最小交易数量")
.def_property_readonly("max_trade_number", &Stock::maxTradeNumber, "最大交易数量")
.def("is_null", &Stock::isNull, R"(is_null(self)
Null
:rtype: bool)")
.def("is_buffer", &Stock::isBuffer, R"(指定类型的K线数据是否被缓存)")
.def("get_kdata", &Stock::getKData, R"(get_kdata(self, query)
K线数据
:param Query query:
:return: K线数据
:rtype: KData)")
.def("get_timeline_list", &Stock::getTimeLineList, R"(get_timeline_list(self, query)
线
:param Query query: K线类型
:rtype: TimeLineList)")
.def("get_trans_list", &Stock::getTransList, R"(get_trans_list(self, query)
:param Query query: K线类型
:rtype: TransList)")
.def("get_count", &Stock::getCount, py::arg("ktype") = KQuery::DAY,
R"(get_count(self, [ktype=Query.DAY])
K线数据量
:param Query.KType ktype: K线数据类别
:return: K线记录数
:rtype: int)")
.def("get_market_value", &Stock::getMarketValue, R"(get_market_value(self, date, ktype)
:param Datetime date:
:param Query.KType ktype: K线数据类别
:return:
:rtype: float)")
.def("get_krecord", getKRecord1, py::arg("pos"), py::arg("ktype") = KQuery::DAY,
R"(get_krecord(self, pos[, ktype=Query.DAY])
K线数据记录
:param int pos:
:param Query.KType ktype: K线数据类别
:return: K线记录
:rtype: KRecord)")
.def("get_krecord", getKRecord2, py::arg("date"), py::arg("ktype") = KQuery::DAY,
R"(get_krecord(self, datetime[, ktype=Query.DAY])
线/线KRecord
:param Datetime datetime:
:param Query.KType ktype: K线数据类别
:return: K线记录
:rtype: KRecord)")
.def("get_krecord_list", &Stock::getKRecordList, R"(get_krecord_list(self, start, end,
ktype)
K线记录 [start, end)使.
:param int start:
:param int end:
:param Query.KType ktype: K线类别
:return: K线记录列表
:rtype: KRecordList)")
.def("get_datetime_list", &Stock::getDatetimeList, R"(get_datetime_list(self, query)
:param Query query:
:rtype: DatetimeList)")
.def("get_finance_info", &Stock::getFinanceInfo, R"(get_finance_info(self)
:rtype: Parameter)")
.def("get_history_finance_info", &Stock::getHistoryFinanceInfo,
R"(get_history_finance_info(self, date)
, https://hikyuu.org/finance_fields.html
:param Datetime date: 0331063009301231 Datetime(201109300000)
:rtype: PriceList)")
.def("realtime_update", &Stock::realtimeUpdate, py::arg("krecord"),
py::arg("ktype") = KQuery::DAY,
R"(realtime_update(self, krecord)
线
:param KRecord krecord: K线记录
:param KQuery.KType ktype: K 线)")
.def("get_weight", &Stock::getWeight, py::arg("start") = Datetime::min(),
py::arg("end") = Datetime(),
R"(get_weight(self, [start, end])
[start,end)
:param Datetime start:
:param Datetime end:
:rtype: StockWeightList)")
.def("load_kdata_to_buffer", &Stock::loadKDataToBuffer, R"(load_kdata_to_buffer(self,
ktype)
K线数据加载至内存缓存
:param Query.KType ktype: K线类型)")
.def("release_kdata_buffer", &Stock::releaseKDataBuffer, R"(release_kdata_buffer(self,
ktype)
K线数据
:param Query.KType ktype: K线类型)")
.def(py::self == py::self)
.def(py::self != py::self)
DEF_PICKLE(Stock);
}