/// <summary> /// Продолжить /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click_1(object sender, EventArgs e) { var CurStrategy = SManager.ActiveStrategy; if (CurStrategy == null) { return; } try { string OldName = CurStrategy.Param.StrategyName; var dictParam = IniTool.ReadSectionParams(CurStrategy.UniqueID); CurStrategy.Param.LoadData(dictParam); CheckStrategyRename(OldName, CurStrategy.Param.StrategyName); var dictState = IniTool.ReadSectionStates(CurStrategy.UniqueID); CurStrategy.State.LoadData(dictState); } catch (Exception ex) { System.Media.SystemSounds.Beep.Play(); Print(String.Format("Ошибка чтения настроек из ini файла: {0}", ex.Message)); return; } ThreadPool.QueueUserWorkItem((x) => CurStrategy.Start(false)); }
/// <summary> /// Прочитать глобальные настройки из ini файла /// </summary> private void ReadFormSettings() { if (File.Exists(IniTool.IniFnameParams)) { try { var data = IniTool.ReadSectionParams("FormSettings"); FSetting.LoadFromDictionary(data); } catch (Exception ex) { System.Media.SystemSounds.Beep.Play(); Print("Ошибка чтения FormSettings: " + ex.Message); FSetting = new FormSettings(); IniTool.ChangeValueParam("FormSettings", FSetting.DataAsDictionary()); return; } } else { var fileIniData = new FileIniDataParser(); var newParsedData = new IniData(); fileIniData.WriteFile(IniTool.IniFnameParams, newParsedData); FSetting = new FormSettings(); IniTool.ChangeValueParam("FormSettings", FSetting.DataAsDictionary()); } }
/// <summary> /// Сохранить /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { string sname = comboBox1.SelectedItem.ToString(); //внести изменения в выбранную биржу bool NeedUpdate = false; FormSettings.ApiKeys CurApiKeys = FSettings.AllApiKeys.First(t => t.StockName == sname); if (CurApiKeys == null) { System.Media.SystemSounds.Beep.Play(); Print("Ошибка: ключи апи для " + sname + " не найдены!"); return; } string NewPublic = textBox6.Text.Trim(); string NewSecret = textBox5.Text.Trim(); if (CurApiKeys.Public != NewPublic || CurApiKeys.Secret != NewSecret) //применить измененния { CurApiKeys.Public = NewPublic; CurApiKeys.Secret = NewSecret; SetApiKeys(CurApiKeys); NeedUpdate = true; } if (FSettings.FormName != textBox1.Text) { FSettings.FormName = textBox1.Text; NeedUpdate = true; } if (NeedUpdate) { OnChangeSettings(FSettings); IniTool.ChangeValueParam("FormSettings", FSettings.DataAsDictionary()); } }
public void SaveData(bool NotOnlyState = true) //сохранить параметры и состояние в файл { var StrategyData = new Dictionary <string, string>(); if (NotOnlyState) { Param.GetData(ref StrategyData); IniTool.ChangeValueParam(UniqueID, StrategyData); StrategyData.Clear(); } State.GetData(ref StrategyData); IniTool.ChangeValueState(UniqueID, StrategyData); }
public virtual event EventHandler <ActiveOrdersGridEventArgs> ChangeActiveOrders; //изменение ордеров в позиции стратегии public Strategy(string uniqueID) { if (uniqueID == "") { var rand = new Random(); string stmp = ""; for (int i = 0; i < 10; i++) { stmp += rand.Next(1, Int32.MaxValue); } uniqueID = IniTool.ConvertName(stmp); } UniqueID = uniqueID; Print = new InvokePrint(PrintMethod); }
/// <summary> /// Удалить /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonDelete_Click(object sender, EventArgs e) { var CurStrategy = SManager.ActiveStrategy; if (CurStrategy == null) { return; } if (CurStrategy.State.IsStartegyRun) { buttonStop_Click(null, null); var tbegin = DateTime.UtcNow; while (DateTime.UtcNow.Subtract(tbegin) < TimeSpan.FromSeconds(5) && CurStrategy.State.IsStartegyRun) { Thread.Sleep(200); } if (CurStrategy.State.IsStartegyRun) { var result = MessageBox.Show("Не удалось остановить стратегию. Все равно удалить?", "Удаление стратегии", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } } string sectname = CurStrategy.UniqueID; IniTool.RemoveFromParams(sectname); IniTool.RemoveFromStates(sectname); SManager.RemoveStrategy(CurStrategy.Param.StrategyName); int index = listBox2.SelectedIndex; listBox2.Items.RemoveAt(index); if (listBox2.Items.Count > 0) { listBox2.SelectedIndex = (index - 1) >= 0 ? index - 1 : 0; } }