Stock 添加获取所属板块列表方法

This commit is contained in:
fasiondog 2024-04-26 18:46:09 +08:00
parent 3504345b9d
commit 02a09de0ff
9 changed files with 74 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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());

View File

@ -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;
/**
*
*/

View File

@ -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()))

View File

@ -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

View File

@ -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 */

View File

@ -35,6 +35,14 @@ public:
*/
bool init(const Parameter& params);
/**
*
* @param stk
* @param category
* @return BlockList
*/
BlockList getStockBelongs(const Stock& stk, const string& category);
/**
*
*/

View File

@ -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) {