StockSharp
268 строк · 6.9 Кб
1#region S# License2/******************************************************************************************
3NOTICE!!! This program and source code is owned and licensed by
4StockSharp, LLC, www.stocksharp.com
5Viewing or use of this code requires your acceptance of the license
6agreement found at https://github.com/StockSharp/StockSharp/blob/master/LICENSE
7Removal of this comment is a violation of the license agreement.
8
9Project: StockSharp.BusinessEntities.BusinessEntities
10File: ExchangeBoard.cs
11Created: 2015, 11, 11, 2:32 PM
12
13Copyright 2010 by StockSharp, LLC
14*******************************************************************************************/
15#endregion S# License16namespace StockSharp.BusinessEntities17{
18using System;19using System.ComponentModel;20using System.ComponentModel.DataAnnotations;21using System.Runtime.Serialization;22using System.Xml;23using System.Xml.Serialization;24using System.Runtime.CompilerServices;25
26using Ecng.Common;27using Ecng.Serialization;28
29using StockSharp.Messages;30using StockSharp.Localization;31
32/// <summary>33/// Information about electronic board.34/// </summary>35[Serializable]36[DataContract]37public partial class ExchangeBoard : Equatable<ExchangeBoard>, IPersistable, INotifyPropertyChanged38{39/// <summary>40/// Initializes a new instance of the <see cref="ExchangeBoard"/>.41/// </summary>42public ExchangeBoard()43{44}45
46private string _code = string.Empty;47
48/// <summary>49/// Board code.50/// </summary>51[DataMember]52[Display(53ResourceType = typeof(LocalizedStrings),54Name = LocalizedStrings.CodeKey,55Description = LocalizedStrings.BoardCodeKey + LocalizedStrings.Dot,56GroupName = LocalizedStrings.GeneralKey57)]58public string Code59{60get => _code;61set62{63if (Code == value)64return;65
66_code = value ?? throw new ArgumentNullException(nameof(value));67Notify();68}69}70
71private TimeSpan _expiryTime;72
73/// <summary>74/// Securities expiration times.75/// </summary>76//[TimeSpan]77[DataMember]78[Display(79ResourceType = typeof(LocalizedStrings),80Name = LocalizedStrings.ExpiryDateKey,81Description = LocalizedStrings.SecExpirationTimeKey,82GroupName = LocalizedStrings.GeneralKey83)]84[XmlIgnore]85public TimeSpan ExpiryTime86{87get => _expiryTime;88set89{90if (ExpiryTime == value)91return;92
93_expiryTime = value;94Notify();95}96}97
98/// <summary>99/// Reserved.100/// </summary>101[Browsable(false)]102[XmlElement(DataType = "duration", ElementName = nameof(ExpiryTime))]103public string ExpiryTimeStr104{105// XmlSerializer does not support TimeSpan, so use this property for106// serialization instead.107get => XmlConvert.ToString(ExpiryTime);108set => ExpiryTime = value.IsEmpty() ? TimeSpan.Zero : XmlConvert.ToTimeSpan(value);109}110
111/// <summary>112/// Exchange, where board is situated.113/// </summary>114[DataMember]115[Display(116ResourceType = typeof(LocalizedStrings),117Name = LocalizedStrings.ExchangeInfoKey,118Description = LocalizedStrings.BoardExchangeKey,119GroupName = LocalizedStrings.GeneralKey120)]121public Exchange Exchange { get; set; }122
123private WorkingTime _workingTime = new() { IsEnabled = true };124
125/// <summary>126/// Board working hours.127/// </summary>128[DataMember]129[Display(130ResourceType = typeof(LocalizedStrings),131Name = LocalizedStrings.WorkingTimeKey,132Description = LocalizedStrings.WorkingHoursKey,133GroupName = LocalizedStrings.GeneralKey134)]135public WorkingTime WorkingTime136{137get => _workingTime;138set139{140if (WorkingTime == value)141return;142
143_workingTime = value ?? throw new ArgumentNullException(nameof(value));144Notify();145}146}147
148[field: NonSerialized]149private TimeZoneInfo _timeZone = TimeZoneInfo.Utc;150
151/// <summary>152/// Information about the time zone where the exchange is located.153/// </summary>154[XmlIgnore]155//[DataMember]156public TimeZoneInfo TimeZone157{158get => _timeZone;159set160{161if (TimeZone == value)162return;163
164_timeZone = value ?? throw new ArgumentNullException(nameof(value));165Notify();166}167}168
169/// <summary>170/// Reserved.171/// </summary>172[Browsable(false)]173[DataMember]174public string TimeZoneStr175{176get => TimeZone.To<string>();177set => TimeZone = value.To<TimeZoneInfo>();178}179
180[field: NonSerialized]181private PropertyChangedEventHandler _propertyChanged;182
183event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged184{185add => _propertyChanged += value;186remove => _propertyChanged -= value;187}188
189private void Notify([CallerMemberName]string propertyName = null)190{191_propertyChanged?.Invoke(this, propertyName);192}193
194/// <inheritdoc />195public override string ToString()196{197return "{0} ({1})".Put(Code, Exchange);198}199
200/// <summary>201/// Compare <see cref="ExchangeBoard"/> on the equivalence.202/// </summary>203/// <param name="other">Another value with which to compare.</param>204/// <returns><see langword="true" />, if the specified object is equal to the current object, otherwise, <see langword="false" />.</returns>205protected override bool OnEquals(ExchangeBoard other)206{207return Code == other.Code && Exchange == other.Exchange;208}209
210private int _hashCode;211
212/// <summary>213/// Get the hash code of the object <see cref="ExchangeBoard"/>.214/// </summary>215/// <returns>A hash code.</returns>216public override int GetHashCode()217{218if (_hashCode == 0)219_hashCode = Code.GetHashCode() ^ (Exchange == null ? 0 : Exchange.GetHashCode());220
221return _hashCode;222}223
224/// <summary>225/// Create a copy of <see cref="ExchangeBoard"/>.226/// </summary>227/// <returns>Copy.</returns>228public override ExchangeBoard Clone()229{230return new ExchangeBoard231{232Exchange = Exchange,233Code = Code,234ExpiryTime = ExpiryTime,235WorkingTime = WorkingTime.Clone(),236TimeZone = TimeZone,237};238}239
240/// <summary>241/// Load settings.242/// </summary>243/// <param name="storage">Settings storage.</param>244public void Load(SettingsStorage storage)245{246Exchange = storage.GetValue<SettingsStorage>(nameof(Exchange))?.Load<Exchange>();247Code = storage.GetValue<string>(nameof(Code));248ExpiryTime = storage.GetValue<TimeSpan>(nameof(ExpiryTime));249WorkingTime = storage.GetValue<SettingsStorage>(nameof(WorkingTime)).Load<WorkingTime>();250TimeZone = storage.GetValue(nameof(TimeZone), TimeZone);251}252
253/// <summary>254/// Save settings.255/// </summary>256/// <param name="storage">Settings storage.</param>257public void Save(SettingsStorage storage)258{259storage.SetValue(nameof(Exchange), Exchange?.Save());260storage.SetValue(nameof(Code), Code);261//storage.SetValue(nameof(IsSupportMarketOrders), IsSupportMarketOrders);262//storage.SetValue(nameof(IsSupportAtomicReRegister), IsSupportAtomicReRegister);263storage.SetValue(nameof(ExpiryTime), ExpiryTime);264storage.SetValue(nameof(WorkingTime), WorkingTime.Save());265storage.SetValue(nameof(TimeZone), TimeZone);266}267}268}