Lean  $LEAN_TAG$
Channel.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 
18 namespace QuantConnect.Data
19 {
20 
21  /// <summary>
22  /// Represents a subscription channel
23  /// </summary>
24  public class Channel
25  {
26 
27  /// <summary>
28  /// Represents an internal channel name for all brokerage channels in case we don't differentiate them
29  /// </summary>
30  public static string Single = "common";
31 
32  /// <summary>
33  /// The name of the channel
34  /// </summary>
35  public string Name { get; private set; }
36 
37  /// <summary>
38  /// The ticker symbol of the channel
39  /// </summary>
40  public Symbol Symbol { get; private set; }
41 
42  /// <summary>
43  /// Creates an instance of subscription channel
44  /// </summary>
45  /// <param name="channelName">Socket channel name</param>
46  /// <param name="symbol">Associated symbol</param>
47  public Channel(string channelName, Symbol symbol)
48  {
49  if (string.IsNullOrEmpty(channelName))
50  {
51  throw new ArgumentNullException(nameof(channelName), "Channel Name can't be null or empty");
52  }
53 
54  if (symbol == null)
55  {
56  throw new ArgumentNullException(nameof(symbol), "Symbol can't be null or empty");
57  }
58 
59  Name = channelName;
60  Symbol = symbol;
61  }
62 
63  /// <summary>
64  /// Indicates whether the current object is equal to another object of the same type.
65  /// </summary>
66  /// <param name="other">An object to compare with this object.</param>
67  /// <returns>
68  /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
69  /// </returns>
70  public bool Equals(Channel other)
71  {
72  if (ReferenceEquals(null, other)) return false;
73  if (ReferenceEquals(this, other)) return true;
74  return string.Equals(Name, other?.Name) && Symbol.Equals(other.Symbol);
75  }
76 
77  /// <summary>
78  /// Determines whether the specified object is equal to the current object.
79  /// </summary>
80  /// <param name="obj">The object to compare with the current object. </param>
81  /// <returns>
82  /// true if the specified object is equal to the current object; otherwise, false.
83  /// </returns>
84  public override bool Equals(object obj)
85  {
86  return Equals(obj as Channel);
87  }
88 
89  /// <summary>
90  /// Serves as the default hash function.
91  /// </summary>
92  /// <returns>
93  /// A hash code for the current object.
94  /// </returns>
95  public override int GetHashCode()
96  {
97  unchecked
98  {
99  int hash = (int)2166136261;
100  hash = (hash * 16777619) ^ Name.GetHashCode();
101  hash = (hash * 16777619) ^ Symbol.GetHashCode();
102  return hash;
103  }
104  }
105  }
106 }