Commit b7a42af8 authored by fasiondog's avatar fasiondog
Browse files

pybind continue

parent c8495478
Showing with 553 additions and 123 deletions
+553 -123
......@@ -49,6 +49,8 @@ SOFTWARE.
"""
import os
import configparser
from datetime import date, datetime, timedelta
from .cpp.core import *
from .pyindicator import *
......@@ -73,13 +75,57 @@ KData.__iter__ = KData_iter
Indicator.__iter__ = indicator_iter
# ------------------------------------------------------------------
# 数据初始化
# 读取配置信息,并初始化
# ------------------------------------------------------------------
#config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini"
config_file = "./test_data/hikyuu_win.ini"
hikyuu_init(config_file)
#config_file = "./test_data/hikyuu_win.ini"
#hikyuu_init(config_file)
#sm = StockManager.instance()
config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini"
if not os.path.exists(config_file):
# 检查老版本配置是否存在,如果存在可继续使用,否则异常终止
data_config_file = os.path.expanduser('~') + "/.hikyuu/data_dir.ini"
data_config = configparser.ConfigParser()
data_config.read(data_config_file)
data_dir = data_config['data_dir']['data_dir']
if sys.platform == 'win32':
config_file = data_dir + "\\hikyuu_win.ini"
else:
config_file = data_dir + "/hikyuu_linux.ini"
if not os.path.exists(config_file):
raise ("未找到配置文件,请先使用数据导入工具导入数据(将自动生成配置文件)!!!")
ini = configparser.ConfigParser()
ini.read(config_file)
hku_param = Parameter()
hku_param.set("tmpdir", ini.get('hikyuu', 'tmpdir'))
if ini.has_option('hikyuu', 'logger'):
hku_param.set("logger", ini['hikyuu']['logger'])
base_param = Parameter()
base_info_config = ini.options('baseinfo')
for p in base_info_config:
base_param.set(p, ini.get('baseinfo', p))
block_param = Parameter()
block_config = ini.options('block')
for p in block_config:
block_param.set(p, ini.get('block', p))
preload_param = Parameter()
preload_config = ini.options('preload')
for p in preload_config:
# 注意:proload参数是布尔类型
preload_param.set(p, ini.getboolean('preload', p))
kdata_param = Parameter()
kdata_config = ini.options('kdata')
for p in kdata_config:
kdata_param.set(p, ini.get('kdata', p))
set_log_level(LOG_LEVEL.TRACE)
sm = StockManager.instance()
sm.init(base_param, block_param, kdata_param, preload_param, hku_param)
set_log_level(LOG_LEVEL.WARN)
# ------------------------------------------------------------------
# 引入blocka、blocksh、blocksz、blockg全局变量,便于交互式环境下使用
......
__version__ = "0.0.1"
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
import tables as tb
dir = "c:/stock/"
tb.copy_file(dir + "sh_day.h5", dir + "sh_day_new.h5")
tb.copy_file(dir + "sz_day.h5", dir + "sz_day_new.h5")
tb.copy_file(dir + "sh_5min.h5", dir + "sh_5min_new.h5")
tb.copy_file(dir + "sz_5min.h5", dir + "sz_5min_new.h5")
#tb.copy_file(dir + "sh_1min.h5", dir + "sh_1min_new.h5")
#tb.copy_file(dir + "sz_1min.h5", dir + "sz_1min_new.h5")
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
import tables as tbl
def delete_h5_index(filename):
"""清除h5数据文件中的周线、月线、季线、半年线、年线数据索引
"""
print("begin clear week, month, quarter, halfyear, year index from ", filename)
with tbl.open_file(filename, "a") as h5file:
try:
h5file.remove_node("/week", recursive=True)
except:
print("remove week failed!")
else:
print("success remove week")
try:
h5file.remove_node("/month", recursive=True)
except:
print("remove month failed!")
else:
print("success remove month")
try:
h5file.remove_node("/quarter", recursive=True)
except:
print("remove quarter failed!")
else:
print("success remove quarter")
try:
h5file.remove_node("/halfyear", recursive=True)
except:
print("remove halfyear failed!")
else:
print("success remove halfyear")
try:
h5file.remove_node("/year", recursive=True)
except:
print("remove year failed!")
else:
print("success remove year")
if __name__ == "__main__":
delete_h5_index("C:\\stock\\sh_day.h5")
delete_h5_index("C:\\stock\\sz_day.h5")
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
import tables
import datetime
import sys
import math
def ProgressBar(cur, total):
percent = '{:.2%}'.format(cur / total)
sys.stdout.write('\r')
sys.stdout.write("[%-50s] %s" % ('=' * int(math.floor(cur * 50 / total)),percent))
sys.stdout.flush()
class FiveMinDataRecordH5File(tables.IsDescription):
datetime = tables.UInt64Col() #IGNORE:E1101
openPrice = tables.UInt32Col() #IGNORE:E1101
highPrice = tables.UInt32Col() #IGNORE:E1101
lowPrice = tables.UInt32Col() #IGNORE:E1101
closePrice = tables.UInt32Col() #IGNORE:E1101
transAmount = tables.UInt64Col() #IGNORE:E1101
transCount = tables.UInt64Col() #IGNORE:E1101
def fenge(src_file_name, dest_file_name, start_date, end_date):
"""
将原始数据按日期范围分隔,方便同步备份
"""
print("正在进行,请稍候.....")
src_hdf5 = tables.openFile(src_file_name, mode='r', filters=tables.Filters(complevel=9,complib='zlib', shuffle=True))
dest_hdf5 = tables.openFile(dest_file_name, mode = "w", filters=tables.Filters(complevel=9,complib='zlib', shuffle=True))
dest_group = dest_hdf5.create_group("/", "data")
start = start_date
end = end_date
all_table = [x for x in src_hdf5.walkNodes("/data")]
total = len(all_table)
for i in range(1,total):
ProgressBar(i+1, total)
src_table = all_table[i]
#print(src_table.name)
dest_table = dest_hdf5.createTable(dest_group, src_table.name, FiveMinDataRecordH5File, src_table.name)
dest_row = dest_table.row
for x in src_table:
if x['datetime'] >= end:
break
if start <= x['datetime'] \
and x['lowPrice'] <= x['openPrice'] <=x['highPrice'] \
and x['lowPrice'] <= x['closePrice'] <= x['highPrice']:
dest_row['datetime'] = x['datetime']
dest_row['openPrice'] = x['openPrice']
dest_row['highPrice'] = x['highPrice']
dest_row['lowPrice'] = x['lowPrice']
dest_row['closePrice'] = x['closePrice']
dest_row['transAmount'] = x['transAmount']
dest_row['transCount'] = x['transCount']
dest_row.append()
dest_table.flush()
src_hdf5.close()
dest_hdf5.close()
def fenge2(src_file_name, dest_dir_name):
"""
将每个stock的数据拆分成独立的文件
"""
src_hdf5 = tables.openFile(src_file_name, mode='r', filters=tables.Filters(complevel=9,complib='zlib', shuffle=True))
all_table = [x for x in src_hdf5.walkNodes("/")]
for i in range(1,len(all_table)):
src_table = all_table[i]
#print src_table.name
dest_table = dest_hdf5.createTable("/", "data", FiveMinDataRecordH5File, src_table.name)
dest_row = dest_table.row
pre_date = 0
for x in src_table:
if x['datetime'] <= pre_date:
print(src_table, pre_date, x['datetime'])
continue
try:
tmp_date = x['datetime']
year = tmp_date / 100000000
month = (tmp_date - year * 100000000) / 1000000
day = (tmp_date - tmp_date / 1000000 * 1000000) / 10000;
ttdate = datetime.date(year, month, day)
except ValueError:
print(src_table, tmp_date)
else:
if x['lowPrice'] <= x['openPrice'] <=x['highPrice'] \
and x['lowPrice'] <= x['closePrice'] <= x['highPrice']:
dest_row['datetime'] = x['datetime']
dest_row['openPrice'] = x['openPrice']
dest_row['highPrice'] = x['highPrice']
dest_row['lowPrice'] = x['lowPrice']
dest_row['closePrice'] = x['closePrice']
dest_row['transAmount'] = x['transAmount']
dest_row['transCount'] = x['transCount']
dest_row.append()
else:
print(src_table, x['datetime'], "warning 2")
dest_table.flush()
dest_hdf5.close()
src_hdf5.close()
if __name__ == "__main__":
import time
starttime = time.time()
#src_file_name = '/home/fasiondog/workspace/hikyuu/test/data/sz_day.h5'
#dest_dir_name = "/home/fasiondog/workspace/hikyuu/test/data/sz/day/"
#fenge2(src_file_name, dest_dir_name)
src_dir = 'c:\\stock'
dst_dir = u'D:\\快盘\\80.stock\\stock'
data_type = '5min' #only '5min' or '1min'
market = 'sz'
year = 2016
src_file_name = src_dir + '\\' + market + '_' + data_type + '.h5' #d:\\stock\\sh_5min.h5'
dest_file_name = dst_dir + "\\" + market + "\\" + data_type + "\\" + str(year) + ".h5"
#dest_file_name = u'D:\\快盘\\80.stock\\stock\\sh\\5min\\2013.h5'
start_date = year * 100000000 + 1010000 #201301010000
end_date = start_date + 100000000 #201401010000
fenge(src_file_name, dest_file_name, start_date, end_date)
endtime = time.time()
print("\n")
print("%.2fs" % (endtime-starttime))
print("%.2fm" % ((endtime-starttime)/60))
#!/usr/bin/python
# cp936
import sqlite3
import tables as tbl
dirname = 'c:\stock'
connect = sqlite3.connect(dirname + '\stock.db')
cur = connect.cursor()
a = cur.execute("select market.market, stock.code from stock join market on stock.marketid = market.marketid")
stk_list = [ s[0]+s[1] for s in a]
def clear_empty_table(h5file, group_name):
group = h5file.get_node(group_name)
node_list = []
for node in group:
if 0 == node.nrows:
node_list.append(node.name)
#print(node.name, " nrows = 0")
elif node.name not in stk_list:
node_list.append(node.name)
#print(node.name, " is not in stk_list")
else:
pass
for node in node_list:
try:
h5file.remove_node(group, node)
except:
pass
print("共清理:%i" % len(node_list))
#--------------------------------------------------
# 清理深证日线数据
#--------------------------------------------------
srcfilename = dirname + '\sz_day.h5'
print('--------------------------------------------------')
print(srcfilename)
h5file = tbl.open_file(srcfilename, "a")
print("清理日线数据")
clear_empty_table(h5file, '/data')
print("\n清理周线数据")
clear_empty_table(h5file, '/week')
print("\n清理月线数据")
clear_empty_table(h5file, '/month')
print("\n清理季线数据")
clear_empty_table(h5file, '/quarter')
print("\n清理半年线数据")
clear_empty_table(h5file, '/halfyear')
print("\n清理年线数据")
clear_empty_table(h5file, '/year')
h5file.close()
#--------------------------------------------------
# 清理上证日线数据
#--------------------------------------------------
srcfilename = dirname + '\sh_day.h5'
print('--------------------------------------------------')
print(srcfilename)
h5file = tbl.open_file(srcfilename, "a")
print("清理日线数据")
clear_empty_table(h5file, '/data')
print("\n清理周线数据")
clear_empty_table(h5file, '/week')
print("\n清理月线数据")
clear_empty_table(h5file, '/month')
print("\n清理季线数据")
clear_empty_table(h5file, '/quarter')
print("\n清理半年线数据")
clear_empty_table(h5file, '/halfyear')
print("\n清理年线数据")
clear_empty_table(h5file, '/year')
h5file.close()
#--------------------------------------------------
# 清理上证5分钟线数据
#--------------------------------------------------
srcfilename = dirname + '\sh_5min.h5'
print('--------------------------------------------------')
print(srcfilename)
h5file = tbl.open_file(srcfilename, "a")
print("清理5分钟线数据")
clear_empty_table(h5file, '/data')
#print("\n清理15分钟线数据")
#clear_empty_table(h5file, '/min15')
#print("\n清理30分钟线数据")
#clear_empty_table(h5file, '/min30')
#print("\n清理60分钟线数据")
#clear_empty_table(h5file, '/min60')
h5file.close()
#--------------------------------------------------
# 清理上证5分钟线数据
#--------------------------------------------------
srcfilename = dirname + '\sz_5min.h5'
print('--------------------------------------------------')
print(srcfilename)
h5file = tbl.open_file(srcfilename, "a")
print("清理5分钟线数据")
clear_empty_table(h5file, '/data')
#print("\n清理15分钟线数据")
#clear_empty_table(h5file, '/min15')
#print("\n清理30分钟线数据")
#clear_empty_table(h5file, '/min30')
#print("\n清理60分钟线数据")
#clear_empty_table(h5file, '/min60')
h5file.close()
#--------------------------------------------------
# 清理上证1分钟线数据
#--------------------------------------------------
srcfilename = dirname + '\sh_1min.h5'
print('--------------------------------------------------')
print(srcfilename)
h5file = tbl.open_file(srcfilename, "a")
print("清理1分钟线数据")
clear_empty_table(h5file, '/data')
h5file.close()
#--------------------------------------------------
# 清理上证5分钟线数据
#--------------------------------------------------
srcfilename = dirname + '\sz_1min.h5'
print('--------------------------------------------------')
print(srcfilename)
h5file = tbl.open_file(srcfilename, "a")
print("清理1分钟线数据")
clear_empty_table(h5file, '/data')
h5file.close()
\ No newline at end of file
......@@ -6,6 +6,7 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "convert_Datetime.h"
#include "pickle_support.h"
#include <hikyuu/serialization/KData_serialization.h>
......@@ -83,10 +84,7 @@ void export_KData(py::module& m) {
.def_property_readonly("amo", &KData::amo, "成交金额指标")
.def_property_readonly("vol", &KData::vol, "成交量指标")
.def(
"getDatetimeList",
[](const KData& k) { return vector_to_python_list(k.getDatetimeList()); },
"返回交易日期列表")
.def("getDatetimeList", &KData::getDatetimeList, "返回交易日期列表")
.def("get", &KData::getKRecord, "获取指定位置的KRecord,未作越界检查")
......@@ -144,7 +142,7 @@ void export_KData(py::module& m) {
start += step;
}
return vector_to_python_list(result);
return result;
})
DEF_PICKLE(KData);
......
......@@ -53,22 +53,13 @@ void export_Stock(py::module& m) {
.def("getKData", &Stock::getKData, "根据查询条件获取K线数据")
.def(
"getTimeLineList",
[](const Stock& stk, const KQuery& query) {
// return vector_to_python_list(stk.getTimeLineList(query));
return stk.getTimeLineList(query);
},
R"(获取分时线
.def("getTimeLineList", &Stock::getTimeLineList,
R"(获取分时线
:param Query query: 查询条件(查询条件中的K线类型、复权类型参数此时无用))")
.def(
"getTransList",
[](const Stock& stk, const KQuery& q) {
return vector_to_python_list(stk.getTransList(q));
},
R"(获取历史分笔数据
.def("getTransList", &Stock::getTransList,
R"(获取历史分笔数据
:param Query query: 查询条件(查询条件中的K线类型、复权类型参数此时无用))")
......@@ -100,46 +91,32 @@ void export_Stock(py::module& m) {
:param datetime date: 指定日期时刻
:param Query.KType ktype: K线数据类别)")
.def(
"getKRecordList",
[](const Stock& stk, size_t start, size_t end, KQuery::KType ktype) {
return vector_to_python_list(stk.getKRecordList(start, end, ktype));
},
R"(获取K线记录 [start, end),一般不直接使用,用getKData替代
.def("getKRecordList", &Stock::getKRecordList,
R"(获取K线记录 [start, end),一般不直接使用,用getKData替代
:param int start: 起始位置
:param int end: 结束位置
:param Query.KType ktype: K线类别
:return: K线记录列表)")
.def(
"getDatetimeList",
[](const Stock& stk, size_t start, size_t end, KQuery::KType ktype) {
return vector_to_python_list<Datetime>(stk.getDatetimeList(start, end, ktype));
},
R"(获取日期时间列表 [start, end)
.def("getDatetimeList",
py::overload_cast<size_t, size_t, KQuery::KType>(&Stock::getDatetimeList, py::const_),
py::arg("start"), py::arg("end"), py::arg("ktype"),
R"(获取日期时间列表 [start, end)
:param int start: 起始位置
:param ind end: 结束位置
:param Query.KType ktype: K线类型)")
.def(
"getDatetimeList",
[](const Stock& stk, const KQuery& q) {
return vector_to_python_list<Datetime>(stk.getDatetimeList(q));
},
R"(获取日期时间列表
.def("getDatetimeList", py::overload_cast<const KQuery&>(&Stock::getDatetimeList, py::const_),
R"(获取日期时间列表
:param Query query: 查询条件)")
.def("getFinanceInfo", &Stock::getFinanceInfo, "获取当前财务信息")
.def(
"getHistoryFinanceInfo",
[](const Stock& stock, const Datetime& date) {
return vector_to_python_list(stock.getHistoryFinanceInfo(date));
},
R"(获取历史财务信息, 字段含义参见:https://hikyuu.org/finance_fields.html
.def("getHistoryFinanceInfo", &Stock::getHistoryFinanceInfo,
R"(获取历史财务信息, 字段含义参见:https://hikyuu.org/finance_fields.html
:param Datetime date: 指定日期必须是0331、0630、0930、1231,如 Datetime(201109300000))")
......@@ -148,15 +125,11 @@ void export_Stock(py::module& m) {
:param KRecord krecord: 新增的实时K线记录)")
.def(
"getWeight", [](const Stock& stk) { return vector_to_python_list(stk.getWeight()); },
"获取全部权息信息")
.def("getWeight", py::overload_cast<void>(&Stock::getWeight, py::const_), "获取全部权息信息")
.def(
"getWeight",
[](const Stock& stk, const Datetime& start, const Datetime& end) {
return vector_to_python_list(stk.getWeight(start, end));
},
py::overload_cast<const Datetime&, const Datetime&>(&Stock::getWeight, py::const_),
py::arg("start"), py::arg("end") = py::none(),
R"(获取指定时间段[start,end)内的权息信息。未指定起始、结束时刻时,获取全部权息记录。
......
......@@ -6,6 +6,7 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <hikyuu/StockManager.h>
#include "convert_any.h"
#include "pybind_utils.h"
......@@ -28,10 +29,7 @@ void export_StockManager(py::module& m) {
.def("getPreloadParameter", &StockManager::getPreloadParameter)
.def("getHikyuuParameter", &StockManager::getHikyuuParameter)
.def(
"getAllMarket",
[](const StockManager& sm) { return vector_to_python_list<string>(sm.getAllMarket()); },
"获取市场简称列表")
.def("getAllMarket", &StockManager::getAllMarket, "获取市场简称列表")
.def("getMarketInfo", &StockManager::getMarketInfo, "获取相应的市场信息")
......@@ -50,19 +48,13 @@ void export_StockManager(py::module& m) {
:param str name: 板块名称
:return: 板块,如找不到返回一个空 Block )")
.def(
"getBlockList",
[](StockManager& sm, const string& category) {
return vector_to_python_list<Block>(sm.getBlockList(category));
},
R"(获取指定分类的板块列表
.def("getBlockList", py::overload_cast<const string&>(&StockManager::getBlockList),
R"(获取指定分类的板块列表
:param str category: 板块分类)")
.def(
"getBlockList",
[](StockManager& sm) { return vector_to_python_list<Block>(sm.getBlockList()); },
"获取全部的板块列表")
.def("getBlockList", py::overload_cast<void>(&StockManager::getBlockList),
"获取全部的板块列表")
.def("getTradingCalendar", &StockManager::getTradingCalendar, py::arg("query"),
py::arg("market") = "SH", R"(获取指定市场的交易日日历
......
......@@ -31,7 +31,7 @@ void export_BlockInfoDriver(py::module& m) {
.def("haveParam", &BlockInfoDriver::haveParam, "指定参数是否存在")
.def("_init", &BlockInfoDriver::_init, "【子类接口(必须)】驱动初始化")
.def("getBlock", &BlockInfoDriver::getBlock,
.def("getBlock", &BlockInfoDriver::getBlock, py::arg("category"), py::arg("name"),
R"(【子类接口(必须)】获取指定板块
:param str category: 指定的板块分类
......
......@@ -36,7 +36,7 @@ public:
BlockList getBlockList() {
auto self = py::cast(this);
auto py_list = self.attr("_getBlockList")(py::none);
auto py_list = self.attr("_getBlockList")(py::none());
return python_list_to_vector<Block>(py_list);
}
};
\ No newline at end of file
......@@ -18,14 +18,28 @@ namespace py = pybind11;
void export_DataDriverFactory(py::module& m) {
py::class_<DataDriverFactory>(m, "DataDriverFactory", "数据驱动工厂类")
.def_static("getBaseInfoDriver", &DataDriverFactory::getBaseInfoDriver)
.def_static("regBaseInfoDriver", &DataDriverFactory::regBaseInfoDriver)
.def_static("removeBaseInfoDriver", &DataDriverFactory::removeBaseInfoDriver)
.def_static("getKDataDriver", &DataDriverFactory::getKDataDriver)
.def_static("removeKDataDriver", &DataDriverFactory::removeKDataDriver)
.def_static("getBlockDriver", &DataDriverFactory::getBlockDriver)
.def_static("regBlockDriver", &DataDriverFactory::regBlockDriver)
.def_static("removeBlockDriver", &DataDriverFactory::removeBlockDriver)
.def_static("regBaseInfoDriver",
[](py::object pydriver) {
auto keep_python_state_alive = std::make_shared<py::object>(pydriver);
auto ptr = pydriver.cast<PyBaseInfoDriver*>();
auto driver = BaseInfoDriverPtr(keep_python_state_alive, ptr);
DataDriverFactory::regBaseInfoDriver(driver);
})
.def_static("regBlockDriver",
[](py::object pydriver) {
auto keep_python_state_alive = std::make_shared<py::object>(pydriver);
auto ptr = pydriver.cast<PyBlockInfoDriver*>();
auto driver = BlockInfoDriverPtr(keep_python_state_alive, ptr);
DataDriverFactory::regBlockDriver(driver);
})
.def_static("regKDataDriver",
[](py::object pydriver) {
auto keep_python_state_alive = std::make_shared<py::object>(pydriver);
......
......@@ -8,23 +8,47 @@
#include "_KDataDriver.h"
void export_KDataDriver(py::module& m) {
py::class_<KDataDriver, KDataDriverPtr, PyKDataDriver>(m, "KDataDriver")
py::class_<KDataDriver, KDataDriverPtr, PyKDataDriver>(m, "KDataDriver",
R"(K线数据驱动基类
子类接口:
- _init(self)
- getCount(self, market, code, ktype)
- getKRecord(self, market, code, pos, ktype)
- _loadKDate(self, market, code, ktype, startix, endix)
- _getIndexRangeByDate(self, market, code, query)
- _getTimeLineList(self, market, code, query)
_ _getTransList(self, market, code, query)
)")
.def(py::init<>())
.def(py::init<const string&>())
.def(py::init<const string&>(), R"(构造函数)
:param str name: 驱动名称)")
.def_property_readonly("name", &KDataDriver::name)
.def_property_readonly("name", &KDataDriver::name, py::return_value_policy::copy, "驱动名称")
.def("__str__", to_py_str<KDataDriver>)
.def("__repr__", to_py_str<KDataDriver>)
.def("getParam", &KDataDriver::getParam<boost::any>)
.def("getParam", &KDataDriver::getParam<boost::any>, "获取指定参数的值")
.def("setParam", &KDataDriver::setParam<boost::any>, "设置参数")
.def("haveParam", &KDataDriver::haveParam, "指定参数是否存在")
.def("_init", &KDataDriver::_init)
.def("loadKData", &KDataDriver::loadKData)
.def("getCount", &KDataDriver::getCount)
.def("getKRecord", &KDataDriver::getKRecord)
//.def("_getIndexRangeByDate", &KDataDriverWrap::_getIndexRangeByDate,
// &KDataDriverWrap::default_getIndexRangeByDate)
.def("_init", &KDataDriver::_init, "【子类接口】初始化驱动")
.def("getCount", &KDataDriver::getCount, py::arg("market"), py::arg("code"), py::arg("ktype"),
R"(【子类接口】获取K线记录数量
:param str markt: 市场简称
:param str code: 证券代码
:param Query.KType ktype: K线类型
:rtype int)")
;
.def("getKRecord", &KDataDriver::getKRecord, py::arg("markt"), py::arg("code"),
py::arg("pos"), py::arg("ktype"), R"(【子类接口】获取指定的K线记录
:param str market: 市场简称
:param str code: 证券代码
:param int pos: K线记录索引位置
:param Query.KType ktype: K线类型)");
}
\ No newline at end of file
......@@ -26,8 +26,6 @@ public:
void loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix,
size_t end_ix, KRecordListPtr out_buffer) {
// PYBIND11_OVERLOAD(void, KDataDriver, loadKData, market, code, kType, start_ix, end_ix,
// out_buffer);
auto self = py::cast(this);
py::list kr_list = self.attr("_loadKData")(market, code, kType, start_ix, end_ix);
auto total = len(kr_list);
......
......@@ -8,6 +8,7 @@
#include <sstream>
#include <hikyuu/indicator/Indicator.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include "../convert_Datetime.h"
#include "../convert_any.h"
......@@ -170,7 +171,7 @@ void export_Indicator(py::module& m) {
start += step;
}
return vector_to_python_list(result);
return result;
})
.def("items",
......
......@@ -6,6 +6,7 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <hikyuu/hikyuu.h>
#include "pybind_utils.h"
#include "convert_Datetime.h"
......@@ -43,22 +44,11 @@ void export_trade_sys(py::module& m);
void export_data_driver(py::module& m);
PYBIND11_MODULE(core, m) {
m.def(
"get_date_range",
[](Datetime& start, Datetime& end) {
return vector_to_python_list<Datetime>(getDateRange(start, end));
},
py::arg("start"), py::arg("end"),
"Return a list of calendar dates for the specified range (start, end].");
m.def(
"print_datetime", [](const Datetime& d) { fmt::print("{}\n", d); },
"test convert Python datetime <--> Datetime");
void export_trade_instance(py::module& m);
m.def(
"print_timedelta", [](const TimeDelta& d) { fmt::print("{}\n", d); },
"test convert Python timedelta <--> TimeDelta");
PYBIND11_MODULE(core, m) {
m.def("get_date_range", getDateRange, py::arg("start"), py::arg("end"),
"Return a list of calendar dates for the specified range (start, end].");
export_Constant(m);
export_utils(m);
......@@ -88,4 +78,6 @@ PYBIND11_MODULE(core, m) {
export_trade_sys(m);
export_data_driver(m);
export_trade_instance(m);
}
\ No newline at end of file
/*
* Copyright (c) hikyuu.org
*
* Created on: 2020-6-18
* Author: fasiondog
*/
#include <hikyuu/indicator/build_in.h>
#include <pybind11/pybind11.h>
#include <hikyuu/trade_instance/ama_sys/AmaInstance.h>
using namespace hku;
namespace py = pybind11;
void export_AmaInstance(py::module& m) {
m.def("AmaSpecial", AmaSpecial);
}
/*
* Copyright (c) hikyuu.org
*
* Created on: 2020-6-18
* Author: fasiondog
*/
#include <hikyuu/indicator/build_in.h>
#include <pybind11/pybind11.h>
namespace py = pybind11;
void export_AmaInstance(py::module& m);
void export_trade_instance(py::module& m) {
export_AmaInstance(m);
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <hikyuu/trade_manage/TradeManager.h>
#include "../convert_Datetime.h"
#include "../pybind_utils.h"
......@@ -111,27 +112,20 @@ void export_TradeManager(py::module& m) {
:rtype: int)")
//.def("getShortHoldNumber", &TradeManager::getShortHoldNumber)
.def(
"getTradeList",
[](const TradeManager& tm, const Datetime& start, const Datetime& end) {
return vector_to_python_list(tm.getTradeList(start, end));
},
py::arg("start") = Datetime::min(), py::arg("end") = Datetime(),
R"(获取交易记录,未指定参数时,获取全部交易记录
.def("getTradeList",
py::overload_cast<const Datetime&, const Datetime&>(&TradeManager::getTradeList,
py::const_),
py::arg("start") = Datetime::min(), py::arg("end") = py::none(),
R"(获取交易记录,未指定参数时,获取全部交易记录
:param datetime start: 起始日期
:param datetime end: 结束日期
:rtype: list)")
.def(
"getPositionList",
[](const TradeManager& tm) { return vector_to_python_list(tm.getPositionList()); },
"获取当前全部持仓记录")
.def("getPositionList", &TradeManager::getPositionList, "获取当前全部持仓记录")
.def(
"getHistoryPositionList",
[](const TradeManager& tm) { return vector_to_python_list(tm.getHistoryPositionList()); },
"获取全部历史持仓记录,即已平仓记录")
.def("getHistoryPositionList", &TradeManager::getHistoryPositionList,
"获取全部历史持仓记录,即已平仓记录")
.def(
"getPosition", &TradeManager::getPosition,
......
......@@ -6,6 +6,7 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <hikyuu/trade_sys/signal/build_in.h>
#include "../convert_any.h"
#include "../pybind_utils.h"
......@@ -76,15 +77,9 @@ void export_Signal(py::module& m) {
:param Datetime datetime: 指定时刻
:rtype: bool)")
.def(
"getBuySignal",
[](const SignalBase& sg) { return vector_to_python_list(sg.getBuySignal()); },
R"(获取所有买入指示日期列表)")
.def("getBuySignal", &SignalBase::getBuySignal, R"(获取所有买入指示日期列表)")
.def(
"getSellSignal",
[](const SignalBase& sg) { return vector_to_python_list(sg.getSellSignal()); },
R"(获取所有卖出指示日期列表)")
.def("getSellSignal", &SignalBase::getSellSignal, R"(获取所有卖出指示日期列表)")
.def("_addBuySignal", &SignalBase::_addBuySignal,
R"(加入买入信号,在_calculate中调用
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment