void SQLCode::_BuildNormalSQL(const SQLVarParms& varParms, SQLStatement& rSQLFormats, SQLStatement& rSqlStatement) { BOOST_LOG_FUNCTION(); if (!rSQLFormats.strCommonSQL.empty()) { _BuildSQL(varParms, rSQLFormats.strCommonSQL, rSqlStatement.strCommonSQL); } else { if (rSQLFormats.strOracleSQL.empty() || rSQLFormats.strMySQLSQL.empty() || rSQLFormats.strSQLiteSQL.empty()) { throw DataAccessException(ER_DB_ERR_SQLCode, "The MySQL or Oracle SQL or SQLite Format is empty"); } // build Oracle SQL Statement _BuildSQL(varParms, rSQLFormats.strOracleSQL, rSqlStatement.strOracleSQL, enumOracleDb); // build MySQL SQL statement _BuildSQL(varParms, rSQLFormats.strMySQLSQL, rSqlStatement.strMySQLSQL, enumMysqlDb); // build SqliteDb SQL Statement _BuildSQL(varParms, rSQLFormats.strSQLiteSQL, rSqlStatement.strSQLiteSQL, enumSqliteDb); } }
void SQLCode::_BuildSQLStatement(SQLVarParms& varParms, SQLStatement& rSqlStatement) { BOOST_LOG_FUNCTION(); std::string strSQLKey; SQLStatement SQLFormats; int nDbType = 0; size_t uiTotalSQLSize = 0; try { size_t uVarCount = varParms.size(); if (uVarCount < 1) { throw DataAccessException(ER_DB_ERR_SQLCode, "the PrepareStatement parameter count error!"); } _GetDbTypeAndSQLKey(varParms, strSQLKey);//strSQLID=strSQLKey=varParms[0] _GetSQLFormat(strSQLKey, SQLFormats); _BuildNormalSQL(varParms, SQLFormats, rSqlStatement); rSqlStatement.logInfo(); } catch (DataAccessException& e) { throw e; } catch (...) { throw DataAccessException(ER_DB_ERR_UNKNOWN, "buildSQLStatement error!"); } }
CInstrumentTickInfo& CInstrumentTickInfo::operator=(const CInstrumentTickInfo& instrumentTickInfo ) { BOOST_LOG_FUNCTION(); m_TickInfo = instrumentTickInfo.m_TickInfo; return *this; }
//"%04d-%02d-%02d %02d:%02d:%02d" std::string CCFDServerUtilityFun::dataTimeToStr(time_t nTimeValue) { BOOST_LOG_FUNCTION(); std::string strTimeString; char* pszCurTime = NULL; int nBufferSize = 256; struct tm* pTM = NULL; time_t time_Value = (time_t)nTimeValue; pszCurTime =new char[nBufferSize]; memset(pszCurTime, 0, nBufferSize); pTM = localtime(&(time_Value)); //TIMESTR--%Y%m%d%H%M%S //format to string if ( NULL != pTM ) { sprintf(pszCurTime, "%04d-%02d-%02d %02d:%02d:%02d", pTM->tm_year + 1900, pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, pTM->tm_sec); strTimeString = pszCurTime; } delete pszCurTime; pszCurTime = NULL; pTM = NULL; return strTimeString; }
void CMarketDataFileManager::setInstrumentBarInfoRequest( const CInstrumentBarInfoRequest& instrumentBarInfoRequest ) { BOOST_LOG_FUNCTION(); m_InstrumentBarInfoRequest = instrumentBarInfoRequest; setAnalieType(AnalierType_Dispatch_MarkketData); }
int CServerManager::_InitServer() { BOOST_LOG_FUNCTION(); int nFunRes = 0; if (g_string_strServerAddress.empty()) { LOG_ERROR<<"error! g_string_strServerAddress="<<g_string_strServerAddress; nFunRes = -1; return nFunRes; } { boost::mutex::scoped_lock lock(m_mutexBrokerServer); m_brokerServer.onConnected = boost::bind(&TA_Base_App::CServerManager::handleConnected, this, _1);//static boost::arg<1> _1; m_brokerServer.onDisconnected = boost::bind(&TA_Base_App::CServerManager::handleDisconnected, this, _1);//static boost::arg<1> _1; m_brokerServer.onReceived = boost::bind(&TA_Base_App::CServerManager::handleReceivedMessage, this, _1);//static boost::arg<1> _1; m_brokerServer.onDeliverFailure = boost::bind(&TA_Base_App::CServerManager::handleDeliverFailure, this, _1);//static boost::arg<1> _1; LOG_DEBUG<< "begin listen g_string_strServerAddress="<<g_string_strServerAddress; m_brokerServer.listen(g_string_strServerAddress); } return nFunRes; }
void CConfigInfoHelper::_GetConifgFileInfo() { BOOST_LOG_FUNCTION(); CFileSystemItem::LstLineT lstLine; CFileSystemItem::LstLineIterT iterLst; m_pConfigFileInfo->getAllLinesInFile(lstLine); iterLst = lstLine.begin(); while (iterLst != lstLine.end()) { std::string strLineTmp = *iterLst; std::string strParamKey; CParamItem* pParamItem = new CParamItem(strLineTmp); strParamKey = pParamItem->getParamKey(); m_MapParamKeyParamItem.insert(MapParamKeyParamItemValueTypeT(strParamKey, pParamItem)); pParamItem = NULL; iterLst++; }//while lstLine.clear(); return; }
void CConfigInfo::logInfo() { BOOST_LOG_FUNCTION(); LOG_INFO<<"CConfigInfo::logInfo" <<" "<<"m_strValue_ConfigFileName="<<m_strValue_ConfigFileName <<" "<<"m_strValue_HistoryDataDirectory="<<m_strValue_HistoryDataDirectory <<" "<<"m_strValue_SaveDataDirectoryBAR="<<m_strValue_SaveDataDirectoryBAR <<" "<<"m_strValue_SaveDataDirectoryTIK="<<m_strValue_SaveDataDirectoryTIK <<" "<<"m_strValue_DbType="<<m_strValue_DbType <<" "<<"m_strValue_StartTime_InDB="<<m_strValue_StartTime_InDB <<" "<<"m_strValue_StartTime_InFile="<<m_strValue_StartTime_InFile <<" "<<"m_strValue_LoadMaxFilesSize="<<m_strValue_LoadMaxFilesSize <<" "<<"m_strValue_AutoRun="<<m_strValue_AutoRun <<" "<<"m_strValue_AutoRunTime="<<m_strValue_AutoRunTime; LOG_INFO<<"CConfigInfo::logInfo" <<" "<<"m_nValue_DbType="<<m_nValue_DbType <<" "<<"m_nValue_StartTime="<<m_nValue_StartTime <<" "<<"m_nValue_LoadMaxFilesSize="<<m_nValue_LoadMaxFilesSize <<" "<<"m_nValue_AutoRun="<<m_nValue_AutoRun; m_pSQLiteConfigFileOperParam->logInfo(); return; }
void CServerManager::handleConnected(const SessionInfo &stSessionInfo) { BOOST_LOG_FUNCTION(); //m_pServerWorkerForTest->handleDisconnected(stSessionInfo); }
void CServerManager::handleDeliverFailure(Message::Ptr pGetMessage) { BOOST_LOG_FUNCTION(); //m_pServerWorkerForTest->handleReceivedMessage(pGetMessage); }
int CSqliteDbOper::_CreateDBTableTick() { BOOST_LOG_FUNCTION(); int nFunRes = 0; bool bExecRes = true; std::string strSQL; QSqlQuery* pSqlQuery = NULL; pSqlQuery = new QSqlQuery(*m_pQSqlDataBaseTIK); strSQL = _BuildSQLForCreateDBTableTick(); LOG_DEBUG<<"exec strSQL="<<strSQL; bExecRes = pSqlQuery->exec(strSQL.c_str()); if (!bExecRes) { nFunRes = -1; LOG_ERROR<<"Fail to exec sql:"<<strSQL<<" error:"<<pSqlQuery->lastError().text().toStdString(); } if (NULL != pSqlQuery) { delete pSqlQuery; pSqlQuery = NULL; } return nFunRes; }
int CFileSystemManager::removeOldFile(time_t nStarTime, MapTimeFileSystemItemT& mapTimeFileSystemItem ) { BOOST_LOG_FUNCTION(); int nFunRes = 0; MapTimeFileSystemItemIterT iterMap; time_t nFileTime; CFileSystemItem* pFileSystemItem = NULL; iterMap = mapTimeFileSystemItem.begin(); while (iterMap != mapTimeFileSystemItem.end()) { nFileTime = iterMap->first; pFileSystemItem = iterMap->second; if (nFileTime <= nStarTime) { delete pFileSystemItem; pFileSystemItem = NULL; mapTimeFileSystemItem.erase(iterMap); iterMap = mapTimeFileSystemItem.begin(); } else { iterMap++; } } return nFunRes; }
CMarketDataFileAnalier::CMarketDataFileAnalier(void) { BOOST_LOG_FUNCTION(); m_pUtilityFun = new CCFDServerUtilityFun(); m_pMarketDataDispatcher = new CMarketDataDispatcher(); }
int CSqliteDbOper::_CommitTransactionTIK() { BOOST_LOG_FUNCTION(); int nFunRes = 0; if (m_bStartTransactionTIK) { if(false == m_pQSqlDataBaseTIK->commit()) { LOG_DEBUG<<m_pDBOperParam->m_strQTDataSrcDbTypeName <<" "<<"m_strSQLiteDBFileNameFullPathTIK="<<m_pDBOperParam->m_strSQLiteDBFileNameFullPathTIK <<" "<<"commit error!" <<" "<<"error: "<<QSqlDatabase::database().lastError().text().toStdString(); if(false == m_pQSqlDataBaseTIK->rollback()) { LOG_ERROR<<m_pDBOperParam->m_strQTDataSrcDbTypeName <<" "<<"m_strSQLiteDBFileNameFullPathTIK="<<m_pDBOperParam->m_strSQLiteDBFileNameFullPathTIK <<" "<<"rollback error!" <<" "<<"error: "<<QSqlDatabase::database().lastError().text().toStdString(); }//if }//if else { LOG_DEBUG<<m_pDBOperParam->m_strQTDataSrcDbTypeName <<" "<<"m_strSQLiteDBFileNameFullPathTIK="<<m_pDBOperParam->m_strSQLiteDBFileNameFullPathTIK <<" "<<"commit Transaction"; } }//if m_bStartTransactionTIK = false; return nFunRes; }
int CSyncMarketDataForCFD::_SyncLstCFDBarInfo(LstBarInfoT& lstBarInfoFirst, LstBarInfoT& lstBarInfoSecond, LstCFDBarInfoT& lstCFDBarInfo) { BOOST_LOG_FUNCTION(); int nFunRes = 0; LstBarInfoIterT iterLstFirst; LstBarInfoIterT iterLstSecond; MarketData* pBarFirst = NULL; MarketData* pBarSecond = NULL; CCFDInstrumentBarInfo* pCFDInstrumentBarInfoTmp = NULL; if (lstBarInfoFirst.size() != lstBarInfoSecond.size()) { LOG_ERROR<<"_SyncLstCFDBarInfo size error!" <<" "<<"lstBarInfoFirst.size()="<<lstBarInfoFirst.size() <<" "<<"lstBarInfoSecond.size()="<<lstBarInfoSecond.size(); nFunRes = -1; return nFunRes; } iterLstFirst = lstBarInfoFirst.begin(); iterLstSecond = lstBarInfoSecond.begin(); while ( (iterLstFirst != lstBarInfoFirst.end()) && (iterLstSecond != lstBarInfoSecond.end()) ) { pBarFirst = NULL; pBarSecond = NULL; pBarFirst = (*iterLstFirst); pBarSecond = (*iterLstSecond); pCFDInstrumentBarInfoTmp =new CCFDInstrumentBarInfo(m_CFDRequest); pCFDInstrumentBarInfoTmp->setCFDRequest(m_CFDRequest); pCFDInstrumentBarInfoTmp->setBarInfoFirst(*pBarFirst); pCFDInstrumentBarInfoTmp->setBarInfoSecond(*pBarSecond); nFunRes = pCFDInstrumentBarInfoTmp->buidCFDBarInfo(); if (0 != nFunRes) { LOG_ERROR<<"buildCFDMarketData DataFirst.Time != DataSecond.Time" <<" ["<<"DataFirst.Time="<<m_pUtilityFun->dataTimeToStr(pBarFirst->getTime())<<"]" <<" ["<<"DataSecond.Time="<<m_pUtilityFun->dataTimeToStr(pBarSecond->getTime())<<"]"; } else { pCFDInstrumentBarInfoTmp->logInfo(); } lstCFDBarInfo.push_back(pCFDInstrumentBarInfoTmp); pCFDInstrumentBarInfoTmp = NULL; iterLstFirst++; iterLstSecond++; }//while return nFunRes; }
int main( int argc, char* argv[] ) { TA_Base_Test::CBoostLogger BoostLogger; BOOST_LOG_FUNCTION(); TA_Base_Test::CTestCase* pTestCase = new TA_Base_Test::CTestCase(); if (1 == g_runAsServer) { pTestCase->runTestCase_ForServer(); } else { pTestCase->runTestCase_ForClient(); } // //sleep { boost::mutex::scoped_lock lock(g_mutexMainRun); g_conditionMainRun.wait(lock); } delete pTestCase; pTestCase = NULL; return 0; }
int CSyncMarketDataForCFD::_SyncSingleBarInfoSynType( enSynType nSynType, const MarketData& nBarInfoFirst, const MarketData& nBarInfoSecond, LstBarInfoT& lstBarInfoFirst, LstBarInfoT& lstBarInfoSecond) { BOOST_LOG_FUNCTION(); int nFunRes = 0; switch (nSynType) { case SynType_EQUAL: nFunRes = _SyncSingleBarInfoSynTypeEqual(nSynType, nBarInfoFirst, nBarInfoSecond, lstBarInfoFirst, lstBarInfoSecond); break; case SynType_SMALL: nFunRes = _SyncSingleBarInfoSynTypeSmall(nSynType, nBarInfoFirst, nBarInfoSecond, lstBarInfoFirst, lstBarInfoSecond); break; case SynType_BIGGER: nFunRes = _SyncSingleBarInfoSynTypeSmall(nSynType, nBarInfoSecond, nBarInfoFirst, lstBarInfoSecond, lstBarInfoFirst); break; default: nFunRes = -1; break; } return nFunRes; }
CInstrumentBarInfo& CInstrumentBarInfo::operator=(const CInstrumentBarInfo& instrumentBarInfo ) { BOOST_LOG_FUNCTION(); m_nInterval = instrumentBarInfo.m_nInterval; m_BarInfo = instrumentBarInfo.m_BarInfo; return *this; }
CZmqREQServerThread::CZmqREQServerThread(void) { BOOST_LOG_FUNCTION(); m_toTerminate = false; m_nThreadJobState = JobState_Begin; }
void CConfigInfoHelper::logInfo() { BOOST_LOG_FUNCTION(); return; }
int CMarketDataFileAnalier::analierFile() { BOOST_LOG_FUNCTION(); int nFunRes = 0; int nLineIndex = 0; CAWorkTime* pTime = new CWorkTimeNoLock(); std::string filename = m_InstrumentBarInfoRequest.m_strCurrentAnalierFileName; std::ifstream priceFile(filename.c_str()); std::string strLogInfo = "get data from file"; pTime->workBegin(); LOG_INFO<<"begin AnalierFile: "<<m_InstrumentBarInfoRequest.m_strCurrentAnalierFileName; m_pMarketDataDispatcher->setInstrumentBarInfoRequest(m_InstrumentBarInfoRequest); while (!priceFile.eof()) { nLineIndex++; if ((1 == nLineIndex) || (nLineIndex % 500000) == 0) { LOG_INFO<<"TimeNow="<<pTime->getTimeNow()<<" "<<nLineIndex; //printf("getTimeNow=%s nLineIndex=%d\n", pTime->getTimeNow().c_str(), nLineIndex); } MarketData marketDataTmp(0); try { priceFile >> marketDataTmp; } catch (...) { LOG_ERROR<<"convert one line to MarketData ERROR!"; } //process price .... { m_pUtilityFun->logMarketDataInfo(strLogInfo, marketDataTmp); m_pMarketDataDispatcher->dispatcherMarketData(marketDataTmp); } } priceFile.close(); pTime->workEnd(); LOG_INFO<<"end AnalierFile: "<<m_InstrumentBarInfoRequest.m_strCurrentAnalierFileName <<" using="<<pTime->getWorkTime()<<" ms"; if (NULL != pTime) { delete pTime; pTime = NULL; } return nFunRes; }
CInstrumentBarInfoRequest& CInstrumentBarInfoRequest::operator=(const CInstrumentBarInfoRequest& instrumentBarInfoRequest ) { BOOST_LOG_FUNCTION(); m_strCurrentAnalierFileName = instrumentBarInfoRequest.m_strCurrentAnalierFileName; m_strHistoryMarketDataTotal = instrumentBarInfoRequest.m_strHistoryMarketDataTotal; m_strInstrumetBarInfoTotal = instrumentBarInfoRequest.m_strInstrumetBarInfoTotal; _AddBarTimeNormal(); return *this; }
int CMarketDataFileManager::setAnalieType(enAnalierType nAnalierType) { BOOST_LOG_FUNCTION(); int nFunRes = 0; m_nAnalierType = nAnalierType; return nFunRes; }
CSyncMarketDataForCFD::~CSyncMarketDataForCFD( void ) { BOOST_LOG_FUNCTION(); if (NULL != m_pUtilityFun) { delete m_pUtilityFun; m_pUtilityFun = NULL; } }
CConfigInfo::CConfigInfo(void) { BOOST_LOG_FUNCTION(); m_strConfigFileName.clear(); m_strConfigFileName = DEF_VALUE_strConfigFileName; loadDefaultConfigInfo(); }
CTOSReqEndTestFrame::CTOSReqEndTestFrame(void) { BOOST_LOG_FUNCTION(); m_nFrameType_SampleValue = C_TO_S_REQ_END_TEST; m_strReqInfo_SampleValue = "client want to end Test!"; setSampleValue(); }
int CZmqREQServerThread::_ProcessUserTerminate() { BOOST_LOG_FUNCTION(); int nFunRes = 0; m_toTerminate = true; m_nThreadJobState = JobState_End; return nFunRes; }
STOCAckBeginTestFrame::STOCAckBeginTestFrame(void) { BOOST_LOG_FUNCTION(); m_nFrameType_SampleValue = S_TO_C_ACK_BEGIN_TEST; m_strACKInfo_SampleValue = "Server is ready, you can begin to do Test Now!"; setSampleValue(); }
std::string CSqliteDbOper::_BuildSQLForInsertBarData(unsigned int nTableKey) { BOOST_LOG_FUNCTION(); std::ostringstream sreaamTmp; std::string strSQL; std::string strTableName; strTableName = _GetTableNameBar(nTableKey); /* INSERT INTO bar_data_15min ( Timestamp, Open, Close, High, Low, Volume ) VALUES ( :Timestamp_Value, :Open_Value, :Close_Value, :High_Value, :Low_Value, :Volume_Value ); */ sreaamTmp.str(""); sreaamTmp<<"INSERT INTO "<<strTableName <<" "<<"(" <<" "<<str_BarData_Column_Timestamp<<"," <<" "<<str_BarData_Column_Open<<"," <<" "<<str_BarData_Column_Close<<"," <<" "<<str_BarData_Column_High<<"," <<" "<<str_BarData_Column_Low<<"," <<" "<<str_BarData_Column_Volume <<" "<<")" <<" "<<"VALUES" <<" "<<"(" <<" "<<"?"<<"," <<" "<<"?"<<"," <<" "<<"?"<<"," <<" "<<"?"<<"," <<" "<<"?"<<"," <<" "<<"?" <<" "<<")"; strSQL = sreaamTmp.str(); return strSQL; }
QT_BEGIN_NAMESPACE CInstrumentBarInfo::CInstrumentBarInfo(int interval, Bar& barInfo) { BOOST_LOG_FUNCTION(); m_nInterval = interval; m_BarInfo = barInfo; }