private IInteractiveLine GetInteractiveLine(IGraphPane pane, IReadOnlyList <IDataBar> bars)
        {
            var minDate              = bars.First().Date;
            var maxDate              = bars.Last().Date;
            var interactiveLine      = (IInteractiveLine)pane.GetInteractiveObject(VariableId);
            var intColor             = ColorParser.Parse(Color);
            var firstMarketPosition  = new MarketPoint(FirstDateTime.Value, FirstValue.Value);
            var secondMarketPosition = new MarketPoint(SecondDateTime.Value, SecondValue.Value);

            if (interactiveLine != null)
            {
                interactiveLine.ExecutionDataBars = bars;
                CorrectMarketPointsEx(ref firstMarketPosition, ref secondMarketPosition, minDate, maxDate);

                if (interactiveLine.PaneSides == PaneSide && interactiveLine.Color == intColor && interactiveLine.Mode == Mode)
                {
                    pane.AddUnremovableInteractiveObjectId(VariableId);
                    interactiveLine.Thickness = Thickness;
                    interactiveLine.FirstPoint.MarketPosition  = firstMarketPosition;
                    interactiveLine.SecondPoint.MarketPosition = secondMarketPosition;
                    return(m_interactiveLine = interactiveLine);
                }
                pane.RemoveInteractiveObject(VariableId);
            }
            else
            {
                CorrectMarketPointsEx(ref firstMarketPosition, ref secondMarketPosition, minDate, maxDate);
            }

            m_interactiveLine                   = pane.AddInteractiveLine(VariableId, PaneSide, false, intColor, Mode, firstMarketPosition, secondMarketPosition);
            m_interactiveLine.Thickness         = Thickness;
            m_interactiveLine.ExecutionDataBars = bars;
            return(m_interactiveLine);
        }
Exemple #2
0
        private void DrawTrades(ISecurity sec, IGraphPane pane)
        {
            // TODO: нужна такая проверка?
            //if (!sec.IsRealtime)
            //{
            //    string msg = RM.GetStringFormat("OptHandlerMsg.PositionsManager.RunAsAgent",
            //        Context.Runtime.TradeName + ":" + MsgId, sec.IsRealtime);
            //    Context.Log(msg, MessageType.Warning, true);
            //    return;
            //}

            //// Позиций нет? Выходим. Ловить нечего.
            //if (sec.Positions.HavePositions)
            //    return;

            // В оптимизации ничего рисовать не надо
            if (Context.IsOptimization)
            {
                return;
            }

            // 0. Чистим за собой мусор от предыдущих прогонов?
            var oldObjects = pane.GetInteractiveObjects(); // Клонирование делается внутри метода

            foreach (var oldObj in oldObjects)
            {
                var oldPoint = oldObj as GraphPane.IInteractivePoint;
                if (oldPoint != null)
                {
                    if (oldPoint.Id.StartsWith(ExecutedOrdPrefix))
                    {
                        pane.RemoveInteractiveObject(oldPoint.Id);
                    }
                    continue;
                }

                var oldLine = oldObj as GraphPane.IInteractiveLine;
                if (oldLine != null)
                {
                    if (oldLine.Id.StartsWith(ActiveOrdPrefix))
                    {
                        pane.RemoveInteractiveObject(oldLine.Id);
                    }
                    continue;
                }
            }

            ISecurityRt secRt;

            if (sec is ISecurityRt)
            {
                secRt = (ISecurityRt)sec;
            }
            else
            {
                secRt = (from s in Context.Runtime.Securities
                         where s.SecurityDescription.Equals(sec) && (s is ISecurityRt)
                         select(ISecurityRt) s).SingleOrDefault();
            }

            if (secRt == null)
            {
                return;
            }

            // ОТЛИЧНО! Эта коллекция позволит мне нарисовать свои заявки и сделки
            var orders         = secRt.Orders.ToList();
            var activeOrders   = new List <IOrder>();
            var executedOrders = new List <IOrder>();

            for (int j = 0; j < orders.Count; j++)
            {
                IOrder ord = orders[j];
                if (ord.IsActive)
                {
                    activeOrders.Add(ord);
                }
                else if (ord.Status == OrderStatus.Executed)
                {
                    executedOrders.Add(ord);
                }
                else
                {
                    //string str = "Все остальное игнорируем?";
                }
            }

            int      id          = 0;
            IDataBar lastBar     = sec.Bars.LastOrDefault();
            int      intervalSec = Context.Runtime.IntervalInstance.ToSeconds();
            DateTime now         = (lastBar != null) ? lastBar.Date : (sec.FinInfo != null) ? sec.FinInfo.LastUpdate : DateTimeUtils.Now;

            // 1. Рисуем активные заявки в виде линий
            foreach (IOrder ord in activeOrders)
            {
                string itemId    = ActiveOrdPrefix + id;
                var    end       = new GraphPane.MarketPoint(now, ord.Price);
                var    beg       = new GraphPane.MarketPoint(now.AddSeconds(-10 * intervalSec), ord.Price);
                Color  actualCol = ord.IsBuy ? s_green : s_red;
                pane.AddInteractiveLine(itemId, PaneSides.RIGHT, true, actualCol,
                                        GraphPane.InteractiveLineMode.Finite, beg, end);

                id++;
            }

            // 2. Рисуем исполненные заявки в виде точек
            foreach (IOrder ord in executedOrders)
            {
                string itemId    = ExecutedOrdPrefix + id;
                Color  actualCol = ord.IsBuy ? s_green : s_red;
                var    point     = new GraphPane.MarketPoint(ord.Date, ord.Price);
                pane.AddInteractivePoint(itemId, PaneSides.RIGHT, true, actualCol, point);

                id++;
            }

            //var point = new GraphPane.MarketPoint(DateTime.Now, 50000);
            //pane.AddInteractivePoint("0", PaneSides.RIGHT, true, new Color(255, 0, 0), point);
        }