📄 database.cpp.svn-base
字号:
if( !pstock || !IsOK() ) return 0;
int nSize = m_pStore->LoadReport( pstock );
if( nSize > 0 )
return nSize;
for( int i=0; i<m_aptrAssistant.GetSize(); i++ )
{
IStStore * pStore = (IStStore *)m_aptrAssistant.ElementAt(i);
if( pStore )
nSize = pStore->LoadReport( pstock );
if( nSize > 0 )
return nSize;
}
return nSize;
}
int CStDatabase::LoadMinute( CStock *pstock )
{
if( !pstock || !IsOK() ) return 0;
int nSize = m_pStore->LoadMinute( pstock );
if( nSize > 0 )
return nSize;
for( int i=0; i<m_aptrAssistant.GetSize(); i++ )
{
IStStore * pStore = (IStStore *)m_aptrAssistant.ElementAt(i);
if( pStore )
nSize = pStore->LoadMinute( pstock );
if( nSize > 0 )
return nSize;
}
return nSize;
}
int CStDatabase::LoadOutline( CStock *pstock )
{
if( !pstock || !IsOK() ) return 0;
int nSize = m_pStore->LoadOutline( pstock );
if( nSize > 0 )
return nSize;
for( int i=0; i<m_aptrAssistant.GetSize(); i++ )
{
IStStore * pStore = (IStStore *)m_aptrAssistant.ElementAt(i);
if( pStore )
nSize = pStore->LoadOutline( pstock );
if( nSize > 0 )
return nSize;
}
return nSize;
}
int CStDatabase::StoreReport( REPORT * pReport, int nCount, BOOL bBigTrade )
{ if(!IsOK()) return 0;
return m_pStore->StoreReport( pReport, nCount, bBigTrade ); }
int CStDatabase::StoreMinute( MINUTE * pMinute, int nCount )
{ if(!IsOK()) return 0;
return m_pStore->StoreMinute( pMinute, nCount ); }
int CStDatabase::StoreOutline( OUTLINE * pOutline, int nCount )
{ if(!IsOK()) return 0;
return m_pStore->StoreOutline( pOutline, nCount ); }
int CStDatabase::InstallCodetbl( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallCodetbl( filename, orgname ); }
int CStDatabase::InstallCodetblBlock( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallCodetblBlock( filename, orgname ); }
int CStDatabase::InstallCodetblFxjBlock( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallCodetblFxjBlock( filename, orgname ); }
int CStDatabase::InstallKData( CKData &kdata, BOOL bOverwrite )
{ if(!IsOK()) return 0;
return m_pStore->InstallKData( kdata, bOverwrite ); }
int CStDatabase::InstallKDataTy( const char * stkfile, int ktype, PROGRESS_CALLBACK fnCallback, void *cookie )
{ if(!IsOK()) return 0;
return m_pStore->InstallKDataTy( stkfile, ktype, fnCallback, cookie ); }
int CStDatabase::InstallKDataFxj( const char * dadfile, int ktype, PROGRESS_CALLBACK fnCallback, void *cookie )
{ if(!IsOK()) return 0;
return m_pStore->InstallKDataFxj( dadfile, ktype, fnCallback, cookie ); }
int CStDatabase::InstallDRData( CDRData &drdata )
{ if(!IsOK()) return 0;
return m_pStore->InstallDRData( drdata ); }
int CStDatabase::InstallDRDataClk( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallDRDataClk( filename, orgname ); }
int CStDatabase::InstallDRDataFxj( const char * fxjfilename )
{ if(!IsOK()) return 0;
return m_pStore->InstallDRDataFxj( fxjfilename ); }
int CStDatabase::InstallBasetable( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallBasetable( filename, orgname ); }
int CStDatabase::InstallBasetableTdx( const char * filename )
{ if(!IsOK()) return 0;
return m_pStore->InstallBasetableTdx( filename ); }
int CStDatabase::InstallBasetableFxj( const char * filename )
{ if(!IsOK()) return 0;
return m_pStore->InstallBasetableFxj( filename ); }
int CStDatabase::InstallBaseText( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallBaseText( filename, orgname ); }
int CStDatabase::InstallBaseText( const char * buffer, int nLen, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallBaseText( buffer, nLen, orgname ); }
int CStDatabase::InstallNewsText( const char * filename, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallNewsText( filename, orgname ); }
int CStDatabase::InstallNewsText( const char * buffer, int nLen, const char *orgname )
{ if(!IsOK()) return 0;
return m_pStore->InstallNewsText( buffer, nLen, orgname ); }
BOOL CStDatabase::AddAssistantRootPath( const char * rootpath, int nDBType )
{
IStStore * pStore = IStStore::CreateStore( rootpath, nDBType );
if( NULL == pStore )
return FALSE;
m_aptrAssistant.Add( pStore );
return TRUE;
}
void CStDatabase::RemoveAssistant( const char * rootpath )
{
if( NULL == rootpath || strlen(rootpath) == 0 )
return;
for( int i=m_aptrAssistant.GetSize()-1; i>=0; i-- )
{
IStStore * pStore = (IStStore *)m_aptrAssistant.ElementAt(i);
if( pStore && 0 == strcmp( pStore->GetRootPath(), rootpath ) )
{
m_aptrAssistant.RemoveAt(i);
delete pStore;
}
}
}
void CStDatabase::RemoveAllAssistant( )
{
for( int i=0; i<m_aptrAssistant.GetSize(); i++ )
{
IStStore * pStore = (IStStore *)m_aptrAssistant.ElementAt(i);
if( pStore )
{
delete pStore;
}
}
m_aptrAssistant.RemoveAll( );
}
CSPTime CStDatabase::GetTimeInitial( )
{
return CSPTime( 1990, 12, 19, 0, 0, 0 );
}
BOOL CStDatabase::GetTimeLocalRange( CSPTime *ptmLatest, CSPTime * ptmPioneer, CSPTime * ptmInitial )
{
CStock stock;
stock.SetStockCode( CStock::marketSHSE, STKLIB_CODE_MAIN );
stock.SetDatabase( this );
if( !stock.PrepareData( CStock::dataK, CKData::ktypeDay ) )
return FALSE;
CKData & kday = stock.GetKDataDay();
int nYear, nMonth, nDay, nHour, nMinute;
if( ptmLatest )
{
if( !kday.LatestDate( nYear, nMonth, nDay, nHour, nMinute ) )
return FALSE;
*ptmLatest = CSPTime( nYear, nMonth, nDay, 23, 59, 59 );
}
if( ptmPioneer )
{
if( kday.GetSize() == 0 || !kday.DateAt(0, nYear, nMonth, nDay, nHour, nMinute ) )
return FALSE;
*ptmPioneer = CSPTime( nYear, nMonth, nDay, 0, 0, 0 );
}
if( ptmInitial )
{
*ptmInitial = GetTimeInitial( );
}
return TRUE;
}
BOOL CStDatabase::GetNeedDownloadRange( CStockInfo &info, CSPTime tmBegin, CSPTime tmEnd, CSPTime &tmDLBegin, CSPTime &tmDLEnd )
{
tmDLBegin = tmBegin;
tmDLEnd = tmEnd;
// Prepare Data
CStock stock;
stock.SetStockInfo( &info );
stock.SetDatabase( this );
if( !stock.PrepareData( CStock::dataK, CKData::ktypeDay ) )
return TRUE;
CKData & kday = stock.GetKDataDay();
// Prepare Time
CSPTime tmInitial, tmLatest, tmPioneer;
CSPTime sptimeInitial;
if( 0 != info.m_datebegin && sptimeInitial.FromStockTimeDay( info.m_datebegin ) )
tmInitial = sptimeInitial.GetTime();
else
tmInitial = GetTimeInitial( );
int nYear, nMonth, nDay, nHour, nMinute;
if( !kday.LatestDate( nYear, nMonth, nDay, nHour, nMinute ) )
return TRUE;
tmLatest = CSPTime( nYear, nMonth, nDay, 23, 59, 59 );
if( kday.GetSize() == 0 || !kday.DateAt(0, nYear, nMonth, nDay, nHour, nMinute ) )
return TRUE;
tmPioneer = CSPTime( nYear, nMonth, nDay, 0, 0, 0 );
// Deal With
if( tmBegin < tmInitial )
tmBegin = tmInitial;
if( tmBegin >= tmPioneer && tmEnd <= tmLatest )
{
int nCount = 0;
for( int k=0; k<kday.GetSize(); k++ )
{
DWORD date = kday.ElementAt(k).m_date;
CSPTime sptime;
if( sptime.FromStockTimeDay(date) )
{
if( sptime.GetTime() >= tmBegin.GetTime() && sptime.GetTime() <= tmEnd.GetTime() )
nCount ++;
}
}
CSPTimeSpan span = tmEnd - tmBegin;
if( nCount > span.GetDays()*4/7 )
return FALSE;
}
if( tmEnd <= tmPioneer )
{
tmDLBegin = tmBegin;
tmDLEnd = tmPioneer-CSPTimeSpan(1,0,0,0);
}
else if( tmBegin >= tmLatest )
{
tmDLBegin = tmLatest+CSPTimeSpan(1,0,0,0);
tmDLEnd = tmEnd;
}
else if( tmBegin < tmPioneer && tmEnd > tmPioneer && tmEnd <= tmLatest )
{
tmDLBegin = tmBegin;
tmDLEnd = tmPioneer-CSPTimeSpan(1,0,0,0);
}
else if( tmBegin >= tmPioneer && tmBegin < tmLatest && tmEnd > tmLatest )
{
tmDLBegin = tmLatest+CSPTimeSpan(1,0,0,0);
tmDLEnd = tmEnd;
}
else
{
tmDLBegin = tmBegin;
tmDLEnd = tmEnd;
}
return TRUE;
}
// 将钱龙格式K线数据 加入 通用数据包
int CStDatabase::AppendToTyData( const char *code, const char *name, int nKType, LPCTSTR lpszKFile, LPCTSTR lpszTyDataFile, time_t tmBegin, time_t tmEnd )
{
int nCount = 0;
CSPFile fileK, fileTy;
if( fileK.Open( lpszKFile, CSPFile::modeRead )
&& fileTy.Open( lpszTyDataFile, CSPFile::modeCreate|CSPFile::modeNoTruncate|CSPFile::modeReadWrite ) )
{
// Init Header
TYDAY_FHEADER header;
memset( &header, 0, sizeof(header) );
header.magic = 0x06;
for( int i=0; i<sizeof(header.code); i++ )
header.code[i] = ' ';
header.magic2 = 0x08;
for( int i=0; i<sizeof(header.name); i++ )
header.name[i] = ' ';
CSPTime sptime = CSPTime::GetCurrentTime();
header.date = sptime.ToStockTimeDay();
header.datebegin= header.date;
header.dateend = header.date;
header.gendate = header.date;
header.gentime = sptime.GetTime();
if( sizeof(header) != fileTy.Read( &header, sizeof(header) ) )
{
fileTy.SeekToBegin();
fileTy.Write( &header, sizeof(header) );
}
header.from = 'CL';
fileTy.SeekToEnd();
// generate
if( CKData::IsDayOrMin(nKType) )
{
DWORD dateBegin = CSPTime(tmBegin).ToStockTimeDay();
DWORD dateEnd = CSPTime(tmEnd).ToStockTimeDay();
struct QL_Data_day qlkd;
while( sizeof(qlkd) == fileK.Read( &qlkd, sizeof(qlkd) ) )
{
if( qlkd.day_date < dateBegin || qlkd.day_date > dateEnd )
continue;
KDATA kd;
TYDAY_RECORD tyrecord;
convert_QL_Data_day_to_KDATA( CStock::marketUnknown, code, &qlkd, &kd );
convert_KDATA_to_TYDAY_RECORD( header.recordcount+1, name, &kd, &tyrecord );
fileTy.Write( &tyrecord, sizeof(tyrecord) );
// Modified header
if( tyrecord.date < header.datebegin )
header.datebegin = tyrecord.date;
if( tyrecord.date > header.dateend )
header.dateend = tyrecord.date;
header.recordcount += 1;
nCount ++;
}
}
else
{
DWORD dateBegin = CSPTime(tmBegin).ToStockTimeMin();
DWORD dateEnd = CSPTime(tmEnd).ToStockTimeMin();
struct QL_Data_5min qlkd;
while( sizeof(qlkd) == fileK.Read( &qlkd, sizeof(qlkd) ) )
{
if( qlkd.min_off < dateBegin || qlkd.min_off > dateEnd )
continue;
KDATA kd;
TYDAY_RECORD tyrecord;
convert_QL_Data_5min_to_KDATA( CStock::marketUnknown, code, &qlkd, &kd );
convert_KDATA_to_TYDAY_RECORD_MIN( header.recordcount+1, name, &kd, &tyrecord );
fileTy.Write( &tyrecord, sizeof(tyrecord) );
// Modified header
if( tyrecord.date < header.datebegin )
header.datebegin = tyrecord.date;
if( tyrecord.date > header.dateend )
header.dateend = tyrecord.date;
header.recordcount += 1;
nCount ++;
}
}
if( nCount > 0 )
header.sharecount += 1;
fileTy.SeekToBegin();
fileTy.Write( &header, sizeof(header) );
fileK.Close();
fileTy.Close();
}
return nCount;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -