/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ namespace QuantConnect.Data.Auxiliary { /// /// Unique definition key for a collection of auxiliary data for a Market and SecurityType /// public class AuxiliaryDataKey { /// /// USA equities market corporate actions key definition /// public static AuxiliaryDataKey EquityUsa { get; } = new (QuantConnect.Market.USA, SecurityType.Equity); /// /// The market associated with these corporate actions /// public string Market { get; } /// /// The associated security type /// public SecurityType SecurityType { get; } /// /// Creates a new instance /// public AuxiliaryDataKey(string market, SecurityType securityType) { Market = market; SecurityType = securityType; } /// /// Serves as a hash function for a particular type. /// public override int GetHashCode() { unchecked { var hashCode = Market.GetHashCode(); return (hashCode*397) ^ SecurityType.GetHashCode(); } } /// /// Determines whether the specified is equal to the current . /// /// /// true if the specified object is equal to the current object; otherwise, false. /// /// The object to compare with the current object. 2 public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (obj.GetType() != GetType()) return false; var other = (AuxiliaryDataKey)obj; return other.Market == Market && other.SecurityType == SecurityType; } /// /// Returns a string containing the market and security type /// public override string ToString() { return $"{Market}:{SecurityType}"; } /// /// Helper method to create a new instance from a Symbol /// public static AuxiliaryDataKey Create(Symbol symbol) => Create(symbol.HasUnderlying ? symbol.Underlying.ID : symbol.ID); /// /// Helper method to create a new instance from a SecurityIdentifier /// public static AuxiliaryDataKey Create(SecurityIdentifier securityIdentifier) { securityIdentifier = securityIdentifier.HasUnderlying ? securityIdentifier.Underlying : securityIdentifier; return new AuxiliaryDataKey(securityIdentifier.Market, securityIdentifier.SecurityType); } } }