/// <summary>
        /// 接收响应数据
        /// </summary>
        /// <param name="responseType"></param>
        /// <param name="pData"></param>
        /// <param name="requestID"></param>
        protected void ReceiveResponseData(TResponseType responseType, IntPtr pData, int requestID)
        {
            //建立响应数据缓存
            if (this.responseDataMap.ContainsKey(requestID) == false)
            {
                this.responseDataMap[requestID] = new List <Object>();
            }

            //保存响应数据
            if (pData != IntPtr.Zero)
            {
                Object value = null;

                if (responseDataTypeMapping.ContainsKey(responseType))
                {
                    Type t = responseDataTypeMapping[responseType];

                    if (t != null)
                    {
                        value = PInvokeUtility.GetObjectFromIntPtr(t, pData);
                    }
                }

                if (value != null)
                {
                    this.responseDataMap[requestID].Add(value);
                }
            }
        }
Example #2
0
        /*
         * /// <summary>
         * /// 初始化接受数据类型
         * /// </summary>
         * protected override void InitResponseDataTypeMapping()
         * {
         * ///客户端认证响应
         * responseDataTypeMapping.Add(CTPStockResponseType.AuthenticateResponse, typeof(CZQThostFtdcRspAuthenticateField));
         * ///登录请求响应
         * responseDataTypeMapping.Add(CTPStockResponseType.UserLoginResponse, typeof(CZQThostFtdcRspUserLoginField));
         * ///登出请求响应
         * responseDataTypeMapping.Add(CTPStockResponseType.UserLogoutResponse, typeof(CZQThostFtdcUserLogoutField));
         * ///用户口令更新请求响应
         * responseDataTypeMapping.Add(CTPStockResponseType.UserPasswordUpdateResponse, typeof(CZQThostFtdcUserPasswordUpdateField));
         * ///报单录入请求响应
         * responseDataTypeMapping.Add(CTPStockResponseType.OrderInsertResponse, typeof(CZQThostFtdcInputOrderField));
         * ///报单操作请求响应
         * responseDataTypeMapping.Add(CTPStockResponseType.OrderActionResponse, typeof(CZQThostFtdcInputOrderActionField));
         * ///查询最大报单数量响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryMaxOrderVolumeResponse, typeof(CZQThostFtdcQueryMaxOrderVolumeField));
         * ///请求查询报单响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryOrderResponse, typeof(CZQThostFtdcOrderField));
         * ///请求查询成交响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryTradeResponse, typeof(CZQThostFtdcTradeField));
         * ///请求查询资金账户响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryTradingAccountResponse, typeof(CZQThostFtdcTradingAccountField));
         * ///请求查询投资者响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryInvestorResponse, typeof(CZQThostFtdcInvestorField));
         * ///请求查询交易编码响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryTradingCodeResponse, typeof(CZQThostFtdcTradingCodeField));
         * ///请求查询合约手续费率响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryInstrumentCommissionRateResponse, typeof(CZQThostFtdcInstrumentCommissionRateField));
         * ///请求查询交易所响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryExchangeResponse, typeof(CZQThostFtdcExchangeField));
         * ///请求查询合约响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryInstrumentResponse, typeof(CZQThostFtdcInstrumentField));
         * ///请求查询行情响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryDepthMarketDataResponse, typeof(CZQThostFtdcDepthMarketDataField));
         * ///请求查询投资者持仓明细响应
         * responseDataTypeMapping.Add(CTPStockResponseType.QueryInvestorPositionDetailResponse, typeof(CZQThostFtdcInvestorPositionDetailField));
         * ///错误应答
         * responseDataTypeMapping.Add(CTPStockResponseType.ErrorResponse, typeof(CZQThostFtdcRspInfoField));
         * ///报单通知
         * responseDataTypeMapping.Add(CTPStockResponseType.ReturnOrderResponse, typeof(CZQThostFtdcOrderField));
         * ///成交通知
         * responseDataTypeMapping.Add(CTPStockResponseType.ReturnTradeResponse, typeof(CZQThostFtdcTradeField));
         * ///报单录入错误回报
         * responseDataTypeMapping.Add(CTPStockResponseType.ErrorReturnOrderInsertResponse, typeof(CZQThostFtdcInputOrderField));
         * ///报单操作错误回报
         * responseDataTypeMapping.Add(CTPStockResponseType.ErrorReturnOrderActionResponse, typeof(CZQThostFtdcOrderActionField));
         * ///合约交易状态通知
         * responseDataTypeMapping.Add(CTPStockResponseType.ReturnInstrumentStatusResponse, typeof(CZQThostFtdcInstrumentStatusField));
         *
         * }
         */

        #region CTP API Invoke

        protected override CTPResponseInfo GetResponseInfo(IntPtr pRspInfo)
        {
            CTPResponseInfo rsp = new CTPResponseInfo();

            CZQThostFtdcRspInfoField rspInfo = PInvokeUtility.GetObjectFromIntPtr <CZQThostFtdcRspInfoField>(pRspInfo);

            rsp.ErrorID = rspInfo.ErrorID;
            //rsp.Message = PInvokeUtility.GetUnicodeString(rspInfo.ErrorMsg);
            rsp.Message = rspInfo.ErrorMsg;

            return(rsp);
        }
        /// <summary>
        /// 创建事件参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rspData"></param>
        /// <param name="rspInfo"></param>
        /// <returns></returns>
        protected CTPEventArgs <T> CreateEventArgs <T>(IntPtr rspData, CTPResponseInfo rspInfo)
        {
            //转换响应数据
            T value = default(T);

            if (rspData != IntPtr.Zero)
            {
                value = PInvokeUtility.GetObjectFromIntPtr <T>(rspData);
            }

            //创建事件参数
            CTPEventArgs <T> args = new CTPEventArgs <T>(value, rspInfo);

            return(args);
        }
Example #4
0
        /// <summary>
        /// 订阅行情应答
        /// </summary>
        internal void OnSubMarketData(IntPtr pSpecificInstrument, IntPtr pRspInfo, int nRequestID, bool bIsLast)
        {
            CZQThostFtdcSpecificInstrumentField instrument = PInvokeUtility.GetObjectFromIntPtr <CZQThostFtdcSpecificInstrumentField>(pSpecificInstrument);

            Trace.WriteLine("【订阅行情】" + instrument.InstrumentID);
        }