void CTraderApi::ReqOrderAction(CThostFtdcOrderField *pOrder) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_InputOrderActionField); if (NULL == pRequest) return; CThostFtdcInputOrderActionField& body = pRequest->InputOrderActionField; ///经纪公司代码 strncpy(body.BrokerID, pOrder->BrokerID,sizeof(TThostFtdcBrokerIDType)); ///投资者代码 strncpy(body.InvestorID, pOrder->InvestorID,sizeof(TThostFtdcInvestorIDType)); ///报单引用 strncpy(body.OrderRef, pOrder->OrderRef,sizeof(TThostFtdcOrderRefType)); ///前置编号 body.FrontID = pOrder->FrontID; ///会话编号 body.SessionID = pOrder->SessionID; ///交易所代码 strncpy(body.ExchangeID,pOrder->ExchangeID,sizeof(TThostFtdcExchangeIDType)); ///报单编号 strncpy(body.OrderSysID,pOrder->OrderSysID,sizeof(TThostFtdcOrderSysIDType)); ///操作标志 body.ActionFlag = THOST_FTDC_AF_Delete; ///合约代码 strncpy(body.InstrumentID, pOrder->InstrumentID,sizeof(TThostFtdcInstrumentIDType)); long lRequest = InterlockedIncrement(&m_lRequestID); m_pApi->ReqOrderAction(&pRequest->InputOrderActionField,lRequest); delete pRequest; }
void CTraderApi::ReqQuoteCancelOrder( const string& szInstrumentId, DFITCLocalOrderIDType localOrderID, DFITCSPDOrderIDType spdOrderID) { WriteLog("ReqQuoteCancelOrder localOrderID=%d spdOrderID =%d szInstrumentId=%s ",localOrderID , spdOrderID, szInstrumentId.c_str()); if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QuoteCancelOrderField); if (NULL == pRequest) return; DFITCCancelOrderField* body = (DFITCCancelOrderField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); // 合约 strncpy(body->instrumentID,szInstrumentId.c_str(),sizeof(DFITCInstrumentIDType)); body->localOrderID = localOrderID; body->spdOrderID = spdOrderID; m_pApi->ReqQuoteCancelOrder(body); delete pRequest->pBuf; delete pRequest;//用完后直接删除 }
int CTraderApi::ReqOrderAction(CSecurityFtdcOrderField *pOrder) { if (nullptr == m_pApi) return 0; SRequest* pRequest = MakeRequestBuf(E_InputOrderActionField); if (nullptr == pRequest) return 0; CSecurityFtdcInputOrderActionField& body = pRequest->InputOrderActionField; ///经纪公司代码 strncpy(body.BrokerID, pOrder->BrokerID,sizeof(TSecurityFtdcBrokerIDType)); ///投资者代码 strncpy(body.InvestorID, pOrder->InvestorID,sizeof(TSecurityFtdcInvestorIDType)); ///报单引用 strncpy(body.OrderRef, pOrder->OrderRef,sizeof(TSecurityFtdcOrderRefType)); ///前置编号 body.FrontID = pOrder->FrontID; ///会话编号 body.SessionID = pOrder->SessionID; ///交易所代码 strncpy(body.ExchangeID,pOrder->ExchangeID,sizeof(TSecurityFtdcExchangeIDType)); ///报单编号 //strncpy(body.OrderSysID,pOrder->OrderSysID,sizeof(TSecurityFtdcOrderSysIDType)); ///操作标志 body.ActionFlag = SECURITY_FTDC_AF_Delete; ///合约代码 strncpy(body.InstrumentID, pOrder->InstrumentID,sizeof(TSecurityFtdcInstrumentIDType)); int nRet = m_pApi->ReqOrderAction(&pRequest->InputOrderActionField, ++m_lRequestID); delete pRequest; return nRet; }
int CTraderApi::ReqQuoteAction(CThostFtdcQuoteField *pQuote) { if (NULL == m_pApi) return 0; SRequest* pRequest = MakeRequestBuf(E_InputQuoteActionField); if (NULL == pRequest) return 0; CThostFtdcInputQuoteActionField& body = pRequest->InputQuoteActionField; ///经纪公司代码 strncpy(body.BrokerID, pQuote->BrokerID, sizeof(TThostFtdcBrokerIDType)); ///投资者代码 strncpy(body.InvestorID, pQuote->InvestorID, sizeof(TThostFtdcInvestorIDType)); ///报单引用 strncpy(body.QuoteRef, pQuote->QuoteRef, sizeof(TThostFtdcOrderRefType)); ///前置编号 body.FrontID = pQuote->FrontID; ///会话编号 body.SessionID = pQuote->SessionID; ///交易所代码 strncpy(body.ExchangeID, pQuote->ExchangeID, sizeof(TThostFtdcExchangeIDType)); ///报单编号 strncpy(body.QuoteSysID, pQuote->QuoteSysID, sizeof(TThostFtdcOrderSysIDType)); ///操作标志 body.ActionFlag = THOST_FTDC_AF_Delete; ///合约代码 strncpy(body.InstrumentID, pQuote->InstrumentID, sizeof(TThostFtdcInstrumentIDType)); int nRet = m_pApi->ReqQuoteAction(&pRequest->InputQuoteActionField, ++m_lRequestID); delete pRequest; return nRet; }
void CTraderApi::ReqQuoteSubscribe() { if (NULL == m_pApi) return; WriteLog("ReqQuoteSubscribe"); SRequest* pRequest = MakeRequestBuf(E_QuoteSubscribeField); if (NULL == pRequest) return; DFITCQuoteSubscribeField * body = (DFITCQuoteSubscribeField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrument(const string& szInstrumentId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentField); if (NULL == pRequest) return; CThostFtdcQryInstrumentField& body = pRequest->QryInstrumentField; strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TThostFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryCustomerCapital() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_CapitalField); if (NULL == pRequest) return; DFITCCapitalField* body = (DFITCCapitalField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryDepthMarketData(const string& szInstrumentId) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryDepthMarketDataField); if (nullptr == pRequest) return; CSecurityFtdcQryDepthMarketDataField& body = pRequest->QryDepthMarketDataField; strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TSecurityFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryOrder() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryOrderField); if (nullptr == pRequest) return; CSecurityFtdcQryOrderField& body = pRequest->QryOrderField; strncpy(body.BrokerID, m_RspUserLogin.BrokerID, sizeof(TSecurityFtdcBrokerIDType)); strncpy(body.InvestorID, m_RspUserLogin.UserID, sizeof(TSecurityFtdcInvestorIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrument(const string& szInstrumentId, const string& szExchange) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentField); if (nullptr == pRequest) return; CSecurityFtdcQryInstrumentField& body = pRequest->QryInstrumentField; strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TSecurityFtdcInstrumentIDType)); strncpy(body.ExchangeID, szExchange.c_str(), sizeof(TSecurityFtdcExchangeIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryMatchInfo(DFITCInstrumentTypeType instrumentType) { if (NULL == m_pApi) return; WriteLog("ReqQryMatchInfo"); SRequest* pRequest = MakeRequestBuf(E_MatchField); if (NULL == pRequest) return; DFITCMatchField* body = (DFITCMatchField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); body->instrumentType = instrumentType; AddToSendQueue(pRequest); }
void CTraderApi::ReqQryArbitrageInstrument(const string& szExchangeId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_AbiInstrumentField); if (NULL == pRequest) return; DFITCAbiInstrumentField* body = (DFITCAbiInstrumentField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->exchangeID,szExchangeId.c_str(),sizeof(DFITCExchangeIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryTradingAccount() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryTradingAccountField); if (nullptr == pRequest) return; CSecurityFtdcQryTradingAccountField& body = pRequest->QryTradingAccountField; strcpy(body.BrokerID, m_RspUserLogin.BrokerID); strcpy(body.InvestorID, m_RspUserLogin.UserID); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrument(const string& szInstrumentId, const string& szExchange) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentField); if (nullptr == pRequest) return; CThostFtdcQryInstrumentField& body = pRequest->QryInstrumentField; strncpy(body.ContractID, szInstrumentId.c_str(), sizeof(TThostFtdcInstrumentIDType)); //strncpy(body.ProductID, szExchange.c_str(), sizeof(TThostFtdcProductIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryTradingAccount() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryTradingAccountField); if (NULL == pRequest) return; CThostFtdcQryTradingAccountField& body = pRequest->QryTradingAccountField; strncpy(body.BrokerID, m_RspUserLogin.BrokerID,sizeof(TThostFtdcBrokerIDType)); strncpy(body.InvestorID, m_RspUserLogin.UserID,sizeof(TThostFtdcInvestorIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrumentCommissionRate(const string& szInstrumentId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentCommissionRateField); if (NULL == pRequest) return; CThostFtdcQryInstrumentCommissionRateField& body = pRequest->QryInstrumentCommissionRateField; strncpy(body.BrokerID, m_RspUserLogin.BrokerID,sizeof(TThostFtdcBrokerIDType)); strncpy(body.InvestorID, m_RspUserLogin.UserID,sizeof(TThostFtdcInvestorIDType)); strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TThostFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryPositionDetail(const string& szInstrumentId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_PositionDetailField); if (NULL == pRequest) return; DFITCPositionDetailField* body = (DFITCPositionDetailField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->instrumentID,szInstrumentId.c_str(),sizeof(DFITCInstrumentIDType)); //body->instrumentType; AddToSendQueue(pRequest); }
void CTraderApi::ReqQryExchangeInstrument(const string& szExchangeId,DFITCInstrumentTypeType instrumentType) { if (NULL == m_pApi) return; WriteLog("ReqQryExchangeInstrument %s %d",szExchangeId.c_str(),instrumentType); SRequest* pRequest = MakeRequestBuf(E_ExchangeInstrumentField); if (NULL == pRequest) return; DFITCExchangeInstrumentField* body = (DFITCExchangeInstrumentField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->exchangeID,szExchangeId.c_str(),sizeof(DFITCExchangeIDType)); body->instrumentType = instrumentType; AddToSendQueue(pRequest); }
void CTraderApi::ReqQryTrade() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryTradeField); if (nullptr == pRequest) return; CUstpFtdcQryTradeField& body = pRequest->QryTradeField; strcpy(body.BrokerID, m_RspUserInvestor.BrokerID); strcpy(body.UserID, m_RspUserInvestor.UserID); strcpy(body.InvestorID, m_RspUserInvestor.InvestorID); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInvestorPosition(const string& szInstrumentId, const string& szExchange) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInvestorPositionField); if (nullptr == pRequest) return; CSecurityFtdcQryInvestorPositionField& body = pRequest->QryInvestorPositionField; strcpy(body.BrokerID, m_RspUserLogin.BrokerID); strcpy(body.InvestorID, m_RspUserLogin.UserID); strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TSecurityFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryUserInvestor() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryUserInvestorField); if (pRequest) { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Doing, 0, nullptr, 0, nullptr, 0, nullptr, 0); CUstpFtdcQryUserInvestorField& body = pRequest->QryUserInvestorField; strncpy(body.BrokerID, m_ServerInfo.BrokerID, sizeof(TUstpFtdcBrokerIDType)); strncpy(body.UserID, m_UserInfo.UserID, sizeof(TUstpFtdcInvestorIDType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqQryInvestorFee(const string& szInstrumentId) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInvestorFeeField); if (nullptr == pRequest) return; CUstpFtdcQryInvestorFeeField& body = pRequest->QryInvestorFeeField; strcpy(body.BrokerID, m_RspUserInvestor.BrokerID); strcpy(body.UserID, m_RspUserInvestor.UserID); strcpy(body.InvestorID, m_RspUserInvestor.InvestorID); strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TUstpFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqUserLogin() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqUserLoginField); if (pRequest) { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logining, 0, nullptr, 0, nullptr, 0, nullptr, 0); CThostFtdcReqUserLoginField& body = pRequest->ReqUserLoginField; strncpy(body.accountID, m_UserInfo.UserID, sizeof(TThostFtdcTraderIDType)); strncpy(body.password, m_UserInfo.Password, sizeof(TThostFtdcPasswordType)); body.loginType = BANKACC_TYPE; AddToSendQueue(pRequest); } }
void CTraderApi::ReqUserLogin() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqUserLoginField); if (pRequest) { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logining, 0, nullptr, 0, nullptr, 0, nullptr, 0); CUstpFtdcReqUserLoginField& body = pRequest->ReqUserLoginField; strncpy(body.UserID, m_UserInfo.UserID, sizeof(TUstpFtdcInvestorIDType)); strncpy(body.BrokerID, m_ServerInfo.BrokerID, sizeof(TUstpFtdcBrokerIDType)); strncpy(body.Password, m_UserInfo.Password, sizeof(TUstpFtdcPasswordType)); strncpy(body.UserProductInfo, m_ServerInfo.UserProductInfo, sizeof(TUstpFtdcProductInfoType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqSettlementInfoConfirm() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_SettlementInfoConfirmField); if (pRequest) { m_status = E_confirming; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); CThostFtdcSettlementInfoConfirmField& body = pRequest->SettlementInfoConfirmField; strncpy(body.BrokerID, m_szBrokerId.c_str(),sizeof(TThostFtdcBrokerIDType)); strncpy(body.InvestorID, m_szInvestorId.c_str(),sizeof(TThostFtdcInvestorIDType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqUserLogin() { if (NULL == m_pApi) return; WriteLog("ReqUserLogin"); SRequest* pRequest = MakeRequestBuf(E_UserLoginField); if (pRequest) { m_status = E_logining; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); DFITCUserLoginField* body = (DFITCUserLoginField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->passwd, m_szPassword.c_str(),sizeof(DFITCPasswdType)); body->companyID = m_sCompanyID; AddToSendQueue(pRequest); } }
void CTraderApi::ReqAuthenticate() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqAuthenticateField); if (pRequest) { m_status = E_authing; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); CThostFtdcReqAuthenticateField& body = pRequest->ReqAuthenticateField; strncpy(body.BrokerID, m_szBrokerId.c_str(),sizeof(TThostFtdcBrokerIDType)); strncpy(body.UserID, m_szInvestorId.c_str(),sizeof(TThostFtdcInvestorIDType)); strncpy(body.UserProductInfo,m_szUserProductInfo.c_str(),sizeof(TThostFtdcProductInfoType)); strncpy(body.AuthCode,m_szAuthCode.c_str(),sizeof(TThostFtdcAuthCodeType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqUserLogin() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqUserLoginField); if (pRequest) { m_status = E_logining; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); CThostFtdcReqUserLoginField& body = pRequest->ReqUserLoginField; strncpy(body.BrokerID, m_szBrokerId.c_str(),sizeof(TThostFtdcBrokerIDType)); strncpy(body.UserID, m_szInvestorId.c_str(),sizeof(TThostFtdcInvestorIDType)); strncpy(body.Password, m_szPassword.c_str(),sizeof(TThostFtdcPasswordType)); strncpy(body.UserProductInfo,m_szUserProductInfo.c_str(),sizeof(TThostFtdcProductInfoType)); AddToSendQueue(pRequest); } }
int CTraderApi::ReqQuoteAction(CUstpFtdcRtnQuoteField *pQuote) { if (nullptr == m_pApi) return 0; SRequest* pRequest = MakeRequestBuf(E_QuoteActionField); if (nullptr == pRequest) return 0; CUstpFtdcQuoteActionField& body = pRequest->QuoteActionField; strcpy(body.BrokerID, pQuote->BrokerID); strcpy(body.InvestorID, pQuote->InvestorID); strcpy(body.UserID, pQuote->UserID); ///报单引用 strcpy(body.UserQuoteLocalID, pQuote->UserQuoteLocalID); ///交易所代码 strcpy(body.ExchangeID, pQuote->ExchangeID); ///报单编号 strcpy(body.QuoteSysID, pQuote->QuoteSysID); ///操作标志 body.ActionFlag = USTP_FTDC_AF_Delete; ///合约代码 int nRet = 0; { lock_guard<mutex> cl(m_csOrderRef); sprintf(body.UserQuoteActionLocalID, "%012lld", m_nMaxOrderRef); ++m_nMaxOrderRef; nRet = m_pApi->ReqQuoteAction(&pRequest->QuoteActionField, ++m_lRequestID); } delete pRequest; return nRet; }
void CTraderApi::Connect( const string& szSvrAddr, const string& szAccountID, const string& szPassword, short sCompanyID) { WriteLog("Connect %s %s",szSvrAddr.c_str(),szAccountID.c_str()); m_szSvrAddr = szSvrAddr; m_szAccountID = szAccountID; m_szPassword = szPassword; m_sCompanyID = sCompanyID; m_pApi = DFITCTraderApi::CreateDFITCTraderApi(); m_status = E_inited; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); SRequest* pRequest = MakeRequestBuf(E_Init); if(pRequest) { AddToSendQueue(pRequest); } }