예제 #1
0
 /// <summary> Получение формы со стаканом и графиком </summary>
 /// <param name="sec"></param>
 /// <returns></returns>
 private Form_GraphicDepth ShowGraphicDepth(Securities sec)
 {
     try
     {
         var form = ListFormsDepth.FirstOrDefault(f => !f.isClose && f.TrElement.Security == sec);
         if (form == null)
         {
             var elTr = this.DataTrading.Collection.FirstOrDefault(e => e.Security == sec);
             if (elTr == null)
             {
                 elTr = new TElement(sec);
                 this.DataTrading.Add(elTr);
                 elTr.Create();
             }
             form = new Form_GraphicDepth(Trader, elTr, this);
             ListFormsDepth.Add(form);
         }
         if (form != null)
         {
             form.Show();
         }
         return(form);
     }
     catch (Exception ee)
     {
         MessageBox.Show(ee.ToString());
     }
     return(null);
 }
예제 #2
0
        void UpdateInfoAllTrades(IEnumerable <Trade> trades)
        {
            //DataTrading.AddNewTrades(trades);
            //Common.Ext.NewThread(() =>
            //{
            mutexTrades.WaitOne();
            try
            {
                foreach (var t in trades)
                {
                    //ControlTrade.Add(t);
                    TElement lastElem = DataTrading.Collection.FirstOrDefault(e => e.Security == t.Sec);
                    if (lastElem == null)
                    {
                        lastElem = new TElement(t.Sec);
                        DataTrading.Add(lastElem);
                        lastElem.Create();
                    }
                    lastElem.NewTrade(t);
                    //Thread.Sleep(1);
                }
                ForEachWinDepth((f) =>
                {
                    f.UpdateGraphic();
                });
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            //});
            if (trades.Count() > 0)
            {
                Trade lastT = trades.Last();
                statusStrip1.GuiAsync(() =>
                {
                    toolStripStatusLabel1.Text = Trader.Objects.CountTrades + " " + lastT.DateTrade.ToLongTimeString() + " Trade " + lastT.Number + " " + lastT.SecCode + ": " +
                                                 lastT.Price + " (" + lastT.Volume + ") " + lastT.Direction;
                });
            }
            mutexTrades.ReleaseMutex();

            /*int count = trades.Count();
             * Action ActionNewTrade = () =>
             * {
             *  foreach (var t in trades)
             *  {
             *      var el = DataTrading.Collection.FirstOrDefault(e => e.Security == t.Sec);
             *      if (el == null)
             *      {
             *          el = new TradingElement(t.Sec);
             *          DataTrading.Add(el);
             *      }
             *      el.NewTrade(t);
             *
             *      mutexAllTrade.WaitOne();
             *      var row = (DataGridViewRow)RowAllTradeClone.Clone();
             *      row.Cells[0].Value = "";
             *      listRowsAllTrades.Add(row);
             *      row.Cells[0].Value = countAllTrades.ToString();
             *      row.Cells[1].Value = t.Number.ToString();
             *      row.Cells[2].Value = t.Sec.Code;
             *      row.Cells[3].Value = t.DateTrade.ToLongTimeString();
             *      row.Cells[4].Value = t.Price.ToString();
             *      row.Cells[5].Value = t.Volume.ToString();
             *      row.Cells[6].Value = t.Direction == OrderDirection.Buy ? "Buy" : "Sell";
             *      mutexAllTrade.ReleaseMutex();
             *
             *      countAllTrades++;
             *  }
             *
             *  if (listRowsAllTrades.Count > 0)
             *  {
             *      dataGridViewAllTrade.GuiAsync(() =>
             *      {
             *          mutexAllTrade.WaitOne();
             *          dataGridViewAllTrade.Rows.AddRange(listRowsAllTrades.ToArray());
             *          listRowsAllTrades.Clear();
             *          mutexAllTrade.ReleaseMutex();
             *      });
             *
             *      if (ScrollAllTrades == null) ScrollAllTrades = (VScrollBar)dataGridViewAllTrade.Controls[1];
             *      int v = ScrollAllTrades.Value;
             *      int maxScroll = ScrollAllTrades.Maximum;
             *      if (v > maxScroll - 3000 && v != 0)
             *      {
             *              //ScrollAllTrades.Value = ScrollAllTrades.Maximum;
             *              dataGridViewAllTrade.GuiAsync(() =>
             *          {
             *              dataGridViewAllTrade.FirstDisplayedCell = dataGridViewAllTrade.Rows[dataGridViewAllTrade.Rows.Count - 1].Cells[0];
             *          });
             *      }
             *  }
             * };
             * if (count > 1000)
             * {
             *  Custome.NewThread(() =>
             *  {
             *      ActionNewTrade();
             *  });
             * }
             * else
             * {
             *  ActionNewTrade();
             * }*/
        }