public Form1() { InitializeComponent(); Print = new InvokePrint(MPrint); SManager = new StrategyManager(Print, OnActiveStartegyChangeState); foreach (var strat in AllStrategies) { strategyType.Items.Add(strat.Key); } strategyType.SelectedIndex = 0; strategyInterval.SelectedIndex = 0; Languages.SelectedIndex = 0; ReadFormSettings(); ChangeSetting(FSetting); foreach (var StockKeys in FSetting.AllApiKeys) { var StockObject = ExTool.StockByName(StockKeys.StockName); if (StockObject != null) { var stocktype = StockObject.GetType(); var MInfo = stocktype.GetMethod("SetApiKeys", BindingFlags.Public | BindingFlags.Static); MInfo.Invoke(null, new object[] { StockKeys.Public, StockKeys.Secret }); AllStocks.Add(StockObject); } else { System.Media.SystemSounds.Beep.Play(); Print("Ошибка: тип биржи " + StockKeys.StockName + " не найдено!"); } } foreach (var stock in AllStocks) { comboBox1.Items.Add(stock.GetStockName()); } comboBox1.SelectedIndex = 0; SManager.ReadStrategies(); foreach (string item in SManager.StrategiesList.Keys) { listBox2.Items.Add(item); } if (listBox2.Items.Count > 0) { listBox2.SelectedIndex = listBox2.Items.Count - 1; } }
public virtual void LoadData(Dictionary <string, string> dict) { StrategyName = dict["StrategyName"]; StrategyType = dict["StrategyType"]; Stock = ExTool.StockByName(dict["Stock"]); Market = Market.LoadFromString(dict["Market"]); BalanceRestBuy = ExTool.StepRepresent.LoadFromString(dict["BalanceRestBuy"]); BalanceRestSell = ExTool.StepRepresent.LoadFromString(dict["BalanceRestSell"]); if (Enum.TryParse(dict["Interval"], out Candle_Interval interval)) { Interval = interval; } else { throw new Exception("не удалось считать интервал."); } FreqUpdate = Convert.ToInt32(dict["FreqUpdate"]); SellOnlyBought = Convert.ToBoolean(dict["SellOnlyBought"]); WriteToFile = Convert.ToBoolean(dict["WriteToFile"]); }
/// <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); } }