int CTraderApi::_Init() { if (m_pApi == nullptr) { m_pApi = CTdxApi::CreateApi(); m_pApi->RegisterSpi(this); } Error_STRUCT* pErr = nullptr; m_pApi->LoadScript(m_ServerInfo.Address, true, false); m_pApi->Init(m_ServerInfo.ExtInfoChar128, &pErr); if (pErr) { RspUserLoginField* pField = (RspUserLoginField*)m_msgQueue->new_block(sizeof(RspUserLoginField)); pField->RawErrorID = pErr->ErrCode; strcpy(pField->Text, pErr->ErrInfo); m_msgQueue->Input_NoCopy(ResponseType::ResponseType_OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Disconnected, 0, pField, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0); } else { m_msgQueue->Input_NoCopy(ResponseType::ResponseType_OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Initialized, 0, nullptr, 0, nullptr, 0, nullptr, 0); ReqUserLogin(); } DeleteError(pErr); return 0; }
int CTraderApi::_Init() { m_msgQueue->Input_NoCopy(ResponseType::ResponseType_OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Initialized, 0, nullptr, 0, nullptr, 0, nullptr, 0); m_pApi = XTP::API::TraderApi::CreateTraderApi(m_UserInfo.ExtInfoInt32, m_szPath.c_str()); if (m_pApi) { m_pApi->RegisterSpi(this); // 初始化连接属性 m_pApi->SetHeartBeatInterval(15); m_pApi->SubscribePublicTopic(XTP_TERT_QUICK); // 设置XTP key,在XTP申请开户时,由xtp人员提供 m_pApi->SetSoftwareKey(m_UserInfo.ExtInfoChar64); // XTP没有单独的连接前置接口,所以这里模拟前置机连接成功消息 m_msgQueue->Input_NoCopy(ResponseType::ResponseType_OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Connecting, 0, nullptr, 0, nullptr, 0, nullptr, 0); m_msgQueue->Input_NoCopy(ResponseType::ResponseType_OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0); //连接成功后自动请求登录 ReqUserLogin(); } return 0; }
void CtpMdSpi::OnFrontConnected() { CXTraderApp* pApp = (CXTraderApp*)AfxGetApp(); if (g_pCWnd) { bRecconnect = TRUE; CXTraderDlg* pDlg = (CXTraderDlg*)g_pCWnd; //pDlg->SetStatusTxt(_T("MD√"),0); ReqUserLogin(pApp->m_sBROKER_ID);//,pApp->m_sINVESTOR_ID,pApp->m_sPASSWORD); DWORD dwRet = WaitForSingleObject(g_hEvent,WAIT_MS); if (dwRet==WAIT_OBJECT_0) { pDlg->SetTipTxt(_T("行情在线"),IDS_MD_TIPS); pDlg->SetPaneTxtColor(0,RED); ResetEvent(g_hEvent); } else { return; } //int iLen = pDlg->m_szInst.GetLength(); char szInst[MAX_PATH]; uni2ansi(CP_ACP,(LPTSTR)(LPCTSTR)pDlg->m_szInst,szInst); SubscribeMarketData(szInst); dwRet = WaitForSingleObject(g_hEvent,WAIT_MS); if (dwRet==WAIT_OBJECT_0) { ResetEvent(g_hEvent); } //Sleep(100); bMdSignal = TRUE; } else { ReqUserLogin(pApp->m_sBROKER_ID); } //if (g_bOnce)SetEvent(g_hEvent); }
void CTraderApi::OnFrontConnected() { WriteLog("OnFrontConnected"); m_status = E_connected; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); ReqUserLogin(); }
//网络故障恢复正常后 自动重连 void CtpTraderSpi::OnFrontConnected() { CXTraderApp* pApp = (CXTraderApp*)AfxGetApp(); if (g_pCWnd) { m_bReconnect = TRUE; CXTraderDlg* pDlg = (CXTraderDlg*)g_pCWnd; //pDlg->SetStatusTxt( _T("TD√"),1); ReqUserLogin(pApp->m_sBROKER_ID,pApp->m_sINVESTOR_ID,pApp->m_sPASSWORD); DWORD dwRet = WaitForSingleObject(g_hEvent,WAIT_MS); if (dwRet==WAIT_OBJECT_0) { ResetEvent(g_hEvent); pDlg->m_pCliInfo->FrtID = m_ifrontId; pDlg->m_pCliInfo->SesID = m_isessionId; pDlg->SetTipTxt(_T("交易在线"),IDS_TRADE_TIPS); pDlg->SetPaneTxtColor(1,RED); SYSTEMTIME curTime; ::GetLocalTime(&curTime); CString szT; szT.Format(_T("%02d:%02d:%02d CTP重登录成功"), curTime.wHour, curTime.wMinute, curTime.wSecond); pDlg->SetStatusTxt(szT,2); } else return; } else { ReqUserLogin(pApp->m_sBROKER_ID,pApp->m_sINVESTOR_ID,pApp->m_sPASSWORD); } //if (g_bOnce)SetEvent(g_hEvent); }
void CTraderApi::OnFrontConnected() { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0); //连接成功后自动请求认证或登录 //if(m_szAuthCode.length()>0 // &&m_szUserProductInfo.length()>0) //{ // //填了认证码就先认证 // ReqAuthenticate(); //} //else { ReqUserLogin(); } }
void CTraderApi::OnFrontConnected() { m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0); ////连接成功后自动请求认证或登录 //if (strlen(m_ServerInfo.AuthCode)>0 // && strlen(m_ServerInfo.UserProductInfo)>0) //{ // //填了认证码就先认证 // ReqAuthenticate(); //} //else //{ ReqUserLogin(); //} }
void CTraderApi::Connect(const string& szPath, ServerInfoField* pServerInfo, UserInfoField* pUserInfo) { m_szPath = szPath; memcpy(&m_ServerInfo, pServerInfo, sizeof(ServerInfoField)); memcpy(&m_UserInfo, pUserInfo, sizeof(UserInfoField)); //char *pszPath = new char[szPath.length() + 1024]; //srand((unsigned int)time(nullptr)); //sprintf(pszPath, "%s/%s/%s/Td/%d/", szPath.c_str(), m_ServerInfo.BrokerID, m_UserInfo.UserID, rand()); //makedirs(pszPath); m_pApi = CGoldTradeApi::CreateGoldTradeApi(); //delete[] pszPath; XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Initialized, 0, nullptr, 0, nullptr, 0, nullptr, 0); if (m_pApi) { m_pApi->RegisterSpi(this); //添加地址 size_t len = strlen(m_ServerInfo.Address) + 1; char* buf = new char[len]; strncpy(buf, m_ServerInfo.Address, len); char* token = strtok(buf, _QUANTBOX_SEPS_); while(token) { if (strlen(token)>0) { m_pApi->RegisterFront(token); } token = strtok(nullptr, _QUANTBOX_SEPS_); } delete[] buf; //m_pApi->SubscribePublicTopic((THOST_TE_RESUME_TYPE)pServerInfo->Resume); //m_pApi->SubscribePrivateTopic((THOST_TE_RESUME_TYPE)pServerInfo->Resume); //初始化连接 int ret = m_pApi->Init(); XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connecting, 0, nullptr, 0, nullptr, 0, nullptr, 0); ReqUserLogin(); } }
void CTraderApi::OnFrontConnected() { m_status = E_connected; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); //连接成功后自动请求认证或登录 if(m_szAuthCode.length()>0 &&m_szUserProductInfo.length()>0) { //填了认证码就先认证 ReqAuthenticate(); } else { ReqUserLogin(); } }
void CTraderApi::OnRspFetchAuthRandCode(CSecurityFtdcAuthRandCodeField *pAuthRandCode, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { RspUserLoginField* pField = (RspUserLoginField*)m_msgQueue->new_block(sizeof(RspUserLoginField)); if (!IsErrorRspInfo(pRspInfo) && pAuthRandCode) { m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Authorized, 0, pField, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0); ReqUserLogin(pAuthRandCode->RandCode); } else { pField->RawErrorID = pRspInfo->ErrorID; strncpy(pField->Text, pRspInfo->ErrorMsg, sizeof(Char256Type)); m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::ConnectionStatus_Disconnected, 0, pField, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0); } }
void CTraderApi::OnRspAuthenticate(CThostFtdcRspAuthenticateField *pRspAuthenticateField, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { if (!IsErrorRspInfo(pRspInfo) &&pRspAuthenticateField) { m_status = E_authed; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); ReqUserLogin(); } else { m_status = E_connected; if(m_msgQueue) m_msgQueue->Input_OnDisconnect(this,pRspInfo,E_authing); } if (bIsLast) ReleaseRequestMapBuf(nRequestID); }
int CTraderApi::_Init() { m_pApi = CGoldTradeApi::CreateGoldTradeApi(); m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Initialized, 0, nullptr, 0, nullptr, 0, nullptr, 0); if (m_pApi) { m_pApi->RegisterSpi(this); //添加地址 size_t len = strlen(m_ServerInfo.Address) + 1; char* buf = new char[len]; strncpy(buf, m_ServerInfo.Address, len); char* token = strtok(buf, _QUANTBOX_SEPS_); while (token) { if (strlen(token)>0) { m_pApi->RegisterFront(token); } token = strtok(nullptr, _QUANTBOX_SEPS_); } delete[] buf; //m_pApi->SubscribePublicTopic((THOST_TE_RESUME_TYPE)pServerInfo->Resume); //m_pApi->SubscribePrivateTopic((THOST_TE_RESUME_TYPE)pServerInfo->Resume); //初始化连接 int ret = m_pApi->Init(); m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connecting, 0, nullptr, 0, nullptr, 0, nullptr, 0); // 这地方的写法怎么是这样的?好像是没有回报 ReqUserLogin(); } return 0; }
void CTraderSpi::OnFrontConnected() { std::cout << "--->>> " << "OnFrontConnected" << std::endl; ///用户登录请求 ReqUserLogin(); }
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。 void CtpQtSpi::OnFrontConnected() { m_connStatus = CTP_CONNECTED; ReqUserLogin(); }
void CMdSpi::OnFrontConnected() { LOG("MD Front Connect Successfully!"); ReqUserLogin(); }
void CTraderApi::OnFrontConnected() { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0); ReqUserLogin(); }
void CCTPAPI::OnFrontConnected(){ ReqUserLogin(); }
void CTraderApi::OnFrontConnected() { m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, m_pClass, ConnectionStatus::Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0); ReqUserLogin(); }
void FollowTraderSpi::OnFrontConnected() { qDebug() << "<<<---" << "OnFrontConnected:" << QThread::currentThreadId() <<endl; ///用户登录请求 ReqUserLogin(); }