Files
spark/src/client/spark_core/data/SecurityTuple.cs
T
John Colvin ed920c7c5a Move security/tick data classes to spark_core
* spark_core is the appropriate project for such
  'vocabulary' types.

* unit tests in the spark_tests project can now
  reference these types (this was the immediate
  impetus for the move).
2021-01-04 18:23:27 -06:00

73 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProtoBuf;
using bts.api;
namespace mbts
{
/// Wraps up a security type, security name and exchange
[ProtoContract]
[Serializable]
public class SecurityTuple : IComparable<SecurityTuple>, IEquatable<SecurityTuple>
{
[ProtoMember(1)]
public readonly SecurityType security_type;
[ProtoMember(2)]
public readonly string security_name;
[ProtoMember(3)]
public readonly Venue security_exchange;
public readonly static SecurityTuple empty = new SecurityTuple(SecurityType.Unset, String.Empty, Venue.Unset);
public SecurityTuple() { }
public SecurityTuple(SecurityType the_security_type,
string the_security_name,
Venue the_security_exchange)
{
security_type = the_security_type;
security_name = the_security_name;
security_exchange = the_security_exchange;
}
internal SecurityTuple(co2.UserSymbol u) : this(u.type, u.symbol, u.exchange) { }
public bool is_empty() { return Equals(empty); }
public SecurityTuple unset_exchange() { return new SecurityTuple(security_type, security_name, Venue.Unset); }
#region Object overrides
public override int GetHashCode() { return security_type.GetHashCode() ^ security_name.GetHashCode() ^ security_exchange.GetHashCode(); }
public override bool Equals(object obj) { return obj != null && obj is SecurityTuple && Equals(obj as SecurityTuple); }
public override string ToString() { return String.Format("{0} {1}", security_name, security_type); }
#endregion
#region IComparable<SecurityTuple> Members
public int CompareTo(SecurityTuple other)
{
if (other == null)
return 1;
int rv = security_exchange.CompareTo(other.security_exchange);
if (rv != 0)
return rv;
rv = security_type.CompareTo(other.security_type);
if (rv != 0)
return rv;
return security_name.CompareTo(other.security_name);
}
#endregion
#region IEquatable<SecurityTuple> Members
public bool Equals(SecurityTuple other) { return other != null && CompareTo(other) == 0; }
#endregion
}
interface ISecurityLookup
{
SecurityTuple get_security(UInt32 security_key);
}
}