103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
#nullable enable
|
|
namespace mbts {
|
|
using bts.api;
|
|
using bts.utils;
|
|
|
|
using mbts.utils;
|
|
|
|
using ProtoBuf;
|
|
|
|
using Spark.Core.Collections;
|
|
using Spark.Core.Protobuf;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
/// <summary>
|
|
/// Wraps up a security type, security name and exchange
|
|
/// </summary>
|
|
[ProtoContract]
|
|
[Serializable]
|
|
public class SecurityTuple : IComparable<SecurityTuple>, IProtobuf<SecurityTuple> {
|
|
public readonly static SecurityTuple empty = new(
|
|
SecurityType.Unset, string.Empty, Venue.Unset);
|
|
|
|
static readonly IComparer<SecurityTuple> _comparer =
|
|
new ComparerBuilder<SecurityTuple>()
|
|
.append(s => s.security_exchange)
|
|
.append(s => s.security_type)
|
|
.append(s => s.security_name)
|
|
.to_comparer()
|
|
.to_safe();
|
|
|
|
public SecurityTuple() =>
|
|
security_name = string.Empty;
|
|
|
|
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;
|
|
}
|
|
|
|
public SecurityTuple(SecurityTupleImmutable api_sec_tuplei)
|
|
: this(api_sec_tuplei.Type, api_sec_tuplei.Symbol, api_sec_tuplei.Venue) { }
|
|
|
|
internal SecurityTuple(co2.UserSymbol u)
|
|
: this(u.type, u.symbol, u.exchange) { }
|
|
|
|
[ProtoMember(1)]
|
|
public SecurityType security_type { get; }
|
|
|
|
[ProtoMember(2)]
|
|
public string security_name { get; }
|
|
|
|
[ProtoMember(3)]
|
|
public Venue security_exchange { get; }
|
|
|
|
public bool is_empty() =>
|
|
Equals(empty);
|
|
|
|
public SecurityTuple unset_exchange() =>
|
|
new(security_type, security_name, Venue.Unset);
|
|
|
|
public bts.api.SecurityTuple to_api_sec_tuple() =>
|
|
new() {
|
|
Type = security_type,
|
|
Symbol = security_name,
|
|
Venue = security_exchange
|
|
};
|
|
|
|
public SecurityTupleImmutable to_api_sec_tuplei() =>
|
|
new(to_api_sec_tuple());
|
|
|
|
public SecurityTuple Clone() =>
|
|
new(security_type, security_name, security_exchange);
|
|
|
|
public bool Equals(SecurityTuple? other) =>
|
|
other is not null &&
|
|
security_type == other.security_type &&
|
|
security_name == other.security_name &&
|
|
security_exchange == other.security_exchange;
|
|
|
|
public override int GetHashCode() =>
|
|
HashCode.Combine(security_type, security_name, security_exchange);
|
|
|
|
public override bool Equals(object? obj) =>
|
|
Equals(obj as SecurityTuple);
|
|
|
|
public override string ToString() =>
|
|
$"{security_exchange} {security_type} {security_name}";
|
|
|
|
public int CompareTo(SecurityTuple? other) =>
|
|
_comparer.Compare(this, other);
|
|
|
|
object ICloneable.Clone() =>
|
|
Clone();
|
|
}
|
|
|
|
interface ISecurityLookup {
|
|
SecurityTuple get_security(uint security_key);
|
|
}
|
|
}
|