Exemplo n.º 1
0
        /// <summary> Инициализация нового инструмента в текущем окне. Сброс на новый инструмент.</summary>
        private void InitReset()
        {
            this.Portfolio = this.Trader.Objects.Portfolios.FirstOrDefault(p => p.Account.AccClasses.FirstOrDefault(c => c == this.TrElement.Security.Class) != null);
            this.Position  = Trader.Objects.Positions.FirstOrDefault(s => s.Sec == this.TrElement.Security);

            Trader.RegisterDepth(this.TrElement.Security);
            Trader.RegisterSecurities(this.TrElement.Security);

            if (this.TrElement.OnNewCandle.IsNull())
            {
                this.TrElement.OnNewCandle += (tf, candle) =>
                {
                    if (tf == this.CurrentTimeFrame)
                    {
                        this.GetHorVol();
                    }
                };
            }

            //цена для заявки
            numericUpDownPrice.Increment     = this.TrElement.Security.Params.MinPriceStep;
            numericUpDownPrice.DecimalPlaces = this.TrElement.Security.Scale;

            //Стоп цена
            numericUpDownStopPrice.Increment     = this.TrElement.Security.Params.MinPriceStep;
            numericUpDownStopPrice.DecimalPlaces = this.TrElement.Security.Scale;

            this.Text = "(" + this.TrElement.Security.Code + ":" + this.TrElement.Security.Class.Code + ") " + this.TrElement.Security.Name;

            //Сброс цены на заявку
            numericUpDownPrice.Value = 0;
            //Сброс стоп цены
            numericUpDownStopPrice.Value = 0;

            //Настройки графика
            this.GraphicStock = new NSGraphic.Graphic(TrElement.Security.Params.MinPriceStep);
            //Задаем в графике точность цены
            GraphicStock.PanelPrices.CountFloat = this.TrElement.Security.Scale;
            //Скрол для графика
            hScrollGraphic.Value = hScrollGraphic.Maximum;

            //Clear depth
            dataGridViewDepth.Rows.Clear();
            this.ArraySell = null;
            this.ArrayBuy  = null;
            this.SetDataDepth(null);

            //Обновим панель заявок
            this.UpdatePanelOrders();

            pictureBoxGraphic.Refresh();
        }
Exemplo n.º 2
0
        void UpdateInfoPositions()
        {
            if (Trader.Objects.tPositions.Count > 0)
            {
                dataGridPositions.GuiAsync(() =>
                {
                    var listPos    = Trader.Objects.tPositions.ToArray().OrderBy(p => p.Sec.ToString());
                    string lastSec = null;
                    foreach (var p in listPos)
                    {
                        if (p.Sec.NotIsNull() && lastSec != p.ToString())
                        {
                            lastSec = p.ToString();
                            var row = listRowsPositions.FirstOrDefault(r => r.Tag.ToString() == lastSec);
                            if (row.IsNull())
                            {
                                var newRow            = (DataGridViewRow)dataGridPositions.Rows[0].Clone();
                                newRow.Cells[0].Value = "";
                                listRowsPositions.Add(newRow);
                                row = newRow;
                                Trader.RegisterSecurities(p.Sec);
                            }
                            //Ищем все позиции данного инструмента
                            var allSecPos = listPos.Where(ps => ps.Sec == p.Sec && ps.Client.Code == p.Client.Code)
                                            .OrderBy(ps => ps.Data.Type)
                                            .ToArray();
                            if (allSecPos.NotIsNull() && allSecPos.Length > 0)
                            {
                                var types  = "";
                                var curPos = "";
                                //dataGridPositions.Rows.Clear();
                                foreach (var itemPos in allSecPos)
                                {
                                    types += types.Empty()
                                        ? itemPos.Data.Type.ToString()
                                        : "/" + itemPos.Data.Type.ToString();
                                    curPos += curPos.Empty()
                                        ? itemPos.Data.CurrentNet.ToString()
                                        : "/" + itemPos.Data.CurrentNet.ToString();
                                }

                                row.Tag            = lastSec;
                                row.Cells[0].Value = p.Sec.Name;
                                row.Cells[1].Value = p.Client.NotIsNull() ? p.Client.Code + " " + types : "";
                                row.Cells[2].Value = p.Sec.ToString();
                                row.Cells[3].Value = p.Sec.Lot.ToString();
                                row.Cells[4].Value = p.Sec.StepPrice.ToString();
                                row.Cells[5].Value = p.Sec.Params.BuyDepo.ToString();
                                row.Cells[6].Value = curPos;// p.Data.CurrentNet.ToString();
                                setColorRow(row.Cells[6], p.Data.CurrentNet);
                                //Orders
                                row.Cells[7].Value = p.Data.OrdersBuy.ToString() + " / " + p.Data.OrdersSell.ToString();
                                //Var margin
                                row.Cells[8].Value = p.Data.VarMargin.ToString();
                                setColorRow(row.Cells[8], p.Data.VarMargin);
                            }
                        }
                    }
                    if (dataGridPositions.Rows.Count - 1 != listRowsPositions.Count)
                    {
                        dataGridPositions.Rows.Clear();
                        dataGridPositions.Rows.AddRange(listRowsPositions.OrderBy(r => r.Cells[0].Value).ToArray());
                        //dataGridPositions.Sort(dataGridPositions.Columns["NamePos"], ListSortDirection.Ascending);
                        dataGridPositions.Update();
                    }
                });
            }
        }