Ejemplo n.º 1
0
        //Замена только параметров, которые меняются с формы
        public static void ChangeBaseParam(ref Strategy pStrategy, StrategyParam ReadParam)
        {
            //StrategyType, FreqUpdate
            pStrategy.Param.StrategyName = ReadParam.StrategyName;
            pStrategy.Param.Market       = ReadParam.Market;
            pStrategy.Param.WriteToFile  = ReadParam.WriteToFile;

            pStrategy.Param.BalanceRestBuy.IsPercentSize = ReadParam.BalanceRestBuy.IsPercentSize;
            pStrategy.Param.BalanceRestBuy.Values[0]     = ReadParam.BalanceRestBuy.Values[0];

            pStrategy.Param.BalanceRestSell.IsPercentSize = ReadParam.BalanceRestSell.IsPercentSize;
            pStrategy.Param.BalanceRestSell.Values[0]     = ReadParam.BalanceRestSell.Values[0];

            pStrategy.Param.Interval       = ReadParam.Interval;
            pStrategy.Param.SellOnlyBought = ReadParam.SellOnlyBought;
            pStrategy.Param.Stock          = ReadParam.Stock;
        }
        public void AddNewStrategy(StrategyParam SParam)
        {
            if (SParam == null)
            {
                return;
            }
            Strategy nStrategy = StrategyTool.GetStrategyByName(SParam.StrategyType, "");

            if (nStrategy == null)
            {
                System.Media.SystemSounds.Beep.Play();
                Print("Ошибка: неправильный тип стратегии - " + SParam.StrategyType);
                return;
            }
            StrategyTool.ChangeBaseParam(ref nStrategy, SParam);
            StrategiesList.Add(nStrategy.Param.StrategyName, nStrategy);
            nStrategy.SaveData();
        }
        /// <summary>
        /// Считать параметры стратегии с формы
        /// </summary>
        /// <returns></returns>
        private StrategyParam ReadStrategyParam(bool ForSave)
        {
            try
            {
                if (strategyName.Text == "" || strategyMarket.Text == "" || strategyBuyValue.Text == "" ||
                    strategySellValue.Text == "")
                {
                    System.Media.SystemSounds.Beep.Play();
                    Print("Заполнены не все поля!", false);
                    return(null);
                }

                if (!SManager.CheckNameValid(strategyName.Text, ForSave))
                {
                    System.Media.SystemSounds.Beep.Play();
                    Print("Такое название уже существует!", false);
                    return(null);
                }

                Market sMarket = null;
                try
                {
                    sMarket = Market.LoadFromString(strategyMarket.Text);
                }
                catch (Exception ex)
                {
                    System.Media.SystemSounds.Beep.Play();
                    Print("Не удалось считать торговую пару! " + ex.Message);
                    return(null);
                }

                //ограничения покупки
                double ValueRestBuy = 0;
                if (!String.IsNullOrEmpty(strategyBuyValue.Text))
                {
                    ValueRestBuy = Convert.ToDouble(strategyBuyValue.Text.Replace(',', '.'), CultureInfo.InvariantCulture);
                }
                var balRestBuy = new ExTool.StepRepresent(1)
                {
                    Values = new List <double>()
                    {
                        ValueRestBuy
                    },
                    IsPercentSize = strategyBuyIsPerc.Checked ? true : false
                };

                //ограничения продажи
                double ValueRestSell = 0;
                if (!String.IsNullOrEmpty(strategySellValue.Text))
                {
                    ValueRestSell = Convert.ToDouble(strategySellValue.Text.Replace(',', '.'), CultureInfo.InvariantCulture);
                }

                var balRestSell = new ExTool.StepRepresent(1)
                {
                    Values = new List <double>()
                    {
                        ValueRestSell
                    },
                    IsPercentSize = strategySellIsPerc.Checked ? true : false,
                };

                var Param = new StrategyParam
                {
                    StrategyName    = strategyName.Text,
                    StrategyType    = AllStrategies[strategyType.SelectedItem.ToString()],
                    Market          = sMarket,
                    BalanceRestBuy  = balRestBuy,
                    BalanceRestSell = balRestSell,
                    Interval        = (Candle_Interval)strategyInterval.SelectedIndex,
                    SellOnlyBought  = strategySellBought.Checked,
                    WriteToFile     = checkBox2.Checked,
                    Stock           = ExTool.StockByName(comboBox1.SelectedItem.ToString())
                };
                return(Param);
            }
            catch (Exception ex)
            {
                System.Media.SystemSounds.Beep.Play();
                Print("Ошибка считывания параметров: " + ex.Message);
                return(null);
            }
        }