Esempio n. 1
0
 public override ChartIcon MakeCopy()
 {
     var cpy = new ChartIconDropDown
                   {
                       Owner = Owner,
                       listControl = new DropDownList(listControl),
                       key = key,
                       Position = Position,
                       Size = Size
                   };
     return cpy;
 }
        public override ChartIcon MakeCopy()
        {
            var cpy = new ChartIconDropDown
            {
                Owner       = Owner,
                listControl = new DropDownList(listControl),
                key         = key,
                Position    = Position,
                Size        = Size
            };

            return(cpy);
        }
        private void SetupFavIndicatorsList(ChartIconDropDown btn)
        {
            var descriptions = new List<object>();
            var favIndis = getFavoriteIndicators();
            foreach (var t in PluginManager.Instance.typeIndicators)
            {
                if (!favIndis.Contains(t.Name)) continue;
                var attrName = (DisplayNameAttribute)Attribute.GetCustomAttribute(t,
                    typeof(DisplayNameAttribute));
                if (attrName == null) continue;
                descriptions.Add(new IndicatorDescription(attrName.DisplayName, "", false)
                    {
                        indicatorType = t
                    });
            }

            btn.listControl.Values = descriptions;
        }
        private void SetupFastTradeButton(ChartIconDropDown buySell)
        {
            var side = buySell.key == ChartIcon.ChartIcon.chartButtonFastBuy;
            buySell.Owner = chart;
            buySell.listControl.Formatter = val =>
                                                {
                                                    return val is string ? (string) val
                                                        : ((int) val).ToStringUniformMoneyFormat();
                                                };
            SetFastBuySellOptions(buySell, side);

            buySell.listControl.cellClicked += (obj, text) =>
                                                   {
                                                       var strVolume = (string) obj;
                                                       var parts = strVolume.Split(new [] { " - "}, StringSplitOptions.RemoveEmptyEntries);

                                                       if (parts.Length != 3)
                                                       {// показать диалог настройки объемов
                                                            var volumesString = string.Join(", ", getDefaultFastDealVolumes());
                                                            DialogResult rst;
                                                            var str = Dialogs.ShowInputDialog("Укажите объемы входа",
                                                                                        "объемы", true,
                                                                                        volumesString, out rst);
                                                            if (rst != DialogResult.OK) return;
                                                            var volumes = str.ToIntArrayUniform();
                                                            if (volumes.Length == 0) return;

                                                            // сохранить объемы
                                                            updateFastVolumes(volumes);

                                                            // обновить список
                                                            foreach (var btn in chart.StockPane.customButtons.Where(
                                                                b => b.key == ChartIcon.ChartIcon.chartButtonFastBuy ||
                                                                b.key == ChartIcon.ChartIcon.chartButtonFastSell))
                                                            {
                                                                SetFastBuySellOptions((ChartIconDropDown) btn,
                                                                                        btn.key == ChartIcon.ChartIcon.chartButtonFastBuy);
                                                            }

                                                            return;
                                                       }

                                                       // торгануть
                                                       var volm = parts[1].Replace(" ", "").ToIntSafe() ?? 0;

                                                        var sign = side ? DealType.Buy : DealType.Sell;
                                                        if (makeTrade != null)
                                                            makeTrade(sign, Symbol, volm);
                                                    };
        }
        private void SetFastBuySellOptions(ChartIconDropDown buySell, bool sideBuy)
        {
            const string strMoreOptions = "другое значение...";
            var lstValues = new List<object> {strMoreOptions};
            lstValues.AddRange(getDefaultFastDealVolumes().Select(vlm =>
                string.Format("{0} - {1} - {2}",
                    sideBuy ? "BUY" : "SELL", vlm.ToStringUniformMoneyFormat(), Symbol)));

            buySell.listControl.Values = lstValues;
            buySell.listControl.Formatter = val =>
                                                {
                                                    return val is string ? (string) val
                                                        : ((int) val).ToStringUniformMoneyFormat();
                                                };
        }
        private static void SetupChartIcons()
        {
            // забубенить кнопкам картинки
            var imageKeyByName = new Dictionary<string, string[]>
                {
                    { ChartIcon.ChartIcon.chartButtonStatByTicker, new [] { "ico_calculator.png" } },
                    { ChartIcon.ChartIcon.chartButtonDealByTicker, new [] { "ico_black_orders.png" } },
                    { ChartIcon.ChartIcon.chartButtonFastBuy, new [] { "ico_black_up.png" } },
                    { ChartIcon.ChartIcon.chartButtonFastSell, new [] { "ico_black_down.png" } },
                    { ChartIcon.ChartIcon.chartButtonFavIndicators, new [] { "ico_black_favourite.png" } },
                    { ChartIcon.ChartIcon.chartButtonIndexAutoScroll, new [] { "ico_black_forward.png", "ico_black_pause.png" } },
                    { ChartIcon.ChartIcon.chartButtonIndicators, new [] { "ico_black_indicator.png" } },
                    { ChartIcon.ChartIcon.chartButtonNewOrder, new [] { "ico_black_dollar.png" } },
                    { ChartIcon.ChartIcon.chartButtonPatchQuotes, new [] { "ico_black_synch.png" } },
                    { ChartIcon.ChartIcon.chartButtonQuoteArchive, new [] { "ico_black_archive.png" } },
                    { ChartIcon.ChartIcon.chartVisualSettings, new [] { "ico_makeup.png" } },
                    { ChartIcon.ChartIcon.chartProfitByTicker, new [] { "ico_profit_ticker.png" } },
                    { ChartIcon.ChartIcon.chartRobot, new [] { "ico_robot.png" } },
                };

            foreach (var img in imageKeyByName)
            {
                var imgCollection = new ChartIcon.ChartIcon.ButtonImageCollection
                    {
                        images = new Bitmap[2,img.Value.Length]
                    };

                for (var i = 0; i < img.Value.Length; i++)
                {
                    // загрузить картинку и создать ее инверсную копию
                    var fullName = "Candlechart.images." + img.Value[i];
                    Bitmap imgNormal, imgInverse;
                    LoadImageFromResxAndMakeInverseCopy(fullName, out imgNormal, out imgInverse);
                    imgCollection.images[0, i] = imgNormal;
                    imgCollection.images[1, i] = imgInverse;
                }
                ChartIcon.ChartIcon.AddButtonImages(img.Key, imgCollection);
            }

            var iconStatByTicker = new ChartIconDropDownDialog
            {
                key = ChartIcon.ChartIcon.chartButtonStatByTicker
            };
            var iconAscroll = new ChartIconCheckBox(null)
            {
                key = ChartIcon.ChartIcon.chartButtonIndexAutoScroll
            };
            var iconIndi = new ChartIcon.ChartIcon((obj, e) => { })
            {
                key = ChartIcon.ChartIcon.chartButtonIndicators
            };
            var iconOrder = new ChartIcon.ChartIcon((obj, e) => { })
            {
                key = ChartIcon.ChartIcon.chartButtonNewOrder
            };
            var iconArchive = new ChartIcon.ChartIcon((obj, e) => { })
            {
                key = ChartIcon.ChartIcon.chartButtonQuoteArchive
            };
            var iconPatchQuotes = new ChartIcon.ChartIcon((obj, e) => { })
            {
                key = ChartIcon.ChartIcon.chartButtonPatchQuotes
            };
            var iconFavIndi = new ChartIconDropDown
            {
                key = ChartIcon.ChartIcon.chartButtonFavIndicators
            };
            var iconFastSell = new ChartIconDropDown
            {
                key = ChartIcon.ChartIcon.chartButtonFastSell
            };
            var iconFastBuy = new ChartIconDropDown
            {
                key = ChartIcon.ChartIcon.chartButtonFastBuy
            };
            var iconFastOrders = new ChartIconDropDown
            {
                key = ChartIcon.ChartIcon.chartButtonDealByTicker
            };
            var iconVisual = new ChartIcon.ChartIcon((obj, e) => { })
            {
                key = ChartIcon.ChartIcon.chartVisualSettings
            };
            var iconProfitByTicker = new ChartIcon.ChartIcon((obj, e) => { })
            {
                key = ChartIcon.ChartIcon.chartProfitByTicker
            };
            var iconRobots = new ChartIconDropDown
            {
                key = ChartIcon.ChartIcon.chartRobot
            };
            iconFastOrders.listControl.columns = new List<FastColumn>
                {
                    new FastColumn("") {ColumnWidth = 38},
                    new FastColumn("") {ColumnWidth = 72},
                    new FastColumn("") {ColumnWidth = 48},
                    new FastColumn("") {ColumnWidth = 73},
                    new FastColumn("") {ColumnWidth = 73}
                };
            iconFastOrders.listControl.MinWidth = iconFastOrders.listControl.columns.Sum(c => c.ColumnWidth);
            iconFastOrders.listControl.MaxWidth = iconFastOrders.listControl.MinWidth;
            iconFastOrders.listControl.Width = iconFastOrders.listControl.MinWidth;
            iconFastOrders.listControl.CalcWidthAuto = false;

            // добавить все в массив
            allChartIcons.Add(iconStatByTicker);
            allChartIcons.Add(iconFastOrders);
            allChartIcons.Add(iconAscroll);
            allChartIcons.Add(iconIndi);
            allChartIcons.Add(iconOrder);
            allChartIcons.Add(iconArchive);
            allChartIcons.Add(iconFavIndi);
            allChartIcons.Add(iconFastSell);
            allChartIcons.Add(iconFastBuy);
            allChartIcons.Add(iconPatchQuotes);
            allChartIcons.Add(iconVisual);
            allChartIcons.Add(iconProfitByTicker);
            allChartIcons.Add(iconRobots);

            allChartIcons.ForEach(i =>
                {
                    i.Size = new Size(22, 22);
                });
        }