mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-29 18:39:10 +08:00
Stock 添加获取所属板块列表方法
This commit is contained in:
parent
3504345b9d
commit
02a09de0ff
@ -34,17 +34,29 @@ Block::Block(const string& category, const string& name, const string& indexCode
|
||||
}
|
||||
|
||||
Block::Block(const Block& block) noexcept {
|
||||
if (m_data == block.m_data)
|
||||
if (!block.m_data)
|
||||
return;
|
||||
m_data = block.m_data;
|
||||
}
|
||||
|
||||
Block::Block(Block&& block) noexcept {
|
||||
if (!block.m_data)
|
||||
return;
|
||||
m_data = std::move(block.m_data);
|
||||
}
|
||||
|
||||
Block& Block::operator=(const Block& block) noexcept {
|
||||
HKU_IF_RETURN(this == &block || m_data == block.m_data, *this);
|
||||
m_data = block.m_data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Block& Block::operator=(Block&& block) noexcept {
|
||||
HKU_IF_RETURN(this == &block || m_data == block.m_data, *this);
|
||||
m_data = std::move(block.m_data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Block::have(const string& market_code) const {
|
||||
HKU_IF_RETURN(!m_data, false);
|
||||
string query_str = market_code;
|
||||
|
@ -23,7 +23,9 @@ public:
|
||||
Block(const string& category, const string& name);
|
||||
Block(const string& category, const string& name, const string& indexCode);
|
||||
Block(const Block&) noexcept;
|
||||
Block(Block&&) noexcept;
|
||||
Block& operator=(const Block&) noexcept;
|
||||
Block& operator=(Block&&) noexcept;
|
||||
virtual ~Block();
|
||||
|
||||
typedef StockMapIterator const_iterator;
|
||||
|
@ -831,6 +831,10 @@ Parameter Stock::getFinanceInfo() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<Block> Stock::getBelongToBlockList(const string& category) const {
|
||||
return StockManager::instance().getStockBelongs(*this, category);
|
||||
}
|
||||
|
||||
// 判断是否在交易时间段内(不判断日期)
|
||||
bool Stock::isTransactionTime(Datetime time) {
|
||||
MarketInfo market_info = StockManager::instance().getMarketInfo(market());
|
||||
|
@ -28,6 +28,7 @@ typedef DriverConnectPool<KDataDriverConnect> KDataDriverConnectPool;
|
||||
typedef shared_ptr<KDataDriverConnectPool> KDataDriverConnectPoolPtr;
|
||||
class HKU_API KData;
|
||||
class HKU_API Parameter;
|
||||
class HKU_API Block;
|
||||
|
||||
/**
|
||||
* Stock基类,Application中一般使用StockPtr进行操作
|
||||
@ -191,6 +192,13 @@ public:
|
||||
*/
|
||||
Parameter getFinanceInfo() const;
|
||||
|
||||
/**
|
||||
* 获取所属板块列表
|
||||
* @param category 指定的板块分类,如果为空,则返回所有板块分类的所属板块
|
||||
* @return BlockList
|
||||
*/
|
||||
vector<Block> getBelongToBlockList(const string& category) const;
|
||||
|
||||
/**
|
||||
* 获取历史财务信息
|
||||
*/
|
||||
|
@ -403,6 +403,10 @@ BlockList StockManager::getBlockList() {
|
||||
return m_blockDriver ? m_blockDriver->getBlockList() : BlockList();
|
||||
}
|
||||
|
||||
BlockList StockManager::getStockBelongs(const Stock& stk, const string& category) {
|
||||
return m_blockDriver ? m_blockDriver->getStockBelongs(stk, category) : BlockList();
|
||||
}
|
||||
|
||||
DatetimeList StockManager::getTradingCalendar(const KQuery& query, const string& market) {
|
||||
auto marketinfo = getMarketInfo(market);
|
||||
return getStock(fmt::format("{}{}", marketinfo.market(), marketinfo.code()))
|
||||
|
@ -141,7 +141,14 @@ public:
|
||||
*/
|
||||
BlockList getBlockList();
|
||||
|
||||
// 目前支持"SH"
|
||||
/**
|
||||
* 获取指定证券所属的板块列表
|
||||
* @param stk 指定证券
|
||||
* @param category 板块分类,如果为空字符串,返回所有板块分类下的所属板块
|
||||
* @return BlockList
|
||||
*/
|
||||
BlockList getStockBelongs(const Stock& stk, const string& category);
|
||||
|
||||
/**
|
||||
* 获取交易日历,目前支持"SH"
|
||||
* @param query
|
||||
|
@ -55,4 +55,15 @@ bool BlockInfoDriver::init(const Parameter& params) {
|
||||
return _init();
|
||||
}
|
||||
|
||||
BlockList BlockInfoDriver::getStockBelongs(const Stock& stk, const string& category) {
|
||||
BlockList ret;
|
||||
auto category_blks = category.empty() ? getBlockList() : getBlockList(category);
|
||||
for (auto&& blk : category_blks) {
|
||||
if (blk.have(stk)) {
|
||||
ret.emplace_back(std::move(blk));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -35,6 +35,14 @@ public:
|
||||
*/
|
||||
bool init(const Parameter& params);
|
||||
|
||||
/**
|
||||
* 获取指定证券所属的板块列表
|
||||
* @param stk 指定证券
|
||||
* @param category 板块分类,如果为空字符串,返回所有板块分类下的所属板块
|
||||
* @return BlockList
|
||||
*/
|
||||
BlockList getStockBelongs(const Stock& stk, const string& category);
|
||||
|
||||
/**
|
||||
* 子类如果需要缓存,可实现该方法将数据加载至自身的缓存
|
||||
*/
|
||||
|
@ -175,6 +175,22 @@ void export_Stock(py::module& m) {
|
||||
:param Datetime end: 结束时刻
|
||||
:rtype: StockWeightList)")
|
||||
|
||||
.def(
|
||||
"get_belong_to_block_list",
|
||||
[](Stock& stk, const py::object& category) {
|
||||
string c_category;
|
||||
if (!category.is_none()) {
|
||||
c_category = category.cast<string>();
|
||||
}
|
||||
return stk.getBelongToBlockList(c_category);
|
||||
},
|
||||
py::arg("category") = py::none(), R"(get_belong_to_block_list(self[, category=None])
|
||||
|
||||
获取所属板块列表
|
||||
|
||||
:param str category: 指定的板块分类,为 None 时,返回所有板块分类下的所属板块
|
||||
:rtype: list)")
|
||||
|
||||
.def(
|
||||
"get_history_finance",
|
||||
[](const Stock& stk) {
|
||||
|
Loading…
Reference in New Issue
Block a user