Пример #1
0
        private void dataGridView_ArbiInstrument_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            ArbitrageCombineInstrumentViewModel model = this.dataGridView_ArbiInstrument.Rows[e.RowIndex].DataBoundItem as ArbitrageCombineInstrumentViewModel;

            Debug.Assert(model != null);

            FireCombineInstrumentSelected(model);
        }
Пример #2
0
        private void gridQuote_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            ArbitrageCombineInstrumentViewModel dataModel = this.dataGridView_ArbiInstrument.Rows[e.RowIndex].DataBoundItem as ArbitrageCombineInstrumentViewModel;

            Debug.Assert(dataModel != null);
            if (e.ColumnIndex == this.Column_Spread.Index)
            {
                SetPriceCellForeColor(e.CellStyle, dataModel.Spread);
            }
        }
Пример #3
0
        private void FireCombineInstrumentSelected(ArbitrageCombineInstrumentViewModel model)
        {
            SelectCombineInstrumentChangeEventHandle handle = this.OnSelectCombineInstrumentChanged;

            if (handle != null)
            {
                try
                {
                    handle(model.ArbitrageCombineInstrument);
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }
            }
        }
        public static ArbitrageCombineInstrumentViewModel CreatArbitrageCombineInstrumentViewModel(ArbitrageCombineInstrumentData data)
        {
            ArbitrageCombineInstrumentViewModel model = new ArbitrageCombineInstrumentViewModel();

            model.ArbitrageCombineInstrument = data.ArbitrageCombineInstrument;
            model.NearLastPrice          = data.NearLastPrice;
            model.FarLastPrice           = data.FarLastPrice;
            model.NearDistanceBuyPrice   = data.NearDistanceBuyPrice;
            model.FarDistanceBuyPrice    = data.FarDistanceBuyPrice;
            model.NearDistanceSellPrice  = data.NearDistanceSellPrice;
            model.FarDistanceSellPrice   = data.FarDistanceSellPrice;
            model.NearDistanceBuyVolumn  = data.NearDistanceBuyVolumn;
            model.FarDistanceBuyVolumn   = data.FarDistanceBuyVolumn;
            model.NearDistanceSellVolumn = data.NearDistanceSellVolumn;
            model.FarDistanceSellVolumn  = data.FarDistanceSellVolumn;
            return(model);
        }
        public static ArbitrageCombineInstrumentData CreatArbitrageCombineInstrumentData(ArbitrageCombineInstrumentViewModel model)
        {
            ArbitrageCombineInstrumentData data = new ArbitrageCombineInstrumentData();

            data.ArbitrageCombineInstrument = model.ArbitrageCombineInstrument;
            data.NearLastPrice          = model.NearLastPrice;
            data.FarLastPrice           = model.FarLastPrice;
            data.NearDistanceBuyPrice   = model.NearDistanceBuyPrice;
            data.FarDistanceBuyPrice    = model.FarDistanceBuyPrice;
            data.NearDistanceSellPrice  = model.NearDistanceSellPrice;
            data.FarDistanceSellPrice   = model.FarDistanceSellPrice;
            data.NearDistanceBuyVolumn  = model.NearDistanceBuyVolumn;
            data.FarDistanceBuyVolumn   = model.FarDistanceBuyVolumn;
            data.NearDistanceSellVolumn = model.NearDistanceSellVolumn;
            data.FarDistanceSellVolumn  = model.FarDistanceSellVolumn;
            return(data);
        }
Пример #6
0
        /// <summary>
        /// 更换品种,订阅品种所有合约行情。
        /// </summary>
        /// <param name="product"></param>
        private void ChangegProduct(USeProduct product)
        {
            m_dataSource.Clear();
            if (product == null)
            {
                return;
            }

            List <USeInstrument> subList = new List <USeInstrument>();

            try
            {
                foreach (ArbitrageCombineInstrument combineIns in m_CombineInstrumentList)
                {
                    if (combineIns.ProductID != product.ProductCode)
                    {
                        continue;
                    }

                    subList.Add(combineIns.FirstInstrument);
                    subList.Add(combineIns.SecondInstrument);

                    ArbitrageCombineInstrumentData combineMarketData = new ArbitrageCombineInstrumentData();
                    combineMarketData.ArbitrageCombineInstrument = combineIns;
                    combineMarketData.FarDistanceBuyPrice        = 0m;
                    combineMarketData.FarDistanceBuyVolumn       = 0;
                    combineMarketData.FarDistanceSellPrice       = 0m;
                    combineMarketData.FarDistanceSellVolumn      = 0;

                    combineMarketData.NearDistanceBuyPrice   = 0m;
                    combineMarketData.NearDistanceBuyVolumn  = 0;
                    combineMarketData.NearDistanceSellPrice  = 0m;
                    combineMarketData.NearDistanceSellVolumn = 0;

                    combineMarketData.NearLastPrice = 0m;
                    combineMarketData.FarLastPrice  = 0m;

                    ArbitrageCombineInstrumentViewModel combineMarketDataModel = ArbitrageCombineInstrumentViewModel.CreatArbitrageCombineInstrumentViewModel(combineMarketData);
                    m_dataSource.Insert(0, combineMarketDataModel);
                }

                //更改当前品种
                m_product = product;

                USeManager.Instance.QuoteDriver.Subscribe(subList);
                //ToDO:快速查询,行情列表需要排序
                foreach (USeInstrument ins in subList)
                {
                    USeManager.Instance.QuoteDriver.QuickQuery(ins);
                }

                foreach (DataGridViewColumn c in this.dataGridView_ArbiInstrument.Columns)
                {
                    c.SortMode = DataGridViewColumnSortMode.Automatic;
                }
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }
        }
