Exemplo n.º 1
0
        //private void OnRspQryInstrumentMarginRate_callback(IntPtr pTraderApi, ref CZQThostFtdcInstrumentMarginRateField pInstrumentMarginRate, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        //{
        //    if (null != OnRspQryInstrumentMarginRate)
        //    {
        //        OnRspQryInstrumentMarginRate(this, new OnRspQryInstrumentMarginRateArgs(pTraderApi, ref pInstrumentMarginRate, ref pRspInfo, nRequestID, bIsLast));
        //    }
        //}

        private void OnRspQryInvestorPosition_callback(IntPtr pTraderApi, ref CZQThostFtdcInvestorPositionField pInvestorPosition, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (null != OnRspQryInvestorPosition)
            {
                OnRspQryInvestorPosition(this, new OnRspQryInvestorPositionArgs(pTraderApi, ref pInvestorPosition, ref pRspInfo, nRequestID, bIsLast));
            }
        }
Exemplo n.º 2
0
 public OnRspQryInvestorPositionArgs(IntPtr pTraderApi, ref CZQThostFtdcInvestorPositionField pInvestorPosition, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.pTraderApi        = pTraderApi;
     this.pInvestorPosition = pInvestorPosition;
     this.pRspInfo          = pRspInfo;
     this.nRequestID        = nRequestID;
     this.bIsLast           = bIsLast;
 }
