コード例 #1
0
 /// <summary> Событие новой заявки </summary>
 public void EventNewOrder(IEnumerable <Order> orders)
 {
     Qlog.CatchException(() =>
     {
         if (TrElement.IsNull())
         {
             return;
         }
         //Обновялем панель заявок
         UpdatePanelOrder(orders);
     });
 }
コード例 #2
0
        /// <summary> Обновление стакана </summary>
        public void UpdateDepth()
        {
            if (TrElement.IsNull())
            {
                return;
            }
            int count  = 20;
            var orders = Trader.Objects.tOrders
                         .SearchAll(o => o.Sec == TrElement.Security && o.Status == OrderStatus.ACTIVE);

            var ordersBuy = orders.Where(o => o.Direction == OrderDirection.Buy)
                            .OrderByDescending(o => o.Price).ToArray();
            var ordersSell = orders.Where(o => o.Direction == OrderDirection.Sell)
                             .OrderBy(o => o.Price).ToArray();

            var pricesBuy  = ordersBuy.Select(o => o.Price).Take(count).ToArray();
            var pricesSell = ordersSell.Select(o => o.Price).Take(count).ToArray();

            if (ArraySell.IsNull())
            {
                ArraySell = new DataGridViewRow[count];
                for (int i = count - 1; i >= 0; i--)
                {
                    var k = dataGridViewDepth.Rows.Add();
                    ArraySell[i] = dataGridViewDepth.Rows[k];
                    ArraySell[i].Cells[0].Value           = "";
                    ArraySell[i].Cells[1].Value           = "";
                    ArraySell[i].Cells[2].Value           = "";
                    ArraySell[i].Cells[3].Value           = "";
                    ArraySell[i].Cells[2].Style.BackColor = Color.LightCoral;
                    ArraySell[i].Cells[1].Style.Font      = new Font(DataGridView.DefaultFont, FontStyle.Regular);
                }
            }
            if (ArrayBuy.IsNull())
            {
                ArrayBuy = new DataGridViewRow[count];
                for (int i = 0; i < count; i++)
                {
                    var k = dataGridViewDepth.Rows.Add();
                    ArrayBuy[i] = dataGridViewDepth.Rows[k];
                    ArrayBuy[i].Cells[0].Value           = "";
                    ArrayBuy[i].Cells[1].Value           = "";
                    ArrayBuy[i].Cells[2].Value           = "";
                    ArrayBuy[i].Cells[3].Value           = "";
                    ArrayBuy[i].Cells[2].Style.BackColor = Color.LightGreen;
                    ArrayBuy[i].Cells[1].Style.Font      = new Font(DataGridView.DefaultFont, FontStyle.Regular);
                }
            }
            MThread.InitThread(() =>
            {
                //Синхронизуируем между потоками
                dataGridViewDepth.GuiAsync(() =>
                {
                    if (ArraySell.NotIsNull())
                    {
                        //Наполняем Sell
                        for (int i = 0; i < ArraySell.Length; i++)
                        {
                            var row = ArraySell[i];
                            if (pricesSell.Length <= i)
                            {
                                ArraySell[i].Cells[2].Value = "";
                                ArraySell[i].Cells[1].Value = "";
                                ArraySell[i].Cells[1].Tag   = null;
                                ArraySell[i].Cells[3].Tag   = null;
                                continue;
                            }
                            var ordersByPrice = ordersSell.Where(o => o.Price == pricesSell[i]).ToArray();
                            var volOrders     = ordersByPrice.Sum(o => o.Balance);

                            decimal Price = pricesSell[i];
                            int Volume    = volOrders;
                            int countOrd  = ordersByPrice.Count();

                            ArraySell[i].Cells[2].Value = Price.ToString();
                            ArraySell[i].Cells[1].Value = countOrd.ToString() + " (" + Volume.ToString() + ")";
                            ArraySell[i].Cells[1].Tag   = new StructClickDepth()
                            {
                                Flag   = "sell",
                                Price  = Price,
                                Volume = Volume,
                            };
                            ArraySell[i].Cells[3].Tag = new StructClickDepth()
                            {
                                Flag   = "buy",
                                Price  = Price,
                                Volume = Volume,
                            };
                        }
                    }
                    if (ArrayBuy.NotIsNull())
                    {
                        //Наполняем Buy
                        for (int i = 0; i < ArrayBuy.Length; i++)
                        {
                            var row = ArrayBuy[i];
                            if (pricesBuy.Length <= i)
                            {
                                ArraySell[i].Cells[2].Value = "";
                                ArraySell[i].Cells[1].Value = "";
                                ArraySell[i].Cells[1].Tag   = null;
                                ArraySell[i].Cells[3].Tag   = null;
                                continue;
                            }
                            var ordersByPrice = ordersBuy.Where(o => o.Price == pricesBuy[i]).ToArray();
                            var volOrders     = ordersByPrice.Sum(o => o.Balance);

                            decimal Price = pricesBuy[i];
                            int Volume    = volOrders;
                            int countOrd  = ordersByPrice.Count();

                            ArrayBuy[i].Cells[2].Value = Price.ToString();
                            ArrayBuy[i].Cells[3].Value = countOrd.ToString() + " (" + Volume.ToString() + ")";

                            ArrayBuy[i].Cells[1].Tag = new StructClickDepth()
                            {
                                Flag   = "sell",
                                Price  = Price,
                                Volume = Volume,
                            };
                            ArrayBuy[i].Cells[3].Tag = new StructClickDepth()
                            {
                                Flag   = "buy",
                                Price  = Price,
                                Volume = Volume,
                            };
                        }
                    }
                });
            });
        }