hikyuu2/hikyuu_pywrap/_StockManager.cpp

226 lines
9.0 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _StockManager.cpp
*
* Created on: 2011-12-4
* Author: fasiondog
*/
#include <hikyuu/StockManager.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
2023-12-27 02:16:10 +08:00
void export_StockManager(py::module& m) {
py::class_<StockManager>(m, "StockManager", "证券信息管理类")
2023-12-28 03:05:07 +08:00
.def_static("instance", &StockManager::instance, py::return_value_policy::reference,
"获取StockManager单例实例")
2020-07-10 00:23:33 +08:00
2021-02-17 19:43:59 +08:00
.def(
2023-12-27 02:16:10 +08:00
"init", &StockManager::init, py::arg("base_info_param"), py::arg("block_param"),
py::arg("kdata_param"), py::arg("preload_param"), py::arg("hikyuu_param"),
py::arg("context") = StrategyContext({"all"}),
2021-02-17 19:43:59 +08:00
R"(init(self, base_info_param, block_param, kdata_param, preload_param, hikyuu_param, context)
2020-07-10 00:23:33 +08:00
:param base_info_param
param block_param
param kdata_param K线数据驱动参数
param preload_param
2021-02-17 19:43:59 +08:00
param hikyuu_param
param StrategyContext context , )")
2020-07-10 00:23:33 +08:00
.def_property_readonly("data_ready", &StockManager::dataReady,
"是否所有数据已准备就绪(加载完毕)")
2021-01-29 00:18:01 +08:00
.def("reload", &StockManager::reload, "重新加载所有证券数据")
2020-07-10 00:23:33 +08:00
.def("tmpdir", &StockManager::tmpdir, R"(tmpdir(self) -> str
m_config中的tmpdir)")
2022-08-31 00:51:52 +08:00
.def("datadir", &StockManager::datadir, R"(datadir(self) -> str
)")
2020-07-10 00:23:33 +08:00
.def("get_base_info_parameter", &StockManager::getBaseInfoDriverParameter,
2023-12-27 02:16:10 +08:00
py::return_value_policy::copy, "获取当前基础信息驱动参数")
2020-07-10 00:23:33 +08:00
.def("get_block_parameter", &StockManager::getBlockDriverParameter,
2023-12-27 02:16:10 +08:00
py::return_value_policy::copy, "获取当前板块信息驱动参数")
2020-12-19 23:57:24 +08:00
.def("get_kdata_parameter", &StockManager::getKDataDriverParameter,
2023-12-27 02:16:10 +08:00
py::return_value_policy::copy, "获取当前K线数据驱动参数")
2020-12-19 23:57:24 +08:00
.def("get_preload_parameter", &StockManager::getPreloadParameter,
2023-12-27 02:16:10 +08:00
py::return_value_policy::copy, "获取当前预加载参数")
.def("get_hikyuu_parameter", &StockManager::getHikyuuParameter, py::return_value_policy::copy,
"获取当前其他参数")
2024-09-01 16:11:27 +08:00
.def("get_context", &StockManager::getStrategyContext, py::return_value_policy::copy,
"获取当前上下文")
2020-07-10 00:23:33 +08:00
.def("get_market_list", &StockManager::getAllMarket, R"(get_market_list(self)
:rtype: StringList)")
.def("get_market_info", &StockManager::getMarketInfo, R"(get_market_info(self, market)
:param string market:
:return: Null<MarketInfo>()
:rtype: MarketInfo)")
.def("get_stock_type_info", &StockManager::getStockTypeInfo,
R"(get_stock_type_info(self, stk_type)
:param int stk_type: :py:data:`constant`
:return: Null<StockTypeInfo>()
:rtype: StockTypeInfo)")
.def("get_stock", &StockManager::getStock, R"(get_stock(self, querystr)
"市场简称证券代码"
:param str querystr: "sh000001"
:return: Null<Stock>()
:rtype: Stock)")
.def(
"get_stock_list",
[](const StockManager& self, py::object filter) {
StockList ret;
if (filter.is_none()) {
ret = self.getStockList();
} else {
HKU_CHECK(py::hasattr(filter, "__call__"), "filter not callable!");
py::object filter_func = filter.attr("__call__");
ret = self.getStockList(
[&](const Stock& stk) { return filter_func(stk).cast<bool>(); });
}
return ret;
},
py::arg("filter") = py::none(), R"(get_stock_list(self[, filter=None])
:param func filter: stock, True | False )")
2020-07-31 00:20:22 +08:00
.def("get_block", &StockManager::getBlock, R"(get_block(self, category, name)
2020-07-10 00:23:33 +08:00
:param str category:
:param str name:
:return: Block
:rtype: Block)")
.def("get_block_list", py::overload_cast<>(&StockManager::getBlockList))
2023-12-27 02:16:10 +08:00
.def("get_block_list", py::overload_cast<const string&>(&StockManager::getBlockList),
R"(get_block_list(self[, category])
2020-07-10 00:23:33 +08:00
:param str category:
:return:
:rtype: BlockList)")
2023-12-27 02:16:10 +08:00
.def("get_trading_calendar", &StockManager::getTradingCalendar, py::arg("query"),
py::arg("market") = "SH",
2020-07-10 00:23:33 +08:00
R"(get_trading_calendar(self, query[, market='SH'])
:param KQuery query: Query查询条件
:param str market:
:return:
:rtype: DatetimeList)")
2023-12-27 02:16:10 +08:00
.def("add_temp_csv_stock", &StockManager::addTempCsvStock, py::arg("code"),
py::arg("day_filename"), py::arg("min_filename"), py::arg("tick") = 0.01,
py::arg("tick_value") = 0.01, py::arg("precision") = 2, py::arg("min_trade_num") = 1,
py::arg("max_trade_num") = 1000000,
R"(add_temp_csv_stock(code, day_filename, min_filename[, tick=0.01, tick_value=0.01,
precision=2, min_trade_num = 1, max_trade_num=1000000])
2020-07-10 00:23:33 +08:00
2022-02-05 21:32:50 +08:00
CSV文件K线数据StockCSV格式的K线数据时
2023-12-27 02:16:10 +08:00
stock market "TMP", sm tmpsm['tmp0001']
CSV文件第一行为标题
DatetimeDateOPENHIGHLOWCLOSEAMOUNTVOLUMEVOLCOUNT
2024-04-16 22:48:19 +08:00
csv 使 utf8
2020-07-10 00:23:33 +08:00
:param str code: Stock相同Null<Stock>
:param str day_filename: 线CSV文件名
:param str min_filename: 线CSV文件名
:param float tick: 0.01
:param float tick_value: 0.01
:param int precision: 2
:param int min_trade_num: 1
:param int max_trade_num: 1000000
:return: Stock
2023-12-27 02:16:10 +08:00
:rtype: Stock)",
py::keep_alive<1, 2>())
2020-07-10 00:23:33 +08:00
.def("remove_temp_csv_stock", &StockManager::removeTempCsvStock,
R"(remove_temp_csv_stock(self, code)
2020-07-10 00:23:33 +08:00
Stock
:param str code: )")
.def("is_holiday", &StockManager::isHoliday, R"(is_holiday(self, d)
:param Datetime d: )")
2024-04-13 18:05:25 +08:00
.def("get_history_finance_field_name", &StockManager::getHistoryFinanceFieldName,
py::return_value_policy::copy, R"(get_history_finance_field_name(self, index)
)")
.def("get_history_finance_field_index", &StockManager::getHistoryFinanceFieldIndex,
R"(get_history_finance_field_index(self, name)
)")
.def(
"get_history_finance_all_fields",
[](const StockManager& sm) {
auto fields = sm.getHistoryFinanceAllFields();
py::list ret;
for (const auto& f : fields) {
ret.append(py::make_tuple(f.first, f.second));
}
return ret;
},
R"(get_history_finance_all_fields(self)
)")
2024-04-14 03:39:45 +08:00
2024-04-16 18:05:23 +08:00
.def("add_stock", &StockManager::addStock, R"(add_stock(self, stock)
2024-04-16 23:44:41 +08:00
Stock
2024-04-16 18:05:23 +08:00
@return True | False)")
.def("remove_stock", &StockManager::removeStock, R"(remove_stock(self, market_code)
2024-04-16 23:44:41 +08:00
sm market_code 使 Stock
:param str market_code: )")
2020-07-10 00:23:33 +08:00
.def("__len__", &StockManager::size, "返回证券数量")
.def("__getitem__", &StockManager::getStock, "同 get_stock")
2023-12-27 02:16:10 +08:00
.def(
"__iter__",
[](const StockManager& sm) {
return py::make_iterator<py::return_value_policy::reference_internal, StockMapIterator,
StockMapIterator, const Stock&>(sm.begin(), sm.end());
},
py::keep_alive<0, 1>());
2015-01-07 01:26:14 +08:00
}