Example #1
0
        /// <summary>
        /// """合约查询回报"""
        /// </summary>
        /// <param name="pInstrument"></param>
        /// <param name="pRspInfo"></param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        public void HandleOnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            var contract = new ContractData();

            contract.gatewayName      = this.Gateway.gatewayName;
            contract.symbol           = pInstrument.InstrumentID;
            contract.exchange         = pInstrument.ExchangeID;
            contract.vtSymbol         = pInstrument.InstrumentID;
            contract.name             = pInstrument.InstrumentName;
            contract.size             = pInstrument.VolumeMultiple;
            contract.priceTick        = pInstrument.PriceTick;
            contract.strikePrice      = pInstrument.StrikePrice;
            contract.underlyingSymbol = pInstrument.UnderlyingInstrID;
            contract.productClass     = (string)TradeConstantDicSetting.ProductTypeDic[pInstrument.ProductClass];
            contract.expiryDate       = pInstrument.ExpireDate;

            if (contract.productClass == TradeCanstant.productOption)
            {
                contract.optionType = (string)TradeConstantDicSetting.OptionTypeDic[pInstrument.OptionsType];
            }
            ///合约推送
            this.Gateway.MainController.MainEvent._OnContract.Invoke(contract);
            if (bIsLast)
            {
                Console.WriteLine("获取合约完毕");
            }
        }
Example #2
0
 public Instrument(ThostFtdcInstrumentField field)
 {
     this.InstrumentID           = field.InstrumentID;
     this.ExchangeID             = field.ExchangeID;
     this.InstrumentName         = field.InstrumentName;
     this.ExchangeInstID         = field.ExchangeInstID;
     this.ProductID              = field.ProductID;
     this.ProductClass           = field.ProductClass;
     this.DeliveryYear           = field.DeliveryYear;
     this.DeliveryMonth          = field.DeliveryMonth;
     this.MaxMarketOrderVolume   = field.MaxMarketOrderVolume;
     this.MinMarketOrderVolume   = field.MinMarketOrderVolume;
     this.MaxLimitOrderVolume    = field.MaxLimitOrderVolume;
     this.MinLimitOrderVolume    = field.MinLimitOrderVolume;
     this.VolumeMultiple         = field.VolumeMultiple;
     this.PriceTick              = field.PriceTick;
     this.CreateDate             = field.CreateDate;
     this.OpenDate               = field.OpenDate;
     this.ExpireDate             = field.ExpireDate;
     this.StartDelivDate         = field.StartDelivDate;
     this.EndDelivDate           = field.EndDelivDate;
     this.InstLifePhase          = field.InstLifePhase;
     this.IsTrading              = field.IsTrading;
     this.PositionType           = field.PositionType;
     this.PositionDateType       = field.PositionDateType;
     this.LongMarginRatio        = field.LongMarginRatio;
     this.ShortMarginRatio       = field.ShortMarginRatio;
     this.MaxMarginSideAlgorithm = field.MaxMarginSideAlgorithm;
     this.UnderlyingInstrID      = field.UnderlyingInstrID;
     this.StrikePrice            = field.StrikePrice;
     this.OptionsType            = field.OptionsType;
     this.UnderlyingMultiple     = field.UnderlyingMultiple;
     this.CombinationType        = field.CombinationType;
 }
Example #3
0
 public Instrument(ThostFtdcInstrumentField field)
 {
     this.InstrumentID = field.InstrumentID;
     this.ExchangeID = field.ExchangeID;
     this.InstrumentName = field.InstrumentName;
     this.ExchangeInstID = field.ExchangeInstID;
     this.ProductID = field.ProductID;
     this.ProductClass = field.ProductClass;
     this.DeliveryYear = field.DeliveryYear;
     this.DeliveryMonth = field.DeliveryMonth;
     this.MaxMarketOrderVolume = field.MaxMarketOrderVolume;
     this.MinMarketOrderVolume = field.MinMarketOrderVolume;
     this.MaxLimitOrderVolume = field.MaxLimitOrderVolume;
     this.MinLimitOrderVolume = field.MinLimitOrderVolume;
     this.VolumeMultiple = field.VolumeMultiple;
     this.PriceTick = field.PriceTick;
     this.CreateDate = field.CreateDate;
     this.OpenDate = field.OpenDate;
     this.ExpireDate = field.ExpireDate;
     this.StartDelivDate = field.StartDelivDate;
     this.EndDelivDate = field.EndDelivDate;
     this.InstLifePhase = field.InstLifePhase;
     this.IsTrading = field.IsTrading;
     this.PositionType = field.PositionType;
     this.PositionDateType = field.PositionDateType;
     this.LongMarginRatio = field.LongMarginRatio;
     this.ShortMarginRatio = field.ShortMarginRatio;
     this.MaxMarginSideAlgorithm = field.MaxMarginSideAlgorithm;
     this.UnderlyingInstrID = field.UnderlyingInstrID;
     this.StrikePrice = field.StrikePrice;
     this.OptionsType = field.OptionsType;
     this.UnderlyingMultiple = field.UnderlyingMultiple;
     this.CombinationType = field.CombinationType;
 }
