This commit is contained in:
fasiondog 2020-07-08 00:18:51 +08:00
parent c69851f8ff
commit 3cd7170768
12 changed files with 295 additions and 246 deletions

View File

@ -46,7 +46,7 @@ TimeDelta 的运算规则基本与 datetime.timedelta 相同。
转化生成 python 的datetime
.. py:method:: isNull(self)
.. py:method:: is_null(self)
是否是Null值, 即是否等于 constant.null_datetime
@ -64,118 +64,118 @@ TimeDelta 的运算规则基本与 datetime.timedelta 相同。
:param TimeDelta td: 指定时长
:rtype: Datetime
.. py:method:: dayOfWeek(self)
.. py:method:: day_of_week(self)
返回是一周中的第几天周日为0周一为1
:rtype: int
.. py:method:: dateOfWeek(self, day)
.. py:method:: date_of_week(self, day)
返回指定的本周中第几天的日期周日为0天周六为第6天
:param int day: 指明本周的第几天如小于则认为为第0天如大于6则认为为第6天
:rtype: Datetime
.. py:method:: dayOfYear(self)
.. py:method:: day_of_year(self)
返回一年中的第几天1月1日为一年中的第1天
:rtype: int
.. py:method:: startOfDay(self)
.. py:method:: start_of_day(self)
返回当天 0点0分0秒
.. py:method:: endOfDay(self)
.. py:method:: end_of_day(self)
返回当日 23点59分59秒
.. py:method:: startOfWeek(self)
.. py:method:: start_of_week(self)
返回周起始日期(周一)
.. py:method:: endOfWeek(self)
.. py:method:: end_of_week(self)
返回周结束日期(周日)
.. py:method:: startOfMonth(self)
.. py:method:: start_of_month(self)
返回月度起始日期
.. py:method:: endOfMonth(self)
.. py:method:: end_of_month(self)
返回月末最后一天日期
.. py:method:: startOfQuarter(self)
.. py:method:: start_of_quarter(self)
返回季度起始日期
.. py:method:: endOfQuarter(self)
.. py:method:: end_of_quarter(self)
返回季度结束日期
.. py:method:: startOfHalfyear(self)
.. py:method:: start_of_halfyear(self)
返回半年度起始日期
.. py:method:: endOfHalfyear(self)
.. py:method:: end_of_halfyear(self)
返回半年度结束日期
.. py:method:: startOfYear(self)
.. py:method:: start_of_year(self)
返回年度起始日期
.. py:method:: endOfYear(self)
.. py:method:: end_of_year(self)
返回年度结束日期
.. py:method:: nextDay(self)
.. py:method:: next_day(self)
返回下一自然日
.. py:method:: nextWeek(self)
.. py:method:: next_week(self)
返回下周周一日期
.. py:method:: nextMonth(self)
.. py:method:: next_month(self)
返回下月首日日期
.. py:method:: nextQuarter(self)
.. py:method:: next_quarter(self)
返回下一季度首日日期
.. py:method:: nextHalfyear(self)
.. py:method:: next_halfyear(self)
返回下一半年度首日日期
.. py:method:: nextYear(self)
.. py:method:: next_year(self)
返回下一年度首日日期
.. py:method:: preDay(self)
.. py:method:: pre_day(self)
返回前一自然日日期
.. py:method:: preWeek(self)
.. py:method:: pre_week(self)
返回上周周一日期
.. py:method:: preMonth(self)
.. py:method:: pre_month(self)
返回上月首日日期
.. py:method:: preQuarter(self)
.. py:method:: pre_quarter(self)
返回上一季度首日日期
.. py:method:: preHalfyear(self)
.. py:method:: pre_halfyear(self)
返回上一半年度首日日期
.. py:method:: preYear(self)
.. py:method:: pre_year(self)
返回上一年度首日日期
@ -363,21 +363,21 @@ K线数据
.. py:class:: KData
通过 Stock.getKData 获取的K线数据由 KRecord 组成的数组,可象 list 一样进行遍历
通过 Stock.get_kdata 获取的K线数据由 KRecord 组成的数组,可象 list 一样进行遍历
.. py:attribute:: startPos
.. py:attribute:: start_pos
获取在原始K线记录中对应的起始位置如果KData为空返回0
.. py:attribute:: lastPos
.. py:attribute:: last_pos
获取在原始K线记录中对应的最后一条记录的位置如果为空返回0,其他等于endPos - 1
.. py:attribute:: endPos
.. py:attribute:: end_pos
获取在原始K线记录中对应范围的下一条记录的位置如果为空返回0,其他等于lastPos + 1
.. py:method:: getDatetimeList()
.. py:method:: get_date_list()
返回交易日期列表
@ -390,14 +390,14 @@ K线数据
:param int pos: 位置索引
:rtype: KRecord
.. py:method:: getByDate(datetime)
.. py:method:: get_by_date(datetime)
获取指定时间的K线记录。
:param Datetime datetime: 指定的日期
:rtype: KRecord
.. py:method:: getPos(datetime)
.. py:method:: get_pos(datetime)
获取指定时间对应的索引位置
@ -410,13 +410,13 @@ K线数据
:rtype: bool
.. py:method:: getQuery()
.. py:method:: get_query()
获取关联的查询条件
:rtype: Query
.. py:method:: getStock()
.. py:method:: get_stock()
获取关联的Stock

