Пример #1
0
 /// <summary>
 /// 构造一个新实例
 /// </summary>
 /// <param name="Panel">所属行情面板</param>
 /// <param name="activeContract">合约</param>
 public Quote(ActiveContract call, ActiveContract put, ActiveContract underlying)
 {
     this.Tag = this;
     this.call = call;
     this.call.MarketUpdated += call_MarketUpdated;
     this.call.ForQuoteArrived += call_ForQuoteArrived;
     this.call.QuoteTraded += call_QuoteTraded;
     this.put = put;
     this.put.MarketUpdated += put_MarketUpdated;
     this.put.ForQuoteArrived += put_ForQuoteArrived;
     this.put.QuoteTraded += put_QuoteTraded;
     this.underlying = underlying;
     this.underlying.MarketUpdated += underlying_MarketUpdated;
     this.QuotePanelRefreshTimer = new System.Threading.Timer(this.QuotePanelRefreshCallback, null, 1000, 1000);
     this.call_MarketUpdated(this, EventArgs.Empty);
     this.put_MarketUpdated(this, EventArgs.Empty);
 }
Пример #2
0
 /// <summary>
 /// 加入活跃合约
 /// </summary>
 public void AddActiveContract(ActiveContract activeContract)
 {
     ActiveContractDictionary.Add(activeContract.Contract.InstrumentID, activeContract);
     marketer.SubscribeMarketData(new string[] { activeContract.Contract.InstrumentID });
 }
Пример #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            LoginForm loginForm = new LoginForm();
            if (loginForm.ShowDialog() == DialogResult.Cancel)
            {
                this.Close();
                return;
            }
            this.trader = loginForm.trader;
            this.marketer = loginForm.marketer;

            #region 订阅行情
            this.InstrumentsList = loginForm.instrumentsList;
            this.InvestorPositionList = loginForm.investorPositionList;
            MarketManeger = new MarketManager(this.marketer);
            foreach (ThostFtdcInstrumentField instrument in InstrumentsList)
            {
                if(instrument.InstrumentID.StartsWith("IF")||instrument.InstrumentID.StartsWith("IO"))
                {
                    ActiveContract activeContract = new ActiveContract(instrument);
                    foreach(ThostFtdcInvestorPositionField position in this.InvestorPositionList)
                    {
                        if(position.InstrumentID == instrument.InstrumentID && position.PosiDirection == EnumPosiDirectionType.Long)
                        {
                            activeContract.LongPosition = position;
                        }
                        else if(position.InstrumentID == instrument.InstrumentID && position.PosiDirection == EnumPosiDirectionType.Short)
                        {
                            activeContract.ShortPosition = position;
                        }
                    }
                    MarketManeger.AddActiveContract(activeContract);
                }
            }

            this.marketer.OnRtnDepthMarketData += marketer_OnRtnDepthMarketData;
            this.marketer.OnRtnForQuoteRsp += marketer_OnRtnForQuoteRsp;
            #endregion

            TraderManager = new TradeManager(trader);
            TraderManager.OnQuoteTraded += TraderManager_OnQuoteTraded;
            TraderManager.OnArbitrageTraded += TraderManager_OnArbitrageTraded;
            #region 加载平价套利
            //Dictionary<string, string[]> ParityConfigValues = ReadParityXML("Parity.xml");
            //foreach (string instrumentID in ParityConfigValues.Keys)
            //{
            //    string[] configValues = ParityConfigValues[instrumentID];
            //    Parity parity = new Parity(instrumentID, (EnumPosiDirectionType)Enum.Parse(typeof(EnumPosiDirectionType), configValues[0]), configValues[1],
            //        (EnumPosiDirectionType)Enum.Parse(typeof(EnumPosiDirectionType), configValues[2]), 0, Double.Parse(configValues[3]), Double.Parse(configValues[4]),
            //        Double.Parse(configValues[5]), Double.Parse(configValues[6]));
            //    parity.Configuration();
            //    this.parityPanel.AddParity(parity);
            //}

            #endregion

            //this.positionHedgeTimer = new System.Threading.Timer(this.positionHedgeCallBack, null, 3 * 1000, 5 * 1000);
            //this.recordVolatilityTimer = new System.Threading.Timer(this.recordVolatilityCallBack, null, 20 * 1000, 10 * 60 * 1000);
            //this.writeXmlTimer = new System.Threading.Timer(this.writerXmlCallBack, null, 10 * 1000, 10 * 1000);
        }