Example #4
0
 public ActiveContract(ThostFtdcInstrumentField contract)
 {
     this.Contract = contract;
     LongPosition = new ThostFtdcInvestorPositionField();
     ShortPosition = new ThostFtdcInvestorPositionField();
     OptionValue = new OptionValue();
 }
Example #5
0
 void _trade_OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pInstrument != null)
     {
         switch (pInstrument.ProductClass)
         {
         case EnumProductClassType.ETFOption:
             this._contracts[pInstrument.InstrumentID] = new OptionContract
             {
                 ID            = pInstrument.InstrumentID,
                 Name          = pInstrument.InstrumentName,
                 CallPut       = pInstrument.OptionsType == EnumOptionsType.Call ? CallPut.Call : CallPut.Put,
                 Maturity      = DateTime.ParseExact(pInstrument.ExpireDate, "yyyyMMdd", CultureInfo.InvariantCulture),
                 Strike        = pInstrument.StrikePrice,
                 SubjectMatter = pInstrument.UnderlyingInstrID,
                 Size          = pInstrument.VolumeMultiple
             };
             break;
         }
     }
     if (bIsLast)
     {
         var ret = this._market.SubscribeMarketData(this.Instruments.Select(_ => _.ID).ToArray());
     }
 }
Example #6
0
 void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     DebugPrintFunc(new StackTrace());
     if (bIsLast && !IsErrorRspInfo(pRspInfo))
     {
         //请求查询合约
         ReqQryTradingAccount();
     }
 }
Example #7
0
 void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     __DEBUGPF__();
     if (bIsLast && !IsErrorRspInfo(pRspInfo))
     {
         //请求查询合约
         ReqQryTradingAccount();
     }
 }
Example #8
0
        private void TraderAdapter_OnRspQryInstrument(ThostFtdcInstrumentField pInstrument,
                                                      ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast)
        {
            try
            {
                if (MyUtils.IsWrongRspInfo(pRspInfo))
                {
                    MyUtils.ReportError(pRspInfo, "查询合约错误");
                    return;
                }

                if (pInstrument != null)
                {
                    if (!pInstrument.InstrumentID.Contains("efp") && !pInstrument.InstrumentID.Contains("eof"))
                    {
                        if (pInstrument.InstrumentID.Contains("&"))
                        {
                            //套利合约
                            MyUtils.ComboInstrumentInfo[pInstrument.InstrumentID] = pInstrument;
                        }
                        else
                        {
                            //标准
                            MyUtils.StandardInstrumentInfo[pInstrument.InstrumentID] = pInstrument;
                        }
                        MyUtils.CategoryToExchangeId[MyUtils.GetInstrumentCategory(pInstrument.InstrumentID)] =
                            pInstrument.ExchangeID;

                        var temp =
                            string.Format(
                                "查询合约回报: 创建日:{0},交割月:{1},交割年份:{2},结束交割日:{3},交易所代码:{4},合约在交易所的代码:{5},到期日:{6},合约生命周期状态:{7},合约代码:{8},合约名称:{9},当前是否交易:{10},多头保证金率:{11},限价单最大下单量:{12},市价单最大下单量:{13},限价单最小下单量:{14},市价单最小下单量:{15},上市日:{16},持仓日期类型:{17},持仓类型:{18},最小变动价位:{19},产品类型:{20},产品代码:{21},空头保证金率:{22},开始交割日:{23},合约数量乘数:{24}",
                                pInstrument.CreateDate, pInstrument.DeliveryMonth, pInstrument.DeliveryYear,
                                pInstrument.EndDelivDate, pInstrument.ExchangeID, pInstrument.ExchangeInstID,
                                pInstrument.ExpireDate, pInstrument.InstLifePhase, pInstrument.InstrumentID,
                                pInstrument.InstrumentName, pInstrument.IsTrading, pInstrument.LongMarginRatio,
                                pInstrument.MaxLimitOrderVolume, pInstrument.MaxMarketOrderVolume,
                                pInstrument.MinLimitOrderVolume, pInstrument.MinMarketOrderVolume, pInstrument.OpenDate,
                                pInstrument.PositionDateType, pInstrument.PositionType, pInstrument.PriceTick,
                                pInstrument.ProductClass, pInstrument.ProductID, pInstrument.ShortMarginRatio,
                                pInstrument.StartDelivDate, pInstrument.VolumeMultiple);
                    }
                }

                if (bIsLast)
                {
                    Thread.Sleep(1000);
                    ReqQryTradingAccount();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("查询合约出错:" + ex.Message);
            }
        }
Example #9
0
 public override void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.instruments.Add(new Instrument(pInstrument));
     if (bIsLast)
     {
         string[] instrumentIDs = this.instruments.Select(p => p.InstrumentID).ToArray();
         MdAdapter.Instance.Start(instrumentIDs);
         Instrument[] instruments = this.instruments.OrderBy(p => p.InstrumentID).ToArray();
         InstrumentListViewModel.Instance.Instruments = instruments;
         InstrumentDAL.Save(instruments);
     }
 }