View File

@ -7,30 +7,6 @@
构建K线查询条件
-----------------
.. py:function:: QueryByDate([start=None, end=None, kType=Query.DAY, recoverType=Query.NO_RECOVER])
构建按日期 [start, end) 方式获取K线数据条件
:param Datetime start: 起始日期
:param Datetime end: 结束日期
:param Query.KType kType: K线数据类型如日线、分钟线等
:param Query.RecoverType recoverType: 复权类型
:return: 查询条件
:rtype: Query
.. py:class:: QueryByIndex([start=0, end=None, kType=Query.KType.DAT, recoverType=Query.RecoverType.NO_RECOVER])
构建按索引 [start, end) 方式获取K线数据条件等同于直接使用 Query 构造
:param ind start: 起始日期
:param ind end: 结束日期
:param Query.KType kType: K线数据类型如日线、分钟线等
:param Query.RecoverType recoverType: 复权类型
:return: 查询条件
:rtype: Query
.. py:class:: Query
对 Query 的简单包装,并简化定义相关常量,可视同为 :py:class:`Query`
@ -70,23 +46,23 @@
结束索引,当按日期查询方式创建时无效,为 constant.null_int64
.. py:attribute:: startDatetime
.. py:attribute:: start_date
起始日期,当按索引查询方式创建时无效,为 constant.null_datetime
.. py:attribute:: endDatetime
.. py:attribute:: end_date
结束日期,当按索引查询方式创建时无效,为 constant.null_datetime
.. py:attribute:: queryType
.. py:attribute:: query_type
查询方式
.. py:attribute:: kType
.. py:attribute:: ktype
查询的K线类型
.. py:attribute:: recoverType
.. py:attribute:: recover_type
查询的复权类型
@ -123,47 +99,6 @@
- EQUAL_FORWARD - 等比前向复权
- EQUAL_BACKWARD - 等比后向复权
.. py:staticmethod:: getQueryTypeName(queryType)
获取queryType名称用于显示输出
:param Query.QueryType queryType: 查询类型
:rtype: str
.. py:staticmethod:: getKTypeName(kType)
获取KType名称用于显示输出
:param Query.KType kType: K线类型
:rtype: str
.. py:staticmethod:: getRecoverTypeName(recoverType)
获取recoverType名称用于显示输出
:param Query.RecoverType recoverType: 复权类型
:rtype: str
.. py:staticmethod:: getQueryTypeEnum(queryType)
根据字符串名称获取相应的queryType枚举值
:param str queryType: 字符串名称如“DATE”
:rtype: Query.QueryType
.. py:staticmethod:: getKTypeEnum(ktype)
根据字符串名称,获取相应的枚举值
:param str ktype: 字符串名称如“DAY”
:rtype: Query.KType
.. py:staticmethod:: getRecoverTypeEnum(recoverType)
根据字符串名称,获取相应的枚举值
:param str recoverType: 字符串名称如“NO_RECOVER”
:rtype: Query.RecoverType
StockManager/Block/Stock
@ -587,7 +522,7 @@ StockManager/Block/Stock
.. py:attribute:: name : 市场全称
.. py:attribute:: description :描述说明
.. py:attribute:: code : 该市场对应的主要指数,用于获取交易日历
.. py:attribute:: lastDate : 该市场K线数据最后交易日期
.. py:attribute:: last_date : 该市场K线数据最后交易日期

