📄 qianlong.cpp.svn-base
字号:
}
sFileName = GetRootPath();
sFileName += ml_sz_now;
if( file.Open( sFileName, CSPFile::modeRead | CSPFile::shareDenyNone ) )
{
// pin yin file
CSPString sFileNamePyjc = GetRootPath();
sFileNamePyjc += ml_sz_pyjc;
CSPFile filePyjc;
filePyjc.Open( sFileNamePyjc, CSPFile::modeRead | CSPFile::shareDenyNone );
if( version302 == m_nVersion )
{
struct QL_Stock_info_V302 block;
while( nCount < maxsize
&& sizeof(block) == file.Read( &block, sizeof(block) ) )
{
pdata[nCount].Clear();
ConvertQLStockInfo( CStock::marketSZSE, block, &(pdata[nCount]) );
// read shortname
if( CSPFile::hFileNull != filePyjc.m_hFile && QL_SHORTNAME_LEN == filePyjc.Read( szShortName, QL_SHORTNAME_LEN ) )
pdata[nCount].SetStockShortName( szShortName );
nCount ++;
}
}
else if( version304 == m_nVersion )
{
struct QL_Stock_info2_V304 block;
while( nCount < maxsize
&& sizeof(block) == file.Read( &block, sizeof(block) ) )
{
pdata[nCount].Clear();
ConvertQLStockInfo( CStock::marketSZSE, block, &(pdata[nCount]) );
// read shortname
if( CSPFile::hFileNull != filePyjc.m_hFile && QL_SHORTNAME_LEN == filePyjc.Read( szShortName, QL_SHORTNAME_LEN ) )
pdata[nCount].SetStockShortName( szShortName );
nCount ++;
}
}
file.Close();
}
container.SetSize( nCount );
return nCount;
}
int CQianlong::StoreCodetable( CStockContainer & container )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::LoadKDataCache( CStockContainer & container, PROGRESS_CALLBACK fnCallback, void *cookie, int nProgStart, int nProgEnd )
{
SP_ASSERT( m_bIsOK );
if( !m_bIsOK ) return 0;
UINT nCacheDays = AfxGetProfile().GetCacheDays();
// 读取行情缓存
SP_ASSERT( nProgStart <= nProgEnd );
int nCount = container.GetSize();
int nCacheCount = 0;
int nProgressSegment = nCount / 25;
double dProgressRatio = ( 0 == nCount ? 1 : (nProgEnd-nProgStart)/nCount );
for( int i=0; i<nCount; i++ )
{
container.Lock();
CStockInfo & info = container.ElementAt(i);
DWORD dwMarket = info.GetMarket();
CSPString sCode = info.GetStockCode();
// Get Data From Day K Line
CSPString sFileName;
GetFileName( sFileName, CStock::dataK, &info, CKData::ktypeDay );
CSPFile file;
if( file.Open( sFileName, CSPFile::modeRead | CSPFile::shareDenyNone ) )
{
DWORD dwFileLen = file.GetLength();
struct QL_Data_day qlkd;
info.m_kdata.SetSize( 0, nCacheDays+3 );
if( dwFileLen > sizeof(qlkd)*(nCacheDays+1) )
file.Seek( dwFileLen-sizeof(qlkd)*(nCacheDays+1), CSPFile::begin );
while( sizeof(qlkd) == file.Read( &qlkd, sizeof(qlkd) ) )
{
KDATA kd;
convert_QL_Data_day_to_KDATA( dwMarket, sCode, &qlkd, &kd );
info.m_kdata.Add( kd );
}
file.Close();
nCacheCount ++;
if( fnCallback && !(nCacheCount % nProgressSegment) )
fnCallback( PROG_PROGRESS, (int)(nProgStart+nCacheCount*dProgressRatio), NULL, cookie );
}
container.UnLock();
}
return nCount;
}
int CQianlong::LoadBasetable( CStockContainer & container )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::StoreBasetable( CStockContainer & container )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::LoadBaseText( CStock *pstock )
{
SP_ASSERT( m_bIsOK && pstock && pstock->GetStockInfo().IsValidStock() );
if( ! m_bIsOK || ! pstock || !pstock->GetStockInfo().IsValidStock() ) return 0;
CSPString sFileName;
GetFileName( sFileName, CStock::dataBasetext, &(pstock->GetStockInfo()) );
int nCount = 0;
CSPFile file;
if( file.Open( sFileName, CSPFile::modeRead | CSPFile::shareDenyNone ) )
{
DWORD dwLen = file.GetLength();
if( pstock->AllocBaseTextMem( dwLen ) )
{
nCount = file.Read( pstock->GetBaseTextPtr(), dwLen );
}
file.Close();
}
return nCount;
}
int CQianlong::LoadKData( CStock *pstock, int nKType )
{
SP_ASSERT( m_bIsOK && pstock && pstock->GetStockInfo().IsValidStock() );
if( ! m_bIsOK || ! pstock || !pstock->GetStockInfo().IsValidStock() ) return 0;
CKData * pkdata = NULL;
DWORD dwMarket = pstock->GetStockInfo().GetMarket();
CSPString sCode = pstock->GetStockCode();
CSPString sFileName;
GetFileName( sFileName, CStock::dataK, &(pstock->GetStockInfo()), nKType );
switch( nKType )
{
case CKData::ktypeMonth:
pkdata = &(pstock->GetKDataMonth());
break;
case CKData::ktypeWeek:
pkdata = &(pstock->GetKDataWeek());
break;
case CKData::ktypeDay:
pkdata = &(pstock->GetKDataDay());
break;
case CKData::ktypeMin60:
return 0;
case CKData::ktypeMin30:
return 0;
case CKData::ktypeMin15:
return 0;
case CKData::ktypeMin5:
pkdata = &(pstock->GetKDataMin5());
break;
default:
return 0;
}
if( CKData::IsDayOrMin(nKType) )
{
CSPFile file;
if( pkdata && file.Open( sFileName, CSPFile::modeRead | CSPFile::shareDenyNone ) )
{
DWORD dwLen = file.GetLength();
struct QL_Data_day qlkd;
int nSize = dwLen/sizeof(qlkd);
int nOldMaindataType = pkdata->GetMaindataType();
pkdata->Clear();
pkdata->SetKType( nKType );
pkdata->SetMaindataType( nOldMaindataType );
pkdata->SetSize( 0, nSize+1 );
while( sizeof(qlkd) == file.Read( &qlkd, sizeof(qlkd) ) )
{
KDATA kd;
convert_QL_Data_day_to_KDATA( dwMarket, sCode, &qlkd, &kd );
pkdata->Add( kd );
}
file.Close();
}
}
else
{
CSPFile file;
if( pkdata && file.Open( sFileName, CSPFile::modeRead | CSPFile::shareDenyNone ) )
{
DWORD dwLen = file.GetLength();
struct QL_Data_5min qlkd;
int nSize = dwLen/sizeof(qlkd);
int nOldMaindataType = pkdata->GetMaindataType();
pkdata->Clear();
pkdata->SetKType( nKType );
pkdata->SetMaindataType( nOldMaindataType );
pkdata->SetSize( 0, nSize+1 );
while( sizeof(qlkd) == file.Read( &qlkd, sizeof(qlkd) ) )
{
KDATA kd;
convert_QL_Data_5min_to_KDATA( dwMarket, sCode, &qlkd, &kd );
pkdata->Add( kd );
}
file.Close();
}
}
return pkdata->GetSize();
}
int CQianlong::LoadDRData( CStock *pstock )
{
return 0;
}
int CQianlong::StoreDRData( CStock *pstock )
{
return 0;
}
int CQianlong::LoadReport( CStock *pstock )
{
// load shtrace.dat sztrace.dat
return 0;
}
int CQianlong::LoadMinute( CStock *pstock )
{
// load shminute.dat szminute.dat
return 0;
}
int CQianlong::LoadOutline( CStock *pstock )
{
return 0;
}
int CQianlong::StoreReport( REPORT * pReport, int nCount, BOOL bBigTrade )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::StoreMinute( MINUTE * pMinute, int nCount )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::StoreOutline( OUTLINE * pOutline, int nCount )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::DetectVersion( const char * szRootPath )
{
int nRet = versionUnknown;
if( ! szRootPath ) return nRet;
int nCount = 0;
CSPString sFileName = szRootPath;
sFileName += ml_sh_now;
CSPFile file;
if( file.Open( sFileName, CSPFile::modeRead | CSPFile::shareDenyNone ) )
{
int nErrorCount = 1;
int nTotalCount = 1;
struct QL_Stock_info_V302 block;
while( sizeof(block) == file.Read( &block, sizeof(block) ) )
{
nTotalCount ++;
if( block.data_id != 0 && block.data_id != 0xFF && block.data_id != 0x94 )
{
nErrorCount ++;
}
}
if( (nErrorCount << 5) < nTotalCount )
{
nRet = version302;
}
else
{
nErrorCount = 1;
nTotalCount = 1;
struct QL_Stock_info2_V304 block2;
file.SeekToBegin();
while( sizeof(block2) == file.Read( &block2, sizeof(block2) ) )
{
nTotalCount ++;
if( block2.data_id != 0 && block2.data_id != 0xFF )
{
nErrorCount ++;
}
}
if( (nErrorCount << 5) < nTotalCount )
nRet = version304;
}
file.Close();
}
return nRet;
}
BOOL CQianlong::GetAccurateRoot( const char * rootpath, char *accurateroot, int maxlen )
{
if( 0 == rootpath || strlen(rootpath)==0 )
return FALSE;
// get rootpath
CSPString strRoot = rootpath;
int nLen = strRoot.GetLength();
if( strRoot[nLen-1] != '\\' && strRoot[nLen-1] != '/' )
strRoot += CHAR_DIRSEP;
nLen = strRoot.GetLength();
//if( 0 != access( strRoot + ml_sh_now, 0 ) )
// return FALSE;
if( 0 != access( strRoot + ml_sh, 0 ) )
return FALSE;
//if( 0 != access( strRoot + ml_sh_base, 0 ) )
// return FALSE;
//if( 0 != access( strRoot + ml_sh_day, 0 ) )
// return FALSE;
//if( 0 != access( strRoot + ml_sh_min, 0 ) )
// return FALSE;
strncpy( accurateroot, strRoot, maxlen-1);
accurateroot[maxlen-1] = '\0';
return TRUE;
}
int CQianlong::InstallCodetbl( const char * filename, const char *orgname )
{
if( NULL == filename || strlen(filename) == 0
|| NULL == orgname || strlen(orgname) == 0 )
return 0;
CSPString sFileName = GetRootPath();
sFileName += ml_dat;
sFileName += orgname;
return CSPFile::CopyFile( filename, sFileName, FALSE );
}
int CQianlong::InstallCodetblBlock( const char * filename, const char *orgname )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::InstallCodetblFxjBlock( const char * filename, const char *orgname )
{
SP_ASSERT( FALSE );
return 0;
}
int CQianlong::InstallKData( CKData &kdata, BOOL bOverwrite )
{
UINT nOpenFlags = CSPFile::modeCreate | CSPFile::modeReadWrite;
if( !bOverwrite ) nOpenFlags |= CSPFile::modeNoTruncate;
int nCount = 0;
CSPFile fileTo;
CSPString sFileName;
CStockInfo stockinfo;
DWORD dwMarket = kdata.ElementAt(0).m_dwMarket;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -