Exemplo n.º 1
0
int InstrItem::RemoveItem()
{
	RemoveInstr();
	return 1;
}
Exemplo n.º 2
0
int CUstpFtdcMduserApi::HandleUnsubmarket()
{
	int ret = 0;
	char sendBuf[BUFSIZE] = {0};
	char rcvBuf[BUFSIZE] = {0};
	MsgHead stHead; 				
	int iSendLen = 0;	
	int iExpectRcvLen = 0;
	char * pSendBuf = NULL;
	char * pRcvBuf = NULL;
	MsgHead *pMsg = NULL;
	RspUnsubMarketFromATF stRsp;
	RspUnsubMarketFromATF *pRsp = NULL;

	//no a instrument has been subscribed
	if(NULL == m_pInstrSubSucc)
	{
		g_log.error("No an instrument subscribed !\n");
		strcpy(stRsp.specificInstrument.InstrumentID,m_acInstrUnsubReq);
		stRsp.rspInfo.ErrorID = 16;
		pRsp = &stRsp;
	}
	else
	{
		SubscribeInstrument *pTmp = m_pInstrSubSucc;
		while(NULL != pTmp)
		{
			//the instrument unsubscribed has been subscribed
			if(0 == strcasecmp(pTmp->instrument,m_acInstrUnsubReq))
			{
				//send msg to ATF
				ReqUnsubMarketToATF unsubInfo;
				strcpy(unsubInfo.instr,m_acInstrUnsubReq);
									
				stHead.iMsgID = htons(MSGID_C2S_QUOTE_REQ_UNSUBSCRIBE);
				stHead.iMsgBodyLen = htons(sizeof(unsubInfo));
				
				pSendBuf = sendBuf;
				memcpy(pSendBuf , &stHead, sizeof(stHead));
				memcpy(pSendBuf+sizeof(stHead),&unsubInfo,sizeof(unsubInfo));
				iSendLen = sizeof(stHead) + sizeof(unsubInfo);
									
				ret = TcpSendData(m_fdConnQuoteSvr,(char*)pSendBuf,iSendLen);
				if(ret != iSendLen)
				{
					g_log.error("[STATUS_QUOTE_REQ_UNSUBSCRIBE]TCP send error,expect %dB,actual %dB.\n",iSendLen,ret);
					return ATF_FAIL;
				}
				g_log.debug("[STATUS_QUOTE_REQ_UNSUBSCRIBE]TCP send %dB \n",ret);


				//rcv msg from ATF						
				iExpectRcvLen = sizeof(MsgHead) + sizeof(RspUnsubMarketFromATF);
				pRcvBuf = rcvBuf;
				ret = TcpRecvData(m_fdConnQuoteSvr,pRcvBuf,iExpectRcvLen);
				if(ret != iExpectRcvLen)
				{					
					g_log.error("[STATUS_QUOTE_REQ_UNSUBSCRIBE]TCP rcv error,expect %dB,actual %dB.\n",iExpectRcvLen,ret);
					return ATF_FAIL;
				}
				g_log.debug("[STATUS_QUOTE_REQ_UNSUBSCRIBE]TCP rcv %dB \n",iExpectRcvLen);
									
				pMsg = (MsgHead *)pRcvBuf;		
				if(MSGID_S2C_QUOTE_RSP_UNSUBSCRIBE == ntohs(pMsg->iMsgID))
				{
					pRsp = (RspUnsubMarketFromATF *)(pRcvBuf + sizeof(MsgHead)); 	

					if(0 == pRsp->rspInfo.ErrorID)
					{
						//remove the instrument unsubscribed from m_pInstrSubSucc
						RemoveInstr(&pRsp->specificInstrument);
					}
				}
				else
				{
					g_log.error("[STATUS_QUOTE_REQ_UNSUBSCRIBE]TCP rcv error,expect %dB,actual %dB.\n",MSGID_S2C_QUOTE_RSP_UNSUBSCRIBE,ntohs(pMsg->iMsgID));

					strcpy(stRsp.specificInstrument.InstrumentID,m_acInstrUnsubReq);
					stRsp.rspInfo.ErrorID = 16;
					pRsp = &stRsp;
				}

				break;
			}
			else
			{
				pTmp = pTmp->pNext;
			}
		}

		//the instrument unsubscribed had not been found in the subscribe list
		if(NULL == pTmp)  
		{
			strcpy(stRsp.specificInstrument.InstrumentID,m_acInstrUnsubReq);
			stRsp.rspInfo.ErrorID = 16;
			pRsp = &stRsp;
			
			g_log.error("the instrument unsubscribed had not been found in the subscribe list !\n");
		}

	}

	//PrintInstr();

	//return rsp to trader3.0
	m_FtdcMdSpi_instance->OnRspUnSubMarketData(&pRsp->specificInstrument,&pRsp->rspInfo,m_iRequestID,true);

	return ATF_SUCC;
}