View File

@ -165,32 +165,6 @@ zsbk_sz180 = sm.getBlock("指数板块", "上证180")
zsbk_hs300 = sm.getBlock("指数板块", "沪深300")
zsbk_zz100 = sm.getBlock("指数板块", "沪深300")
# ------------------------------------------------------------------
# 重定义Query
# ------------------------------------------------------------------
Query.INDEX = Query.QueryType.INDEX
Query.DATE = Query.QueryType.DATE
Query.DAY = "DAY"
Query.WEEK = "WEEK"
Query.MONTH = "MONTH"
Query.QUARTER = "QUARTER"
Query.HALFYEAR = "HALFYEAR"
Query.YEAR = "YEAR"
Query.MIN = "MIN"
Query.MIN5 = "MIN5"
Query.MIN15 = "MIN15"
Query.MIN30 = "MIN30"
Query.MIN60 = "MIN60"
Query.HOUR2 = "HOUR2"
Query.HOUR4 = "HOUR4"
Query.HOUR6 = "HOUR6"
Query.HOUR12 = "HOUR12"
Query.NO_RECOVER = Query.RecoverType.NO_RECOVER
Query.FORWARD = Query.RecoverType.FORWARD
Query.BACKWARD = Query.RecoverType.BACKWARD
Query.EQUAL_FORWARD = Query.RecoverType.EQUAL_FORWARD
Query.EQUAL_BACKWARD = Query.RecoverType.EQUAL_BACKWARD
# ==============================================================================
#
# 设置关键类型简称

View File

