Exemplo n.º 1
0
        private void CreatePortfolioButtonClick(object sender, EventArgs e)
        {
            var portfolioName = "TOP " + AccountModel.Instance.GetUserLogin();
            if (portfolioName.Length > 50)
                portfolioName = portfolioName.Substring(0, 50);
            var portfolio = new TopPortfolio
                {
                    Name = portfolioName,
                    Criteria = SelectedFunction.Function,
                    DescendingOrder = SelectedFunction.PreferredSortOrder == SortOrder.Descending,
                    MarginValue = SelectedFunction.MarginValue,
                    ParticipantCount = ParticipantCount
                };

            var complete = new CompleteSubscribeOnPortfolioDlg(portfolio).ShowDialog() == DialogResult.OK;
            if (!complete) return;

            // открыть диалог настройки авто-торговли
            var dlg = new AutoTradeSettingsForm();
            if (dlg.ShowDialog(this) != DialogResult.OK)
                return;
            var tradeSettings = dlg.sets;

            RequestStatus status;
            try
            {
                status =
                    AccountModel.Instance.ServerProxy.SubscribeOnPortfolio(
                        CurrentProtectedContext.Instance.MakeProtectedContext(),
                        AccountModel.Instance.GetUserLogin(), portfolio, null, tradeSettings);
            }
            catch (Exception ex)
            {
                //4 debug
                MessageBox.Show(this, "Операция выполнена с ошибкой:" + Environment.NewLine + ex.Message, "Предупреждение",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Logger.Info("TopPortfolioControl.Subscribe: error calling SubscribeOnPortfolio/UnsubscribePortfolio", ex);
                return;
            }
            if (status == RequestStatus.OK)
                MessageBox.Show(this, "Операция выполнена успешно", "Информация", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            else
                MessageBox.Show(this,
                                "Операция выполнена с ошибкой:" + Environment.NewLine +
                                EnumFriendlyName<RequestStatus>.GetString(status), "Предупреждение", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
        }
 // copied from TopPortfolioControl
 private void SetupButtonClick(object sender, EventArgs e)
 {
     try
     {
         var subscribedPortfolio = TradeSharpAccountStatistics.Instance.proxy.GetSubscribedTopPortfolio(
             AccountModel.Instance.GetUserLogin());
         var form = new AutoTradeSettingsForm(subscribedPortfolio.TradeSettings);
         if (form.ShowDialog(this) == DialogResult.Cancel)
             return;
         var status = AccountModel.Instance.ServerProxy.ApplyPortfolioTradeSettings(
             CurrentProtectedContext.Instance.MakeProtectedContext(),
             AccountModel.Instance.GetUserLogin(), form.sets);
         if (status == RequestStatus.OK)
             MessageBox.Show(this, "Операция выполнена успешно", "Информация", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
         else
             MessageBox.Show(this,
                             "Операция выполнена с ошибкой:" + Environment.NewLine +
                             EnumFriendlyName<RequestStatus>.GetString(status), "Ошибка",
                             MessageBoxButtons.OK,
                             MessageBoxIcon.Exclamation);
     }
     catch (Exception ex)
     {
         //4 debug
         MessageBox.Show(this, "Операция выполнена с ошибкой:" + Environment.NewLine + ex.Message, "Ошибка",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         Logger.Info("TopSubscriptionControl.SetupButtonClick: error calling ApplyPortfolioTradeSettings", ex);
         return;
     }
 }
Exemplo n.º 3
0
 private void EditTradeSettings()
 {
     if (selectedCategory == null) return;
     var dlg = new AutoTradeSettingsForm(selectedCategory.AutoTradeSettings);
     if (dlg.ShowDialog() == DialogResult.Cancel)
         return;
     selectedCategory.AutoTradeSettings = dlg.sets;
     SubscriptionModel.Instance.ModifySubscription(selectedCategory);
 }
Exemplo n.º 4
0
        /// <summary>
        /// подписаться или отписаться от получения торговых сигналов
        /// </summary>
        /// <param name="performer">сигнальщик</param>
        /// <param name="tradeAuto">оказать диалог автоторговли</param>
        public static bool SubscribeOrUnsubscribe(PerformerStat performer, bool? tradeAuto)
        {
            var isSubscribed = SubscriptionModel.Instance.SubscribedCategories.Any(s => s.Service == performer.Service);
            var isOk = isSubscribed ? Unsubscribe(performer) : Subscribe(performer, tradeAuto ?? false);

            if (!isOk) return false;

            if (!isSubscribed && (tradeAuto ?? false))
            {
                // показать диалог настройки авто-торговли
                var cat = SubscriptionModel.Instance.SubscribedCategories.FirstOrDefault(
                    c => c.Service == performer.Service);
                if (cat == null)
                    return false;
                var dlg = new AutoTradeSettingsForm(cat.AutoTradeSettings ?? new AutoTradeSettings());
                if (dlg.ShowDialog() != DialogResult.OK)
                    return false;
                cat.AutoTradeSettings = dlg.sets;
            }
            else
            {
                // предупредить пользователя - изменения вступят в силу не мгновенно
                var msg = "Вы " + (isSubscribed
                                   ? "отказались от получения торговых сигналов \""
                                   : "подписались на получение торговых сигналов\n \"") + performer.TradeSignalTitle + "\"";
                MessageBox.Show(msg);
            }

            return true;
        }
Exemplo n.º 5
0
        private void Subscribe(object sender, EventArgs e)
        {
            RequestStatus status;
            try
            {
                if (isSubsribed)
                {
                    status =
                        AccountModel.Instance.ServerProxy.UnsubscribePortfolio(
                            CurrentProtectedContext.Instance.MakeProtectedContext(),
                            AccountModel.Instance.GetUserLogin(), true, true);
                }
                else
                {
                    var complete = new CompleteSubscribeOnPortfolioDlg(portfolio).ShowDialog() == DialogResult.OK;
                    if (!complete) return;

                    var tradeSettings = new AutoTradeSettings();
                    // открыть диалог настройки авто-торговли
                    var dlg = new AutoTradeSettingsForm();
                    if (dlg.ShowDialog(this) == DialogResult.OK)
                        tradeSettings = dlg.sets;
                    status =
                        AccountModel.Instance.ServerProxy.SubscribeOnPortfolio(
                            CurrentProtectedContext.Instance.MakeProtectedContext(),
                            AccountModel.Instance.GetUserLogin(), portfolio, null, tradeSettings);
                }
            }
            catch (Exception ex)
            {
                //4 debug
                MessageBox.Show(this, "Операция выполнена с ошибкой:" + Environment.NewLine + ex.Message, Localizer.GetString("TitleWarning"),
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Logger.Info("TopPortfolioControl.Subscribe: error calling SubscribeOnPortfolio/UnsubscribePortfolio", ex);
                return;
            }
            if (status == RequestStatus.OK)
                MessageBox.Show(this, "Операция выполнена успешно", Localizer.GetString("TitleInformation"), MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            else
                MessageBox.Show(this,
                                "Операция выполнена с ошибкой:" + Environment.NewLine +
                                EnumFriendlyName<RequestStatus>.GetString(status), Localizer.GetString("TitleWarning"), MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            IsSubsribed = !isSubsribed;
            if (SubscriptionChanged != null)
                SubscriptionChanged(this, new EventArgs());
        }