Exemplo n.º 3
0
        //#region 保证金率列表
        //private void OnRspQryInstrumentMarginRate(IntPtr pTraderApi, ref CZQThostFtdcInstrumentMarginRateField pInstrumentMarginRate, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        //{
        //    if (0 == pRspInfo.ErrorID)
        //    {
        //        _dictMarginRate[pInstrumentMarginRate.InstrumentID] = pInstrumentMarginRate;
        //        Console.WriteLine("TdApi:{0},已经接收保证金率 {1}",
        //                Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
        //                pInstrumentMarginRate.InstrumentID);

        //        Console.WriteLine("{0},{1},{2},{3}", pInstrumentMarginRate.LongMarginRatioByMoney, pInstrumentMarginRate.LongMarginRatioByVolume,
        //            pInstrumentMarginRate.ShortMarginRatioByMoney, pInstrumentMarginRate.ShortMarginRatioByVolume);

        //        //通知单例
        //        CTPZQAPI.GetInstance().FireOnRspQryInstrumentMarginRate(pInstrumentMarginRate);
        //    }
        //    else
        //        EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrumentMarginRate:" + pRspInfo.ErrorMsg);
        //}
        //#endregion

        #region 持仓回报
        private void OnRspQryInvestorPosition(IntPtr pTraderApi, ref CZQThostFtdcInvestorPositionField pInvestorPosition, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (0 == pRspInfo.ErrorID)
            {
                _dbInMemInvestorPosition.InsertOrReplace(
                    pInvestorPosition.InstrumentID,
                    pInvestorPosition.PosiDirection,
                    pInvestorPosition.HedgeFlag,
                    pInvestorPosition.PositionDate,
                    pInvestorPosition.Position,
                    pInvestorPosition.LongFrozen,
                    pInvestorPosition.ShortFrozen);
                timerPonstion.Enabled = false;
                timerPonstion.Enabled = true;
            }
            else
            {
                tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInvestorPosition:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInvestorPosition:" + pRspInfo.ErrorMsg);
            }
        }
        public static string GetOrderUniqueKey(object field)
        {
            //委托单
            //if (field is CZQThostFtdcInputOrderField)
            //{
            //  CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field;
            //  return string.Format("{0}_{1}_{2}_{3}", ctpOrder.BrokerID, ctpOrder.InvestorID, ctpOrder.InstrumentID, ctpOrder.OrderRef);
            //}

            //撤单
            if (field is CZQThostFtdcOrderActionField)
            {
                CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field;
                return(string.Format("{0:X}_{1:X}_{2}", ctpOrder.FrontID, ctpOrder.SessionID, ctpOrder.OrderRef.Trim()));
            }

            //订单
            if (field is CZQThostFtdcOrderField)
            {
                CZQThostFtdcOrderField ctpOrder = (CZQThostFtdcOrderField)field;
                return(string.Format("{0:X}_{1:X}_{2}", ctpOrder.FrontID, ctpOrder.SessionID, ctpOrder.OrderRef.Trim()));
            }

            //预埋单
            if (field is CZQThostFtdcParkedOrderField)
            {
                CZQThostFtdcParkedOrderField ctpOrder = (CZQThostFtdcParkedOrderField)field;
                return(string.Format("{0}_{1}_{2}", ctpOrder.BrokerID, ctpOrder.InvestorID, ctpOrder.ParkedOrderID));
            }

            //删除预埋单
            if (field is CZQThostFtdcRemoveParkedOrderField)
            {
                CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field;
                return(string.Format("{0}_{1}_{2}", ctpOrder.BrokerID, ctpOrder.InvestorID, ctpOrder.ParkedOrderID));
            }


            //成交单
            if (field is CZQThostFtdcTradeField)
            {
                CZQThostFtdcTradeField ctpData = (CZQThostFtdcTradeField)field;
                return(string.Format("{0}_{1}_{2}_{3}", ctpData.BrokerID, ctpData.InvestorID, ctpData.TradingDay, ctpData.TradeID));
            }

            //持仓
            if (field is CZQThostFtdcInvestorPositionField)
            {
                CZQThostFtdcInvestorPositionField ctpData = (CZQThostFtdcInvestorPositionField)field;
                return(string.Format("{0}_{1}_{2}_{3}_{4}", ctpData.BrokerID, ctpData.InvestorID, ctpData.TradingDay, ctpData.InstrumentID, ctpData.PosiDirection));
            }

            //持仓明细
            if (field is CZQThostFtdcInvestorPositionDetailField)
            {
                //注意!!成交单ID可能重复
                CZQThostFtdcInvestorPositionDetailField ctpData = (CZQThostFtdcInvestorPositionDetailField)field;
                return(string.Format("{0}_{1}_{2}_{3}", ctpData.BrokerID, ctpData.InvestorID, ctpData.TradingDay, ctpData.TradeID));
            }

            throw new Exception("Unknow type : " + field.GetType().ToString());
        }
        public static string GetUserKey(object field)
        {
            //委托单
            if (field is CZQThostFtdcInputOrderField)
            {
                CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //撤单
            if (field is CZQThostFtdcOrderActionField)
            {
                CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //预埋单
            if (field is CZQThostFtdcParkedOrderField)
            {
                CZQThostFtdcParkedOrderField ctpOrder = (CZQThostFtdcParkedOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //删除预埋单
            if (field is CZQThostFtdcRemoveParkedOrderField)
            {
                CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //预埋撤单
            if (field is CZQThostFtdcParkedOrderActionField)
            {
                CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //删除预埋撤单
            if (field is CZQThostFtdcRemoveParkedOrderActionField)
            {
                CZQThostFtdcRemoveParkedOrderActionField ctpOrder = (CZQThostFtdcRemoveParkedOrderActionField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //订单
            if (field is CZQThostFtdcOrderField)
            {
                CZQThostFtdcOrderField ctpOrder = (CZQThostFtdcOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //成交单
            if (field is CZQThostFtdcTradeField)
            {
                CZQThostFtdcTradeField ctpData = (CZQThostFtdcTradeField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //持仓
            if (field is CZQThostFtdcInvestorPositionField)
            {
                CZQThostFtdcInvestorPositionField ctpData = (CZQThostFtdcInvestorPositionField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //持仓明细
            if (field is CZQThostFtdcInvestorPositionDetailField)
            {
                CZQThostFtdcInvestorPositionDetailField ctpData = (CZQThostFtdcInvestorPositionDetailField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //持仓明细
            if (field is CZQThostFtdcInvestorPositionCombineDetailField)
            {
                CZQThostFtdcInvestorPositionCombineDetailField ctpData = (CZQThostFtdcInvestorPositionCombineDetailField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //资金账户
            if (field is CZQThostFtdcTradingAccountField)
            {
                CZQThostFtdcTradingAccountField ctpData = (CZQThostFtdcTradingAccountField)field;
                return(GetUserKey(ctpData.AccountID, ctpData.BrokerID));
            }

            throw new Exception("unknow type : " + field.GetType().FullName);
        }