@ -25,10 +25,13 @@ def deprecated_attr(name_dict):
def wrapfunc(self, name):
clzname = self.__class__.__name__
if name in name_dict:
print(
'Deprecated warning: the "{}.{}" will be deprecated, please use: "{}.{}"'.
format(clzname, name, clzname, name_dict[name])
)
if name_dict[name] is None:
print('Removed warning: the {}.{} will be removed!'.format(clzname, name))
else:
print(
'Deprecated warning: the "{}.{}" will be deprecated, please use: "{}.{}"'.
format(clzname, name, clzname, name_dict[name])
)
return func(self, name_dict[name])
return func(self, name)
@ -54,6 +57,26 @@ def getStock(querystr):
pass
@deprecated_func(Query, 'KQuery', 'Query')
def KQuery(*args, **kwargs):
pass
@deprecated_func(Query, 'QueryByIndex', 'Query')
def QueryByIndex(*args, **kwargs):
pass
@deprecated_func(Query, 'QueryByDate', 'Query')
def QueryByDate(*args, **kwargs):
pass
@deprecated_func(get_date_range, 'getDateRange', 'get_date_range')
def getDateRange(*args, **kwargs):
pass
#--------------------------------------------------------------------
#
# 待废弃属性
@ -61,6 +84,45 @@ def getStock(querystr):
#--------------------------------------------------------------------
@deprecated_attr(
{
'isNull': 'is_null',
'dayOfWeek': 'day_of_week',
'dayOfYear': 'day_of_year',
'startOfDay': 'start_of_day',
'endOfDay': 'end_of_day',
'nextDay': 'next_day',
'nextWeek': 'next_week',
'nextMonth': 'next_month',
'nextQuarter': 'next_quarter',
'nextHalfyear': 'next_halfyear',
'nextYear': 'next_year',
'preDay': 'pre_day',
'preWeek': 'pre_week',
'preMonth': 'pre_month',
'preQuarter': 'pre_quarter',
'preHalfyear': 'pre_halfyear',
'preYear': 'pre_year',
'dateOfWeek': 'date_of_week',
'startOfWeek': 'start_of_week',
'endOfWeek': 'end_of_week',
'startOfMonth': 'start_of_month',
'endOfMonth': 'end_of_month',
'startOfQuarter': 'start_of_quarter',
'endOfQuarter': 'end_of_quarter',
'startOfHalfyear': 'start_of_halfyear',
'endOfHalfyear': 'end_of_halfyear',
'startOfYear': 'start_of_year',
'endOfYear': 'end_of_year'
}
)
def Datetime_getattr(self, name):
return getattr(self, name)
Datetime.__getattr__ = Datetime_getattr
@deprecated_attr({'size': '__len__', 'get': '__getitem__'})
def Block_getattr(self, name):
return getattr(self, name)
@ -69,6 +131,25 @@ def Block_getattr(self, name):
Block.__getattr__ = Block_getattr
@deprecated_attr(
{
'startPos': 'start_pos',
'endPos': 'end_pos',
'lastPos': 'last_pos',
'getPos': 'get_pos',
'getDatetimeList': 'get_date_list',
'getByDate': 'get_by_date',
'getQuery': 'get_query',
'getStock': 'get_stock',
}
)
def KData_getattr(self, name):
return getattr(self, name)
KData.__getattr__ = KData_getattr
@deprecated_attr(
{
'openPrice': 'open',
@ -86,6 +167,30 @@ def KRecord_getattr(self, name):
KRecord.__getattr__ = KRecord_getattr
@deprecated_attr({'lastDate': 'last_date'})
def MarketInfo_getattr(self, name):
return getattr(self, name)
MarketInfo.__getattr__ = MarketInfo_getattr
@deprecated_attr(
{
'startDatetime': 'start_date',
'endDatetime': 'end_date',
'queryType': 'query_type',
'kType': 'ktype',
'recoverType': 'recover_type'
}
)
def Query_getattr(self, name):
return getattr(self, name)
Query.__getattr__ = Query_getattr
@deprecated_attr({'getKData': 'get_kdata'})
def Stock_getattr(self, name):
return getattr(self, name)

View File

@ -35,9 +35,7 @@
from pylab import plot
from numpy import mean
from hikyuu import (
QueryByIndex, constant, Indicator, CLOSE, EMA, MACD, VIGOR, SAFTYLOSS, CVAL, PRICELIST
)
from hikyuu import (Query, constant, Indicator, CLOSE, EMA, MACD, VIGOR, SAFTYLOSS, CVAL, PRICELIST)
from .drawplot import (
create_figure, show_gcf, ax_draw_macd2, adjust_axes_show, ax_set_locator_formatter
)
@ -99,7 +97,7 @@ def _draw_ema_pipe(axes, kdata, ema, n=22, w=0.10):
axes.fill_between(range(emas_len), fy1, fy2, alpha=0.2, color='y')
def draw(stock, query=QueryByIndex(-130), ma_n=22, ma_w='auto', vigor_n=13):
def draw(stock, query=Query(-130), ma_n=22, ma_w='auto', vigor_n=13):
"""绘制亚历山大.艾尔德交易系统图形"""
kdata = stock.getKData(query)
close = CLOSE(kdata)

View File

@ -234,7 +234,7 @@ def KData_getPos(kdata, datetime):
KData.__getitem__ = KData_getitem
KData.__iter__ = KData_iter
KData.getPos = KData_getPos
KData.get_pos = KData_getPos
# ------------------------------------------------------------------
# 封装增强其他C++ vector类型的遍历、打印
@ -282,6 +282,58 @@ TransList.__repr__ = lambda self: repr(list(self))
TimeLineList.__str__ = lambda self: str(list(self))
TimeLineList.__repr__ = lambda self: repr(list(self))
# ------------------------------------------------------------------
# 重定义Query
# ------------------------------------------------------------------
Query.INDEX = Query.QueryType.INDEX
Query.DATE = Query.QueryType.DATE
Query.DAY = "DAY"
Query.WEEK = "WEEK"
Query.MONTH = "MONTH"
Query.QUARTER = "QUARTER"
Query.HALFYEAR = "HALFYEAR"
Query.YEAR = "YEAR"
Query.MIN = "MIN"
Query.MIN5 = "MIN5"
Query.MIN15 = "MIN15"
Query.MIN30 = "MIN30"
Query.MIN60 = "MIN60"
Query.HOUR2 = "HOUR2"
Query.HOUR4 = "HOUR4"
Query.HOUR6 = "HOUR6"
Query.HOUR12 = "HOUR12"
Query.NO_RECOVER = Query.RecoverType.NO_RECOVER
Query.FORWARD = Query.RecoverType.FORWARD
Query.BACKWARD = Query.RecoverType.BACKWARD
Query.EQUAL_FORWARD = Query.RecoverType.EQUAL_FORWARD
Query.EQUAL_BACKWARD = Query.RecoverType.EQUAL_BACKWARD
old_Query_init = Query.__init__
def new_Query_init(self, start=0, end=None, ktype=Query.DAY, recover_type=Query.NO_RECOVER):
"""
[start, end) K线数据条件startend应同为 int Datetime
:param int|Datetime start:
:param int|Datetime end:
:param Query.KType ktype: K线数据类型线线
:param Query.RecoverType recover_type:
:return:
:rtype: KQuery
"""
if isinstance(start, int):
end_pos = constant.null_int64 if end is None else end
elif isinstance(start, Datetime):
end_pos = constant.null_datetime if end is None else end
else:
raise TypeError('Incorrect parameter type error!')
old_Query_init(self, start, end_pos, ktype, recover_type)
Query.__init__ = new_Query_init
# ------------------------------------------------------------------
# 增加转化为 np.array、pandas.DataFrame 的功能
# ------------------------------------------------------------------

View File

@ -43,39 +43,39 @@ void export_Datetime() {
.add_property("microsecond", &Datetime::microsecond, "微秒")
.add_property("number", &Datetime::number)
.def("isNull", &Datetime::isNull, "\n是否是Null值等于 Datetime() 直接创建的对象")
.def("is_null", &Datetime::isNull, "\n是否是Null值等于 Datetime() 直接创建的对象")
.def("dayOfWeek", &Datetime::dayOfWeek, "\n返回是一周中的第几天周日为0周一为1")
.def("dayOfYear", &Datetime::dayOfYear, "\n返回一年中的第几天1月1日为一年中的第1天")
.def("startOfDay", &Datetime::startOfDay, "\n返回当天 0点0分0秒")
.def("endOfDay", &Datetime::endOfDay, "\n返回当日 23点59分59秒")
.def("nextDay", &Datetime::nextDay, "\n返回下一自然日")
.def("nextWeek", &Datetime::nextWeek, "\n返回下周周一日期")
.def("nextMonth", &Datetime::nextMonth, "\n返回下月首日日期")
.def("nextQuarter", &Datetime::nextQuarter, "\n返回下一季度首日日期")
.def("nextHalfyear", &Datetime::nextHalfyear, "\n返回下一半年度首日日期")
.def("nextYear", &Datetime::nextYear, "\n返回下一年度首日日期")
.def("preDay", &Datetime::preDay, "\n返回前一自然日日期")
.def("preWeek", &Datetime::preWeek, "\n返回上周周一日期")
.def("preMonth", &Datetime::preMonth, "\n返回上月首日日期")
.def("preQuarter", &Datetime::preQuarter, "\n返回上一季度首日日期")
.def("preHalfyear", &Datetime::preHalfyear, "\n返回上一半年度首日日期")
.def("preYear", &Datetime::preYear, "\n返回上一年度首日日期")
.def("dateOfWeek", &Datetime::dateOfWeek,
.def("day__of_week", &Datetime::dayOfWeek, "\n返回是一周中的第几天周日为0周一为1")
.def("day_of_year", &Datetime::dayOfYear, "\n返回一年中的第几天1月1日为一年中的第1天")
.def("start_of_day", &Datetime::startOfDay, "\n返回当天 0点0分0秒")
.def("end__of_day", &Datetime::endOfDay, "\n返回当日 23点59分59秒")
.def("next_day", &Datetime::nextDay, "\n返回下一自然日")
.def("next_week", &Datetime::nextWeek, "\n返回下周周一日期")
.def("next_month", &Datetime::nextMonth, "\n返回下月首日日期")
.def("next_quarter", &Datetime::nextQuarter, "\n返回下一季度首日日期")
.def("next_halfyear", &Datetime::nextHalfyear, "\n返回下一半年度首日日期")
.def("next_year", &Datetime::nextYear, "\n返回下一年度首日日期")
.def("pre_day", &Datetime::preDay, "\n返回前一自然日日期")
.def("pre_week", &Datetime::preWeek, "\n返回上周周一日期")
.def("pre_month", &Datetime::preMonth, "\n返回上月首日日期")
.def("pre_quarter", &Datetime::preQuarter, "\n返回上一季度首日日期")
.def("pre_halfyear", &Datetime::preHalfyear, "\n返回上一半年度首日日期")
.def("pre_year", &Datetime::preYear, "\n返回上一年度首日日期")
.def("date_of_week", &Datetime::dateOfWeek,
R"(
06
:param int day: 066)")
.def("startOfWeek", &Datetime::startOfWeek, "\n返回周起始日期(周一)")
.def("endOfWeek", &Datetime::endOfWeek, "\n返回周结束日期(周日)")
.def("startOfMonth", &Datetime::startOfMonth, "\n返回月度起始日期")
.def("endOfMonth", &Datetime::endOfMonth, "\n返回月末最后一天日期")
.def("startOfQuarter", &Datetime::startOfQuarter, "\n返回季度起始日期")
.def("endOfQuarter", &Datetime::endOfQuarter, "\n返回季度结束日期")
.def("startOfHalfyear", &Datetime::startOfHalfyear, "\n返回半年度起始日期")
.def("endOfHalfyear", &Datetime::endOfHalfyear, "\n返回半年度结束日期")
.def("startOfYear", &Datetime::startOfYear, "\n返回年度起始日期")
.def("start_of_week", &Datetime::startOfWeek, "\n返回周起始日期(周一)")
.def("end_of_week", &Datetime::endOfWeek, "\n返回周结束日期(周日)")
.def("start_of_month", &Datetime::startOfMonth, "\n返回月度起始日期")
.def("end_of_month", &Datetime::endOfMonth, "\n返回月末最后一天日期")
.def("start_of_quarter", &Datetime::startOfQuarter, "\n返回季度起始日期")
.def("end_of_quarter", &Datetime::endOfQuarter, "\n返回季度结束日期")
.def("start_of_halfyear", &Datetime::startOfHalfyear, "\n返回半年度起始日期")
.def("end_of_halfyear", &Datetime::endOfHalfyear, "\n返回半年度结束日期")
.def("start_of_year", &Datetime::startOfYear, "\n返回年度起始日期")
.def("endOfYear", &Datetime::endOfYear, "\n返回年度结束日期")
.def("min", &Datetime::min, "\n获取支持的最小日期, Datetime(1400, 1, 1)")
.staticmethod("min")
@ -102,5 +102,5 @@ void export_Datetime() {
#endif
;
def("getDateRange", getDateRange, (arg("start"), arg("end")));
def("get_date_range", getDateRange, (arg("start"), arg("end")));
}

View File

@ -21,13 +21,14 @@ void export_KData() {
.def("__str__", &KData::toString)
.def("__repr__", &KData::toString)
.add_property("startPos", &KData::startPos,
.add_property("start_pos", &KData::startPos,
"获取在原始K线记录中对应的起始位置如果KData为空返回0")
.add_property(
"endPos", &KData::endPos,
"end_pos", &KData::endPos,
"获取在原始K线记录中对应范围的下一条记录的位置如果为空返回0,其他等于lastPos + 1")
.add_property("lastPos", &KData::lastPos,
.add_property("last_pos", &KData::lastPos,
"获取在原始K线记录中对应的最后一条记录的位置如果为空返回0,其他等于endPos - 1")
.add_property("open", &KData::open, "返回包含开盘价的 Indicator 实例,相当于 OPEN(k)")
.add_property("close", &KData::close, "返回包含收盘价的 Indicator 实例,相当于 CLOSE(k)")
.add_property("high", &KData::high, "返回包含最高价的 Indicator 实例,相当于 HIGH(k)")
@ -35,7 +36,7 @@ void export_KData() {
.add_property("amo", &KData::amo, "返回包含成交金额的 Indicator 实例,相当于 AMO(k)")
.add_property("vol", &KData::vol, "返回包含成交量的 Indicator 实例,相当于 VOL(k)")
.def("getDatetimeList", &KData::getDatetimeList, R"(getDatetimeList(self)
.def("get_date_list", &KData::getDatetimeList, R"(get_date_list(self)
@ -48,7 +49,7 @@ void export_KData() {
:param int pos:
:rtype: KRecord)")
.def("getByDate", &KData::getKRecordByDate, R"(getByDate(self, datetime)
.def("get_by_date", &KData::getKRecordByDate, R"(get_by_date(self, datetime)
K线记录
@ -63,13 +64,13 @@ void export_KData() {
:rtype: bool)")
.def("getQuery", &KData::getQuery, R"(getQuery(self)
.def("get_query", &KData::getQuery, R"(get_query(self)
:rtype: KQuery)")
.def("getStock", &KData::getStock, R"(getStock(self)
.def("get_stock", &KData::getStock, R"(get_stock(self)
Stock

View File

@ -12,38 +12,27 @@
using namespace boost::python;
using namespace hku;
// BOOST_PYTHON_FUNCTION_OVERLOADS(KQueryByDate_overload, KQueryByDate, 0, 4);
BOOST_PYTHON_FUNCTION_OVERLOADS(KQueryByIndex_overload, KQueryByIndex, 0, 4);
void export_KQuery() {
// def("QueryByDate", KQueryByDate, KQueryByDate_overload());
def("QueryByIndex", KQueryByIndex, KQueryByIndex_overload());
scope in_Query =
class_<KQuery>("Query", init<>())
class_<KQuery>("Query", "K线数据查询条件", init<>())
.def(init<int64, optional<int64, KQuery::KType, KQuery::RecoverType> >())
.def(init<Datetime, optional<Datetime, KQuery::KType, KQuery::RecoverType> >())
.def(self_ns::str(self))
.add_property("start", &KQuery::start)
.add_property("end", &KQuery::end)
.add_property("startDatetime", &KQuery::startDatetime)
.add_property("endDatetime", &KQuery::endDatetime)
.add_property("queryType", &KQuery::queryType)
.add_property("kType", &KQuery::kType)
.add_property("recoverType", &KQuery::recoverType)
.def("getQueryTypeName", &KQuery::getQueryTypeName)
.staticmethod("getQueryTypeName")
.def("getKTypeName", &KQuery::getKTypeName)
.staticmethod("getKTypeName")
.def("getRecoverTypeName", &KQuery::getRecoverTypeName)
.staticmethod("getRecoverTypeName")
.def("getQueryTypeEnum", &KQuery::getQueryTypeEnum)
.staticmethod("getQueryTypeEnum")
.def("getKTypeEnum", &KQuery::getKTypeEnum)
.staticmethod("getKTypeEnum")
.def("getRecoverTypeEnum", &KQuery::getRecoverTypeEnum)
.staticmethod("getRecoverTypeEnum")
.def(self_ns::repr(self))
.add_property("start", &KQuery::start,
"起始索引,当按日期查询方式创建时无效,为 constant.null_int64")
.add_property("end", &KQuery::end,
"结束索引,当按日期查询方式创建时无效,为 constant.null_int64")
.add_property("start_date", &KQuery::startDatetime,
"起始日期,当按索引查询方式创建时无效,为 constant.null_datetime")
.add_property("end_date", &KQuery::endDatetime,
"结束日期,当按索引查询方式创建时无效,为 constant.null_datetime")
.add_property("query_type", &KQuery::queryType, "查询方式 Query.QueryType")
.add_property("ktype", &KQuery::kType, "查询的K线类型 Query.KType")
.add_property("recover_type", &KQuery::recoverType, "查询的复权类型 Query.RecoverType")
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<KQuery>())
#endif

View File

@ -13,17 +13,14 @@ using namespace hku;
void export_log() {
enum_<LOG_LEVEL>("LOG_LEVEL")
.value("DEBUG", LOG_LEVEL::DEBUG)
.value("TRACE", LOG_LEVEL::TRACE)
.value("INFO", LOG_LEVEL::INFO)
.value("WARN", LOG_LEVEL::WARN)
.value("ERROR", LOG_LEVEL::ERROR)
.value("FATAL", LOG_LEVEL::FATAL)
.value("OFF", LOG_LEVEL::OFF)
;
.value("DEBUG", LOG_LEVEL::DEBUG)
.value("TRACE", LOG_LEVEL::TRACE)
.value("INFO", LOG_LEVEL::INFO)
.value("WARN", LOG_LEVEL::WARN)
.value("ERROR", LOG_LEVEL::ERROR)
.value("FATAL", LOG_LEVEL::FATAL)
.value("OFF", LOG_LEVEL::OFF);
def("get_log_level", get_log_level);
def("set_log_level", set_log_level);
def("get_log_level", get_log_level, "获取当前日志级别");
def("set_log_level", set_log_level, "设置当前日志级别");
}

View File

@ -13,19 +13,32 @@ using namespace boost::python;
using namespace hku;
void export_MarketInfo() {
class_<MarketInfo>("MarketInfo", init<>())
.def(init<const string&, const string&, const string&, const string&, const Datetime&>())
//.def(self_ns::str(self))
.def("__str__", &MarketInfo::toString)
.add_property("market", make_function(&MarketInfo::market, return_value_policy<copy_const_reference>()))
.add_property("name", make_function(&MarketInfo::name, return_value_policy<copy_const_reference>()))
.add_property("description", make_function(&MarketInfo::description, return_value_policy<copy_const_reference>()))
.add_property("code", make_function(&MarketInfo::code, return_value_policy<copy_const_reference>()))
.add_property("lastDate", &MarketInfo::lastDate)
class_<MarketInfo>("MarketInfo", "市场信息记录", init<>())
.def(init<const string&, const string&, const string&, const string&, const Datetime&>())
//.def(self_ns::str(self))
.def("__str__", &MarketInfo::toString)
.add_property("market",
make_function(&MarketInfo::market, return_value_policy<copy_const_reference>()),
"市场标识沪市“SH”, 深市“SZ”")
.add_property("name",
make_function(&MarketInfo::name, return_value_policy<copy_const_reference>()),
"市场全称")
.add_property(
"description",
make_function(&MarketInfo::description, return_value_policy<copy_const_reference>()),
"描述说明")
.add_property("code",
make_function(&MarketInfo::code, return_value_policy<copy_const_reference>()),
"该市场对应的主要指数代码,用于获取交易日历")
.add_property("last_date", &MarketInfo::lastDate, "该市场K线数据最后交易日期")
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<MarketInfo>())
.def_pickle(normal_pickle_suite<MarketInfo>())
#endif
;
;
}

View File

@ -153,19 +153,4 @@ BOOST_PYTHON_MODULE(core) {
:param Query query:
:return: K线数据
:rtype: KData)");
py::def(
"QueryByDate", KQueryByDate,
(py::arg("start") = Datetime::min(), py::arg("end") = Datetime(),
py::arg("ktype") = KQuery::DAY, py::arg("recover_type") = KQuery::NO_RECOVER),
R"(QueryByDate([start=Datetime.min(), end=Datetime(), ktype=Query.DAY, recover_type=Query.NO_RECOVER])
[start, end) K线数据条件
:param Datetime start:
:param Datetime end:
:param Query.KType ktype: K线数据类型线线
:param Query.RecoverType recover_type:
:return:
:rtype: KQuery)");
}