Пример #7
0
        //public void OnArbitrageCombineInstrumentAdd_Changed(ArbitrageCombineInstrument arbitrageInstrument)
        //{
        //    Debug.Assert(arbitrageInstrument != null);

        //    //ToDo::
        //    if (arbitrageInstrument.ProductID != m_product.ProductCode) return;

        //    ArbitrageCombineInstrumentData combineMarketData = new ArbitrageCombineInstrumentData();
        //    combineMarketData.ArbitrageCombineInstrument = arbitrageInstrument;
        //    combineMarketData.FarDistanceBuyPrice = 0m;
        //    combineMarketData.FarDistanceBuyVolumn = 0;
        //    combineMarketData.FarDistanceSellPrice = 0m;
        //    combineMarketData.FarDistanceSellVolumn = 0;

        //    combineMarketData.NearDistanceBuyPrice = 0m;
        //    combineMarketData.NearDistanceBuyVolumn = 0;
        //    combineMarketData.NearDistanceSellPrice = 0m;
        //    combineMarketData.NearDistanceSellVolumn = 0;

        //    combineMarketData.NearLastPrice = 0m;
        //    combineMarketData.FarLastPrice = 0m;

        //    ArbitrageCombineInstrumentViewModel combineMarketDataModel = ArbitrageCombineInstrumentViewModel.CreatArbitrageCombineInstrumentViewModel(combineMarketData);

        //    m_CombineInstrumentList.Add(combineMarketDataModel.ArbitrageCombineInstrument);
        //    m_dataSource.Insert(0, combineMarketDataModel);

        //    USeManager.Instance.QuoteDriver.Subscribe(arbitrageInstrument.FirstInstrument);
        //    USeManager.Instance.QuoteDriver.Subscribe(arbitrageInstrument.SecondInstrument);
        //}


        //public void OnArbitrageCombineInstrumentRemove_Changed(ArbitrageCombineInstrument arbitrageInstrument)
        //{
        //    Debug.Assert(arbitrageInstrument != null);

        //    //Todo::
        //    if (arbitrageInstrument.ProductID != m_product.ProductCode) return;
        //    ArbitrageCombineInstrumentViewModel combinIns = (from ins in m_dataSource
        //                                                     where ins.ArbitrageCombineInstrument == arbitrageInstrument
        //                                                     select ins).FirstOrDefault();
        //    if (combinIns != null)
        //    {
        //        m_dataSource.Remove(combinIns);
        //        m_CombineInstrumentList.Remove(combinIns.ArbitrageCombineInstrument);
        //    }
        //}


        /// <summary>
        /// 订阅的市场价格更改。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QuoteDriver_OnMarketDataChanged(object sender, USeMarketDataChangedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler <USeMarketDataChangedEventArgs>(QuoteDriver_OnMarketDataChanged), sender, e);
                return;
            }

            if (USeTraderProtocol.GetVarieties(e.MarketData.Instrument.InstrumentCode) != m_product.ProductCode)
            {
                return;
            }


            m_marketDataDic[e.MarketData.Instrument] = e.MarketData;

            foreach (ArbitrageCombineInstrument combineIns in m_CombineInstrumentList)
            {
                USeInstrument firIns = combineIns.FirstInstrument;
                USeInstrument secIns = combineIns.SecondInstrument;

                if (m_marketDataDic.ContainsKey(firIns) && m_marketDataDic.ContainsKey(secIns))
                {
                    ArbitrageCombineInstrumentData combineMarketData = new ArbitrageCombineInstrumentData();
                    combineMarketData.ArbitrageCombineInstrument = combineIns;
                    combineMarketData.FarDistanceBuyPrice        = m_marketDataDic[secIns].BidPrice;
                    combineMarketData.FarDistanceBuyVolumn       = m_marketDataDic[secIns].BidSize;
                    combineMarketData.FarDistanceSellPrice       = m_marketDataDic[secIns].AskPrice;
                    combineMarketData.FarDistanceSellVolumn      = m_marketDataDic[secIns].AskSize;

                    combineMarketData.NearDistanceBuyPrice   = m_marketDataDic[firIns].BidPrice;
                    combineMarketData.NearDistanceBuyVolumn  = m_marketDataDic[firIns].BidSize;
                    combineMarketData.NearDistanceSellPrice  = m_marketDataDic[firIns].AskPrice;
                    combineMarketData.NearDistanceSellVolumn = m_marketDataDic[firIns].AskSize;

                    combineMarketData.NearLastPrice = m_marketDataDic[firIns].LastPrice;
                    combineMarketData.FarLastPrice  = m_marketDataDic[secIns].LastPrice;

                    if (m_dataSource.Count == 0)
                    {
                        continue;
                    }
                    Debug.WriteLine(DateTime.Now.ToString() + "--" + m_dataSource.Count() + combineIns.ArbitrageInstrumentOneCode + combineIns.ArbitrageInstrumentTwoCode);

                    ArbitrageCombineInstrumentViewModel combineMarketModel = (from p in m_dataSource
                                                                              where p.ArbitrageCombineInstrument == combineIns
                                                                              select p).FirstOrDefault();


                    if (combineMarketModel != null)
                    {
                        combineMarketModel.Update(combineMarketData);
                    }
                    else
                    {
                        m_dataSource.Add(combineMarketModel);
                    }
                }
                else
                {
                    continue;
                }
            }
        }