/// <summary> /// 初始化。 /// </summary> public void Initialize() { try { if (m_dataAccessor == null) { throw new ApplicationException("未设定数据访问器"); } USeSystemSetting systemSetting = m_dataAccessor.GetUseSystemSetting(); if (systemSetting == null) { systemSetting = USeSystemSetting.CreateDefault(); } UserDefineSetting userDefineSetting = m_dataAccessor.GetUserDefineSetting(); if (userDefineSetting == null) { userDefineSetting = UserDefineSetting.CreateDefault(); } lock (m_syncObj) { m_systemSetting = systemSetting; m_userDefineSetting = userDefineSetting; } } catch (Exception ex) { throw new Exception("初始化系统配置管理类失败," + ex.Message); } }
private void UseSystemConfigForm_Load(object sender, EventArgs e) { try { USeSystemSetting setting = USeManager.Instance.SystemConfigManager.GetSystemSetting(); Debug.Assert(setting != null); switch (setting.MarketPriceMethods) { case USeMarketPriceMethod.OpponentPrice: this.rbnMarketPriceMethod_OpponentPrice.Checked = true; break; case USeMarketPriceMethod.OnePriceTick: this.rbnMarketPriceMethod_OnePriceTick.Checked = true; break; case USeMarketPriceMethod.TwoPriceTick: this.rbnMarketPriceMethod_TwoPriceTick.Checked = true; break; case USeMarketPriceMethod.ThreePriceTick: this.rbnMarketPriceMethod_ThreePriceTick.Checked = true; break; } this.txtTaskOrder_TaskMaxTryCount.Text = setting.TaskOrder.TaskMaxTryCount.ToString(); this.txtTaskOrder_TryOrderMinInterval.Text = ((int)setting.TaskOrder.TryOrderMinInterval.TotalMilliseconds).ToString(); this.txtOrderMargin_MaxUseRate.Text = (setting.OrderMargin.MaxUseRate * 100).ToString(); } catch (Exception ex) { USeFuturesSpiritUtility.ShowWarningMessageBox(this, "加载系统配置信息失败," + ex.Message); } }
/// <summary> /// 获取系统设定。 /// </summary> /// <returns></returns> public USeSystemSetting GetSystemSetting() { Debug.Assert(m_systemSetting != null); lock (m_syncObj) { USeSystemSetting setting = m_systemSetting.Clone(); return(setting); } }
/// <summary> /// 保存系统配置。 /// </summary> /// <param name="config">系统配置。</param> public void SaveUSeSystemConfig(USeSystemSetting config) { try { USeXmlSerializer.SaveToXml(this.SystemConfigFilePath, config); } catch (Exception ex) { throw new Exception("SaveUSeSystemConfig failed,Error:" + ex.Message); } }
/// <summary> /// 保存系统设定。 /// </summary> /// <param name="systemSetting"></param> public void SaveSystemSetting(USeSystemSetting systemSetting) { try { m_dataAccessor.SaveUSeSystemConfig(systemSetting); lock (m_syncObj) { m_systemSetting = systemSetting.Clone(); } } catch (Exception ex) { throw new Exception("保存系统设定失败," + ex.Message); } SafeFireSystemSettingChanged(); }
/// <summary> /// 克隆。 /// </summary> /// <returns></returns> public USeSystemSetting Clone() { USeSystemSetting setting = new USeSystemSetting(); setting.MarketPriceMethods = this.MarketPriceMethods; if (this.TaskOrder != null) { setting.TaskOrder = this.TaskOrder.Clone(); } if (this.OrderMargin != null) { setting.OrderMargin = this.OrderMargin.Clone(); } if (this.Alarm != null) { setting.Alarm = this.Alarm.Clone(); } return(setting); }
/// <summary> /// 获取系统配置信息。 /// </summary> /// <returns></returns> public USeSystemSetting GetUseSystemSetting() { USeSystemSetting setting = null; try { if (File.Exists(this.SystemConfigFilePath) == false) { setting = null; } else { setting = USeXmlSerializer.LoadFromXml <USeSystemSetting>(this.SystemConfigFilePath); } return(setting); } catch (Exception ex) { throw new Exception("GetUseSystemConfig failed,Error:" + ex.Message); } }
/// <summary> /// 创建默认系统配置。 /// </summary> /// <returns></returns> public static USeSystemSetting CreateDefault() { USeSystemSetting setting = new USeSystemSetting(); setting.MarketPriceMethods = USeMarketPriceMethod.OpponentPrice; setting.TaskOrder = new TaskOrderSetting() { TaskMaxTryCount = 3, TryOrderMinInterval = new TimeSpan(0, 0, 5) }; setting.OrderMargin = new OrderMarginSetting() { MaxUseRate = 0.9m }; setting.Alarm = new AlarmSetting() { }; return(setting); }
private void btnOK_Click(object sender, EventArgs e) { USeMarketPriceMethod marketPriceMethod = USeMarketPriceMethod.Unknown; if (this.rbnMarketPriceMethod_OpponentPrice.Checked) { marketPriceMethod = USeMarketPriceMethod.OpponentPrice; } else if (this.rbnMarketPriceMethod_OnePriceTick.Checked) { marketPriceMethod = USeMarketPriceMethod.OnePriceTick; } else if (this.rbnMarketPriceMethod_TwoPriceTick.Checked) { marketPriceMethod = USeMarketPriceMethod.TwoPriceTick; } else if (this.rbnMarketPriceMethod_ThreePriceTick.Checked) { marketPriceMethod = USeMarketPriceMethod.ThreePriceTick; } else { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请选择市价定义"); return; } int taskMaxTryCount = 0; if (int.TryParse(this.txtTaskOrder_TaskMaxTryCount.Text, out taskMaxTryCount) == false) { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-最大尝试次数"); this.txtTaskOrder_TaskMaxTryCount.Focus(); return; } if (taskMaxTryCount <= 0 || taskMaxTryCount > 20) { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-最大尝试次数,合法范围[1~20]"); this.txtTaskOrder_TaskMaxTryCount.Focus(); return; } int tryOrderMinInterval = 0; if (int.TryParse(this.txtTaskOrder_TryOrderMinInterval.Text, out tryOrderMinInterval) == false) { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-两次下单最小间隔"); this.txtTaskOrder_TaskMaxTryCount.Focus(); return; } if (tryOrderMinInterval < 0) { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-两次下单最小间隔"); this.txtTaskOrder_TaskMaxTryCount.Focus(); return; } decimal maxMarginUseRate = 0; if (decimal.TryParse(this.txtOrderMargin_MaxUseRate.Text, out maxMarginUseRate) == false) { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的套利单保证金占用最大比例,合法范围(0~100]"); return; } if (maxMarginUseRate <= 0 || maxMarginUseRate > 100) { USeFuturesSpiritUtility.ShowInformationMessageBox(this, "套利单保证金占用最大比例"); return; } maxMarginUseRate = maxMarginUseRate / 100m; try { USeSystemSetting setting = new USeSystemSetting(); setting.MarketPriceMethods = marketPriceMethod; setting.TaskOrder = new TaskOrderSetting() { TaskMaxTryCount = taskMaxTryCount, TryOrderMinInterval = new TimeSpan(0, 0, 0, 0, tryOrderMinInterval) }; setting.OrderMargin = new OrderMarginSetting() { MaxUseRate = maxMarginUseRate }; USeManager.Instance.SystemConfigManager.SaveSystemSetting(setting); } catch (Exception ex) { USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message); return; } this.DialogResult = DialogResult.Yes; this.Close(); }