QList<Position*> AccountTradeInfo::GetPositions() const { QMutexLocker oLocker(&m_mLock); QList<Position*> lPositions; lPositions.append(m_lPositions); return lPositions; }
void GPageLoadRequestManager::ReceiveRequest(GUpdateURLCurrentPageRequest* pReq) { LOG_LEVEL4("ReceiveRequest(GUpdateURLCurrentPageRequest)"); QMutexLocker oLocker(&m_qmInternalMutex); if( !m_qmSessions.contains(pReq->GetSessionId()) ) { LOG_LEVEL1("Invalid session id. Discarding request."); delete pReq; return; } pReq->SetRequestId(GenerateRequestId()); pReq->SetNotification(false); if( m_qlsReqs.isEmpty() ) { ProcessRequest(pReq); } else { m_qlsReqs << pReq; LOG_LEVEL4(QString("Quantity of pending requests(") + QString::number(m_qlsReqs.count()) + ")."); } }
QList<Transaction*> AccountTradeInfo::CreateTransaction(Order const*pOrder,QDateTime const& oTimestamp,size_t nQuantity,double dPrice) { QMutexLocker oLocker(&m_mLock); OrderOperator oOperator; QList<Transaction*> lTransactions; auto iPos = m_lPositions.begin(); while(iPos != m_lPositions.begin()) { Position *pPosition = *iPos; Transaction* pTransaction = oOperator.Close(pPosition,pOrder,oTimestamp,nQuantity,dPrice); lTransactions.append(pTransaction); if(pPosition->GetQuantity() == 0) { iPos = m_lPositions.erase(iPos); RemovePosition(pPosition); } else { break; } } m_lTradeDayTransactions.append(lTransactions); UpdateOrder(const_cast<Order*>(pOrder)); SaveTransaction(lTransactions); return lTransactions; }
QList<Transaction*> AccountTradeInfo::GetTradeDayTransactions() const { QMutexLocker oLocker(&m_mLock); QList<Transaction*> lTransactions; lTransactions.append(m_lTradeDayTransactions); return lTransactions; }
bool CTPOrderProcessor::Initialize() { m_nRequestNumber = 1; strcpy(m_oLoginInfo.BrokerID,m_pAccount->GetBroker()->GetId().toStdString().c_str()); strcpy(m_oLoginInfo.UserID,m_pAccount->GetID().toStdString().c_str()); strcpy(m_oLoginInfo.Password,m_pAccount->GetPassword().toStdString().c_str()); m_pTradeApi = CThostFtdcTraderApi::CreateFtdcTraderApi(); m_pTradeApi->SubscribePrivateTopic(THOST_TERT_QUICK); m_pTradeApi->SubscribePublicTopic(THOST_TERT_QUICK); m_pTradeApi->RegisterSpi(this); QStringList lTradeUrls = m_pAccount->GetBroker()->GetTradeUrl(); for(auto iPos = lTradeUrls.begin(); iPos != lTradeUrls.end();iPos++) { QString strUrl = *iPos; m_pTradeApi->RegisterFront(const_cast<char*>(strUrl.toStdString().c_str())); } strcpy(m_oSettlementInfoConfirm.BrokerID,m_pAccount->GetBroker()->GetId().toStdString().c_str()); strcpy(m_oSettlementInfoConfirm.InvestorID,m_pAccount->GetID().toStdString().c_str()); m_bConnected = false; m_pTradeApi->Init(); std::unique_lock<std::mutex> oLocker(m_lLock); auto oWaitCondition = [&]()->bool { return m_bConnected == true; }; if(m_cWaitCondition.wait_for(oLocker,std::chrono::seconds(30),oWaitCondition)) { return true; } m_pTradeApi->Release(); m_pTradeApi = nullptr; return false; }
QList<Order*> AccountTradeInfo::GetRunningOrders() const { QMutexLocker oLocker(&m_mLock); QList<Order*> lOrders; lOrders.append(m_lRunningOrders); return lOrders; }
void CTPOrderProcessor::Cancel(Order const* pOrder) { std::unique_lock<std::mutex> oLocker(m_lLock); CTPOrderOperation oOperation; oOperation.eType = ootCancel; oOperation.pOrder = pOrder; m_qOrders.push_back(oOperation); m_cWaitCondition.notify_one(); }
Position* AccountTradeInfo::CreatePosition(Order const*pOrder,QDateTime const& oTimestamp,size_t nQuantity,double dPrice) { QMutexLocker oLocker(&m_mLock); OrderOperator oOperator; Position *pPosition = oOperator.Open(pOrder,oTimestamp,nQuantity,dPrice); UpdateOrder(const_cast<Order*>(pOrder)); SavePosition(pPosition); m_lPositions.push_back(pPosition); return pPosition; }
double AccountTradeInfo::GetTradeDayProfit() const { QMutexLocker oLocker(&m_mLock); double dProfit = 0; for(auto iPos = m_lPositions.begin() ; iPos != m_lPositions.end() ; iPos++) { Position *pPosition = *iPos; dProfit = pPosition->GetTradeDayProfit(); } return dProfit; }
// // Delete watcher // void AcceptLoopContext::DeleteWatcher(NetworkEventWatcher * pWatcher) { this -> clients.DeleteWatcher(pWatcher); CRITICAL { MutexLocker oLocker(this -> mutex); if (this -> main_context.global_context.shutdown_type != GlobalContext::NONE && clients.Size() == 0) { thread_loop.UnLoop(); } } }
QList<Order*> AccountTradeInfo::GetOrders() { QMutexLocker oLocker(&m_mLock); QList<Order*> lOrders ; lOrders.append(m_lTradeDayOrders); if(!m_bOrderLoaded) { LoadOrders(); m_bOrderLoaded = true; } lOrders.append(m_lOrders); return lOrders; }
QList<Transaction*> AccountTradeInfo::GetTransactions() { QMutexLocker oLocker(&m_mLock); QList<Transaction*> lTransactions; lTransactions.append(m_lTradeDayTransactions); if(!m_bTransactionLoaded) { LoadTransactions(); m_bTransactionLoaded = true; } lTransactions.append(m_lTransactions); return lTransactions; }
size_t AccountTradeInfo::GetPositionQuantity(Direction eDirection,HedgeFlag eHedgeFlag) const { QMutexLocker oLocker(&m_mLock); size_t nQuantity = 0; for(auto iPos = m_lPositions.begin() ; iPos != m_lPositions.end() ; iPos++) { Position *pPosition = *iPos; if(pPosition->GetDirection() == eDirection && pPosition->GetHedgeFlag() == eHedgeFlag) { nQuantity += pPosition->GetQuantity(); } } return nQuantity; }
unsigned int GPageLoadRequestManager::Subscribe(QString sName, bool bIsView) { LOG_LEVEL4("Subscribe()"); QMutexLocker oLocker(&m_qmInternalMutex); GPageLoadRequestManagerSession oSession( (bIsView)?(GenerateSessionId()):(0), sName, bIsView); m_qmSessions[oSession.GetId()] = oSession; LOG_LEVEL3(QString("Subscribe(") + GetSessionName(oSession.GetId()) + ")."); return oSession.GetId(); }
double AccountTradeInfo::GetFrezonMargin() const { double dFrezonMargin = 0; QMutexLocker oLocker(&m_mLock); for(auto iPos = m_lRunningOrders.begin() ; iPos != m_lRunningOrders.end() ; iPos++) { Order *pOrder = *iPos; dFrezonMargin += pOrder->GetFrezonMargin(); } for(auto iPos = m_lPositions.begin() ; iPos != m_lPositions.end() ; iPos++) { Position *pPosition = *iPos; dFrezonMargin += pPosition->GetFrezonMargin(); } return dFrezonMargin; }
void GPageLoadRequestManager::Notify(GLoadersManagerRequestNotify &oNotify) throw(GException) { LOG_LEVEL4("Notify()"); QMutexLocker oLocker(&m_qmInternalMutex); GAbsPageLoadRequest* pRequest(0); for( int i = 0; i < m_qlsReqs.size(); ++i ) { if( m_qlsReqs.at(i)->GetRequestId() == oNotify.GetRequest()->GetRequestId() ) { pRequest = oNotify.GetRequest(); m_qlsReqs.removeAt(i); break; } } if( pRequest != 0 ) { QString sResult("Timeout"); if( oNotify.GetNofifyType() == GLoadersManagerRequestNotify::eContentLoadComplete ) { m_pMainView->setPage(oNotify.GetWebPage()); sResult = "Completed"; SetAsActive(oNotify.GetLoadersManagerId()); } static QString const strTemp("RequestId(%1), has been completed with result (%2) for (%3)."); LOG_LEVEL4(QString(strTemp) . arg(pRequest->GetRequestId()) . arg(sResult) . arg(GetSessionName(pRequest->GetSessionId()))); if( pRequest->IsSynchronize() ) { GAbsView::SignalSynchronize( (sResult=="Completed")?(true):(false) ); } delete pRequest; ProcessNewRequest(); return; } throw(GException("Cannot found the request in the internal queue.")); }
void CTPOrderProcessor::operator()() { while(true) { if(m_bStop) { return ; } std::unique_lock<std::mutex> oLocker(m_lLock); while(m_qOrders.isEmpty()) { if(m_bStop) { return; } m_cWaitCondition.wait(oLocker); } CTPOrderOperation oOperation = m_qOrders.front(); m_qOrders.pop_front(); switch (oOperation.eType) { case ootSubmit: { CTPOrder *pCTPOrder = new CTPOrder(oOperation.pOrder,oOperation.pOrderListener); CThostFtdcInputOrderField const& oInputOrder = pCTPOrder->GetInputOrder(); m_hOrders.insert(QString(oInputOrder.OrderRef),pCTPOrder); m_pTradeApi->ReqOrderInsert(const_cast<CThostFtdcInputOrderField*>(&oInputOrder),m_nRequestNumber++); pCTPOrder->GetOrderListener()->OnSubmited(oOperation.pOrder); } break; case ootCancel: { QString strOrderRef = oOperation.pOrder->GetId(); ; CTPOrder *pCTPOrder = m_hOrders[strOrderRef]; if(pCTPOrder) { CThostFtdcInputOrderActionField const& oInputOrder = pCTPOrder->GetInputOrderAction(); m_pTradeApi->ReqOrderAction(const_cast<CThostFtdcInputOrderActionField*>(&oInputOrder),m_nRequestNumber++); pCTPOrder->GetOrderListener()->OnCancelling(oOperation.pOrder); } } break; default: break; } } }
void AccountTradeInfo::UpdateOrderStatus(Order const*pOrder,OrderStatus eStatus) { QMutexLocker oLocker(&m_mLock); OrderOperator oOperator; oOperator.UpdateOrderStatus(const_cast<Order*>(pOrder),eStatus); UpdateOrder(const_cast<Order*>(pOrder)); switch (eStatus) { case osCancelled: case osCancelledAndPartedTraded: case osError: { m_lRunningOrders.removeOne(const_cast<Order*>(pOrder)); } break; default: break; } }
QSharedPointer<GURLModelSingleton> GURLModelSingleton::GetInstance() throw(GException) { LOG_LEVEL3( "GetInstance()" ); QMutexLocker oLocker(&GURLModelSingleton::m_mutex); if( m_pGURLModelSingleton.isNull() ) { m_pGURLModelSingleton = QSharedPointer<GURLModelSingleton>(new GURLModelSingleton()); } if( m_pGURLModelSingleton.isNull() ) { throw( GException("GURLModelSingleton::GetInstance() made a NULL pointer.") ); } return m_pGURLModelSingleton; }
void GGstLaunchMediaManager::SynchroStopMedia() { LOG_LEVEL4("SynchroStopMedia()"); if (m_iVideoProcessid) { QMutexLocker oLocker(&GGstLaunchMediaManager::_mtxSynchMutexVideoTermination); emit SignalSynchroStopMedia(); GGstLaunchMediaManager::_cndSynchConditionalVideoTermination.wait(&GGstLaunchMediaManager::_mtxSynchMutexVideoTermination); } else { LOG_LEVEL4("No Video Process running currently."); } }
double AccountTradeInfo::GetTradeDayCommission() const { QMutexLocker oLocker(&m_mLock); double dCommission = 0; for(auto iPos = m_lPositions.begin() ; iPos != m_lPositions.end() ; iPos++) { Position *pPosition = *iPos; if(pPosition->GetTimestamp().date() == m_pInstrument->GetTradeDay()) { dCommission += pPosition->GetCommission(); } } for(auto iPos = m_lTradeDayTransactions.begin() ; iPos != m_lTradeDayTransactions.end() ; iPos++) { Transaction *pTransaction = *iPos; dCommission +=pTransaction->GetOpenCommission(); dCommission += pTransaction->GetCloseCommission(); } return dCommission; }
Order* AccountTradeInfo::CreateOrder(Direction eDirection,Operation eOperation, HedgeFlag eHedgeFlag,PriceMode ePriceMode,size_t nQuantity,double dQuote) { QMutexLocker oLocker(&m_mLock); Order *pOrder = nullptr; QDateTime oTradeTime = QDateTime::currentDateTime(); if(eOperation == opOpen) { pOrder = new Order(m_pAccount->GenOrderID(),m_pAccount,m_pInstrument,m_pPositionCost,oTradeTime.date(),oTradeTime.time(),eOperation, eDirection,eHedgeFlag,ePriceMode,nQuantity,dQuote,osNew); } else { pOrder = new Order(m_pAccount->GenOrderID(),m_pAccount,m_pInstrument,m_pPositionCost,oTradeTime.date(),oTradeTime.time(),eOperation, eDirection,eHedgeFlag,ePriceMode,nQuantity,dQuote,osNew); } SaveOrder(pOrder); m_lRunningOrders.push_back(pOrder); m_lTradeDayOrders.push_back(pOrder); return pOrder; }
QSharedPointer<GPageLoadRequestManager> GPageLoadRequestManager::GetInstance() throw(GException) { LOG_LEVEL4("GetInstance()"); QMutexLocker oLocker(&GPageLoadRequestManager::m_mutex); if( m_pGPageLoadRequestManager.isNull() ) { m_pGPageLoadRequestManager = QSharedPointer<GPageLoadRequestManager>(new GPageLoadRequestManager()); if (!m_pGPageLoadRequestManager.isNull()) { m_pGPageLoadRequestManager->Init(); } } if( m_pGPageLoadRequestManager.isNull() ) { throw(GException("GPageLoadRequestManager::GetInstance() made a NULL pointer.")); } return m_pGPageLoadRequestManager; }
QSharedPointer<GGDIView> GGDIView::GetInstance() throw(GException) { LOG_LEVEL4("GetInstance()"); QMutexLocker oLocker(&GGDIView::m_mutex); if( m_pGGDIView.isNull() ) { m_pGGDIView = QSharedPointer<GGDIView>(new GGDIView()); if( !m_pGGDIView.isNull() ) { m_pGGDIView->Init(); } } if( m_pGGDIView.isNull() ) { throw(GException("GGDIView::GetInstance() made a NULL pointer.")); } return m_pGGDIView; }
QList<Order*> AccountTradeInfo::GetOrders(QDate const& oTradeDay) { QMutexLocker oLocker(&m_mLock); if(oTradeDay == m_pInstrument->GetTradeDay()) { return m_lTradeDayOrders; } QList<Order*> lOrders; if(!m_bOrderLoaded) { m_bOrderLoaded = true; LoadOrders(); } for(int nCount = 0 ; nCount < m_lOrders.size() ; nCount) { Order *pOrder = m_lOrders[nCount]; if(pOrder->GetTradeDay() == oTradeDay) { lOrders.append(pOrder); } } return lOrders; }
QList<Transaction*> AccountTradeInfo::GetTransactions(QDate const& oTradeDay) { QMutexLocker oLocker(&m_mLock); QList<Transaction*> lTransactions; if(m_pInstrument->GetTradeDay() == oTradeDay) { lTransactions.append(m_lTradeDayTransactions); return lTransactions; } if(!m_bTransactionLoaded) { LoadTransactions(); m_bTransactionLoaded = true; } for(auto iPos = m_lTransactions.begin() ; iPos != m_lTransactions.end() ; iPos++) { Transaction *pTransaction = *iPos; if(pTransaction->GetOpenTime().date() != oTradeDay) { lTransactions.append(pTransaction); } } return lTransactions; }