策略为王扩展系列-stkLIb工程扩展支持上海指数

Published

src/Client/StkLib/Include/Container.h

添加变量 和函数

protected:
	CSPMapStringToPtr	m_map2; //准备处理000001和指数重复问题
/*************custom extend 工具条 by freema*******/
	BOOL	SetMap2();
	/*****************************************/

 

添加实现

src/Client/StkLib/Src/Container.cpp

*************custom extend by freemam*******/
//功能:建立股票容器索引哈希表:股票代码+加市场,索引号 by freeman
BOOL CStockContainer::SetMap2()
{
	CSPMutex::Scoped	l(m_mutex);

	m_map2.RemoveAll();

	if (GetSize() == 0)
		return TRUE;

	m_map2.InitHashTable(GetSize() * 2 + 10);

	for (int i = 0; i < GetSize(); i++)
	{
		CSPString	str;

		CStockInfo& info = ElementAt(i);

		if (CStock::marketSZSE == info.GetMarket())
		{
			str.Format("1%s", info.GetStockCode());
			m_map2.SetAt(str, (void*)i);		
		}
		else
		{
			str.Format("0%s", info.GetStockCode());
			m_map2.SetAt(str, (void*)i);
		}
		
	}
	return TRUE;
}
/*****************************************/

 

建立索引:程序启动时建立索引

G:\stock\TskingVS2019\src\Client\StkLib\Src\Container.cpp

//加载代码表、加载财务数据 by freeman
BOOL CStockContainer::Load( CStDatabase * pDB, PROGRESS_CALLBACK fnCallback, void *cookie, int nProgStart, int nProgEnd )
{
	CSPMutex::Scoped	l(m_mutex);

	SP_ASSERT( nProgStart <= nProgEnd );
	SP_ASSERT( pDB );
	if( nProgStart > nProgEnd || NULL == pDB )
		return FALSE;

	Clear( );
	//加载代码表
	int	nLen	=	pDB->LoadCodetable( *this );
	SetMap( );//股票容器建立hash表索引 by freeman


/*************custom extend SetMap2 by freema*******/
	SetMap2();//股票容器建立hash表索引 by freeman
/*****************************************/

 

股票列表容器建立索引

//股票列表底部菜单分类、策略选股 by freeman
BOOL CStockContainer::RetrieveFromStatic( int nType, LPCTSTR lpszDomain, CStrategy * pStrategy, DWORD dwDate )
{
	
	}

	//股票容器建立hash表索引 by freeman
	SetMap( );


	/*************custom extend SetMap2 by freema*******/
	SetMap2();
	/*****************************************/
	

	DWORD	dwMainDate = -1;
	AfxGetStockContainer().GetCurrentType( NULL, NULL, &dwMainDate );
	if( m_dwDate != dwMainDate )
		OnDataChanged();
	else
		SetAverage( );
	return TRUE;
}

 

增加查找当前股票函数

/*************custom extend SetMap2 by freema*******/
	BOOL SetCurrentStock(CStockInfo* info);
	/*****************************************/