Example #10
0
 public override void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.instruments.Add(new Instrument(pInstrument));
     if (bIsLast)
     {
         string[] instrumentIDs = this.instruments.Select(p => p.InstrumentID).ToArray();
         MdAdapter.Instance.Start(instrumentIDs);
         Instrument[] instruments = this.instruments.OrderBy(p => p.InstrumentID).ToArray();
         InstrumentListViewModel.Instance.Instruments = instruments;
         InstrumentDAL.Save(instruments);
     }
 }
Example #11
0
        public Trader(string instrumentID, double targetPrice, TradeFramework framework)
        {
            if (framework == null)
            {
                throw new ArgumentNullException();
            }
            this.Volume       = 1;
            this.instrumentID = instrumentID;
            this.targetPrice  = targetPrice;
            this.frame        = framework;

            this.frame.Subscribe(this, instrumentID);
            this.instrument = this.frame.GetInstrument(instrumentID);
        }
Example #12
0
        void api_OnCtpRspQryEvent(object sender, CtpRspQryEventArgs e)
        {
            Console.WriteLine(e.EventType.ToString());

            switch (e.EventType)
            {
            case CtpEnumRspQryType.RspQryInstrument:
            {
                ThostFtdcInstrumentField f = e.Param as ThostFtdcInstrumentField;
                if (f != null)
                {
                    Console.WriteLine("{0}, {1}, {2}", f.InstrumentID, f.InstrumentName, f.PriceTick);
                }
            }
            break;
            }
        }
Example #13
0
 public override void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo != null && pRspInfo.ErrorID != 0)
     {
         LogCenter.Error("请求查询合约错误:" + pRspInfo.ErrorMsg);
         return;
     }
     if (pInstrument.ProductClass == EnumProductClassType.Futures)
     {
         this.instruments.Add(new Instrument(pInstrument));
     }
     if (bIsLast)
     {
         LogCenter.Log("收到期货合约数量:" + this.instruments.Count);
         InstrumentCenter.Instance.SetInstruments(this.instruments.OrderBy(p => p.InstrumentID).ToArray());
     }
 }
Example #14
0
        private void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            __DEBUGPF__();

            // 保存返回的合约代码
            instruments.Add(pInstrument.InstrumentID);

            if (bIsLast)
            {
                HandleStatusInternal("CTP合约代码已获取");

                if (mdClient != null)
                {
                    mdClient.Subscribe(instruments.ToArray());
                }

                //请求查询资金账户
                ReqQryTradingAccount();
            }
        }
Example #15
0
 ///请求查询合约响应
 public void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (!IsErrorRspInfo(pRspInfo) && pInstrument != null)
     {
         if (pInstrument.ProductClass != EnumProductClassType.EFP)
         {
             cMainForm.SetTDRspQryInstrument((object)pInstrument);
         }
     }
 }
Example #16
0
        /// <summary>
        /// 请求查询合约响应
        /// </summary>
        /// <param name="pInstrument"></param>
        /// <param name="pRspInfo"></param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            DebugPrintFunc(new StackTrace());
            Console.WriteLine("密钥生成日期:{0},交割月:{1},交割年份:{2},结束交割日:{3},交易所代码:{4}",
                pInstrument.CreateDate,
                pInstrument.DeliveryMonth,
                pInstrument.DeliveryYear,
                pInstrument.EndDelivDate,
                pInstrument.ExchangeID);

            if (bIsLast && !IsErrorRspInfo(pRspInfo))
            {
                //请求查询资金账户
                ReqQryTradingAccount();
            }
        }
Example #17
0
 public Instrument(ThostFtdcInstrumentField field)
 {
     this.InstrumentID = field.InstrumentID;
 }
Example #18
0
 public override void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo != null && pRspInfo.ErrorID != 0)
     {
         LogCenter.Error("请求查询合约错误:" + pRspInfo.ErrorMsg);
         return;
     }
     if (pInstrument.ProductClass == EnumProductClassType.Futures)
     {
         this.instruments.Add(new Instrument(pInstrument));
     }
     if (bIsLast)
     {
         LogCenter.Log("收到期货合约数量:" + this.instruments.Count);
         InstrumentCenter.Instance.SetInstruments(this.instruments.OrderBy(p => p.InstrumentID).ToArray());
     }
 }
Example #19
0
 public Instrument(ThostFtdcInstrumentField field)
 {
     this.InstrumentID = field.InstrumentID;
 }
Example #20
0
 void trader_OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if(!bIsLast)
     {
         instrumentsList.Add(pInstrument);
         return;
     }
     this.SetMsg("正在连接行情主机……");
     marketer.RegisterFront(MDFrontAddr);
     marketer.Init();
 }