Lean  $LEAN_TAG$
CashAmount.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 ProtoBuf;
17 
19 {
20  /// <summary>
21  /// Represents a cash amount which can be converted to account currency using a currency converter
22  /// </summary>
23  [ProtoContract(SkipConstructor = true)]
24  public struct CashAmount
25  {
26  /// <summary>
27  /// The amount of cash
28  /// </summary>
29  [ProtoMember(1)]
30  public decimal Amount { get; }
31 
32  /// <summary>
33  /// The currency in which the cash amount is denominated
34  /// </summary>
35  [ProtoMember(2)]
36  public string Currency { get; }
37 
38  /// <summary>
39  /// Initializes a new instance of the <see cref="CashAmount"/> class
40  /// </summary>
41  /// <param name="amount">The amount</param>
42  /// <param name="currency">The currency</param>
43  public CashAmount(decimal amount, string currency)
44  {
45  Amount = amount;
46  Currency = currency;
47  }
48 
49  /// <summary>
50  /// Will determine if two <see cref="CashAmount"/> instances are equal
51  /// Useful to compare against the default instance
52  /// </summary>
53  /// <returns>True if <see cref="Currency"/> and <see cref="Amount"/> are equal</returns>
54  public static bool operator ==(CashAmount lhs, CashAmount rhs)
55  {
56  return Equals(lhs, rhs);
57  }
58 
59  /// <summary>
60  /// Will determine if two <see cref="CashAmount"/> instances are different
61  /// Useful to compare against the default instance
62  /// </summary>
63  /// <returns>True if <see cref="Currency"/> or <see cref="Amount"/> are different</returns>
64  public static bool operator !=(CashAmount lhs, CashAmount rhs)
65  {
66  return !Equals(lhs, rhs);
67  }
68 
69  /// <summary>
70  /// Used to compare two <see cref="CashAmount"/> instances.
71  /// Useful to compare against the default instance
72  /// </summary>
73  /// <param name="obj">The other object to compare with</param>
74  /// <returns>True if <see cref="Currency"/> and <see cref="Amount"/> are equal</returns>
75  public override bool Equals(object obj)
76  {
77  if (obj is CashAmount)
78  {
79  var cashAmountObj = (CashAmount) obj;
80  return Amount == cashAmountObj.Amount
81  && Currency == cashAmountObj.Currency;
82  }
83  return false;
84  }
85 
86  /// <summary>
87  /// Get Hash Code for this Object
88  /// </summary>
89  /// <returns>Integer Hash Code</returns>
90  public override int GetHashCode()
91  {
92  return base.GetHashCode();
93  }
94  }
95 }