Beispiel #1
0
        private void SetupChartForm(ChartForm child)
        {
            child.MdiParent = this;
            child.bookmarkId = bookmarkStrip.SelectedBookmark.Id;
            child.chart.receiveMarketOrders += () => MarketOrdersStorage.Instance.MarketOrders;
            child.chart.receivePendingOrders += () => MarketOrdersStorage.Instance.PendingOrders;
            child.chart.enforceClosedOrdersUpdate += HistoryOrderStorage.Instance.HurryUpUpdate;
            child.chart.getOuterCharts += GetChartsListByIds;
            child.chart.EnableExtendedVisualStyles = UserSettings.Instance.EnableExtendedThemes;
            child.chart.OnScaleChanged += ChartScaleChanged;
            child.chart.CursorCrossIsUpdated += ChartCrossChanged;
            child.chart.ChartToolChanged += OnChartToolChanged;
            child.chart.PublishTradeSignal += OnPublishTradeSignal;
            child.chart.MakeNewTextSignal += OnMakeNewSignalMessage;
            child.chart.ScriptMenuItemActivated += ChartScriptMenuItemActivated;
            child.chart.getRobotsByTicker += ticker =>
                {
                    var allRobots = RobotFarm.GetRobotCopies();
                    return allRobots.Where(r => r.Graphics.Any(g => g.a == ticker)).Select(r => r.GetUniqueName()).ToList();
                };
            child.chart.onRobotSelected += robotUniqueName =>
                {
                    var state = robotFarm.State;
                    if (state == RobotFarm.RobotFarmState.Started)
                        ShowRobotStateDialog(robotUniqueName);
                    else if (state == RobotFarm.RobotFarmState.Stopped)
                        ShowRobotPortfolioDialog(robotUniqueName);
                };

            AddScriptsToChart(child.chart);

            child.chart.getAccountId += () =>
                {
                    if (AccountStatus.Instance.isAuthorized)
                        return AccountStatus.Instance.accountID;
                    OpenLoginDialog();
                    if (AccountStatus.Instance.isAuthorized)
                        return AccountStatus.Instance.accountID;
                    return null;
                };
            child.chart.makeTrade += MakeTrade;
            child.chart.NewOrder += PlaceNewOrder;
            child.chart.ShowQuoteArchive += delegate(string symbol)
                                                {
                                                    new QuoteBaseForm(symbol).ShowDialog();
                                                };
            child.chart.SyncQuoteHistory += delegate(List<string> tickers, DateTime timeStart, bool showIntervalDlg)
                                                {
                                                    UpdateTickersCacheForRobotsChooseIntervals(
                                                        tickers.ToDictionary(t => t,
                                                                             t => timeStart), showIntervalDlg, true);
                                                };
            child.chart.EditMarketOrders += orderIds => new MultyOrdersEditForm(orderIds).ShowDialog();
            child.chart.getDefaultFastDealVolumes += () => UserSettings.Instance.FastDealVolumes;
            child.chart.getFavoriteIndicators += () => UserSettings.Instance.FavoriteIndicators;
            child.chart.getAllNewsByChannel += channel => NewsLocalStorage.Instance.GetNews(channel);
            child.chart.FavoriteIndicatorsAreUpdated += indis =>
                                                            {
                                                                UserSettings.Instance.FavoriteIndicators = indis.Distinct().ToList();
                                                                UserSettings.Instance.SaveSettings();
                                                            };
            child.chart.UpdateFastVolumes += volumes =>
                                                        {
                                                            UserSettings.Instance.FastDealVolumes = volumes;
                                                            UserSettings.Instance.SaveSettings();
                                                        };
            child.chart.ProfitByTickerRequested += s =>
                                                   new ProfitByTickerForm(s).ShowDialog();
            child.chart.OpenScriptSettingsDialog += () =>
                new ChartToolsSetupForm(lstGlyph32, ChartToolsSetupForm.ChartToolsFormTab.Scripts).ShowDialog();
            child.chart.VisualSettingsSetupCalled += ShowVisualSettingsDialog;
            child.chart.OnShowWindowEditMarketOrder += order => new OrderDlg(OrderDlg.OrderDialogMode.OrderEditMarket, order.ID).ShowDialog();
            child.chart.OnShowWindowInfoOnClosedOrder += order => new PositionForm(order).ShowDialog();
            child.chart.OnEditMarketOrderRequest += order => SendEditMarketRequestSafe(order);
            child.chart.PendingOrdersUpdated += OnPendingOrdersUpdatedChanged;
            child.chart.MarketOrdersUpdated += OnMarketOrdersChanged;
            child.chart.CloseMarketOrders += delegate(List<int> orderList)
                {
                    if (orderList.Count == 0) return;
                    if (orderList.Count == 1)
                    {
                        var accountId = AccountStatus.Instance.accountID;
                        if (accountId == 0) return;
                        if (MessageBox.Show(Localizer.GetString("MessageCloseDealQuestion"), Localizer.GetString("TitleConfirmation"),
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            return;
                        SendCloseRequestSafe(accountId, orderList[0], PositionExitReason.ClosedFromUI);
                        return;
                    }

                    if (MessageBox.Show(
                        string.Format(Localizer.GetString("MessageCloseNDealsQuestion"), orderList.Count),
                        Localizer.GetString("TitleConfirmation"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                        DialogResult.No)
                        return;
                    var dlg = new ClosePositionsForm(orderList);
                    dlg.ShowDialog();
                };
            child.formMoved += OnChildMove;
            child.resizeEnded += OnChildResizeEnd;
            // иконки-кнопки
            var iconSet = UserSettings.Instance.SelectedChartIcons;
            child.chart.ChooseChartIconsToShow(iconSet);

            HistoryOrderStorage.Instance.OrdersUpdated += child.UpdateClosedOrdersListAsynch;
        }
        /// <summary>
        /// разом закрыть пачку сделок (отобразить процесс в диалоговом окошке)
        /// </summary>
        private static void ClosePositions(List<int> orderList)
        {
            if (orderList.Count == 0) return;

            if (orderList.Count == 1)
            {
                var accountId = AccountStatus.Instance.accountID;
                if (accountId == 0) return;
                MainForm.Instance.SendCloseRequestSafe(accountId, orderList[0], PositionExitReason.ClosedFromUI);
                return;
            }

            var dlg = new ClosePositionsForm(orderList);
            dlg.ShowDialog();
        }