20 using Newtonsoft.Json;
30 [JsonConverter(typeof(SymbolJsonConverter))]
31 [ProtoContract(SkipConstructor =
true)]
32 public sealed
class Symbol : IEquatable<Symbol>, IComparable
38 private bool? _isEmpty;
62 public static Symbol Create(
string ticker,
SecurityType securityType,
string market,
string alias =
null, Type baseDataType =
null)
120 return new Symbol(sid, alias ?? ticker);
138 return CreateBase(baseType.CreateType(), underlying, market);
166 return new Symbol(sid, underlying.
Value, underlying);
185 var underlyingSymbol =
new Symbol(underlyingSid, underlying);
187 return CreateOption(underlyingSymbol, market, style, right, strike, expiry, alias);
204 return CreateOption(underlyingSymbol,
null, market, style, right, strike, expiry, alias);
224 return new Symbol(sid, alias ??
GetAlias(sid, underlyingSymbol), underlyingSymbol);
252 market ??= underlyingSymbol.
ID.
Market;
257 optionType.DefaultOptionStyle(),
274 public static Symbol CreateFuture(
string ticker,
string market, DateTime expiry,
string alias =
null)
301 if (_canonical !=
null)
342 while (current.HasUnderlying)
344 if (current.Underlying == symbol)
349 current = current.Underlying;
361 public string Value {
get;
private set; }
375 get {
return !ReferenceEquals(
Underlying,
null); }
396 public string CUSIP {
get {
return _securityDefinitionSymbolResolver.Value.CUSIP(
this); } }
401 public string CompositeFIGI {
get {
return _securityDefinitionSymbolResolver.Value.CompositeFIGI(
this); } }
406 public string SEDOL {
get {
return _securityDefinitionSymbolResolver.Value.SEDOL(
this); } }
411 public string ISIN {
get {
return _securityDefinitionSymbolResolver.Value.ISIN(
this); } }
416 public int?
CIK {
get {
return _securityDefinitionSymbolResolver.Value.CIK(
this); } }
431 throw new ArgumentNullException(nameof(value));
456 if (mappedSymbol ==
Value)
462 var underlying =
new Symbol(
id, mappedSymbol);
463 underlying = underlying.AdjustSymbolByOffset(contractDepthOffset);
466 return new Symbol(
ID, underlying.Value, underlying);
498 return new Symbol(
ID, mappedSymbol, underlyingSymbol);
520 switch (securityType)
541 switch (securityType)
564 throw new ArgumentNullException(nameof(value));
567 Value = value.LazyToUpper();
573 #region Overrides of Object
584 if (ReferenceEquals(
null, obj))
return false;
585 if (ReferenceEquals(
this, obj))
return true;
588 var sidString = obj as string;
589 if (sidString !=
null)
604 if (obj.GetType() != GetType())
return false;
630 var str = obj as string;
633 return string.Compare(
Value, str, StringComparison.OrdinalIgnoreCase);
638 return string.Compare(
Value, sym.Value, StringComparison.OrdinalIgnoreCase);
658 #region Equality members
669 if (ReferenceEquals(
this, other))
return true;
671 if (ReferenceEquals(other,
null)
672 || ReferenceEquals(other,
Empty))
676 if (!_isEmpty.HasValue)
681 return _isEmpty.Value;
696 if (ReferenceEquals(left, right))
701 if (ReferenceEquals(left,
null) || left.
Equals(
Empty))
703 return ReferenceEquals(right,
null) || right.
Equals(
Empty);
705 return left.
Equals(right);
716 return !(left == right);
721 #region Implicit operators
728 [Obsolete(
"Symbol implicit operator to string is provided for algorithm use only.")]
729 public static implicit
operator string(
Symbol symbol)
739 [Obsolete(
"Symbol implicit operator from string is provided for algorithm use only.")]
740 public static implicit
operator Symbol(
string ticker)
751 return new Symbol(sid, sid.Symbol);
759 #region String methods
763 #pragma warning disable 1591
764 [Obsolete(
"Symbol.Contains is a pass-through for Symbol.Value.Contains")]
765 public bool Contains(
string value) {
return Value.Contains(value); }
766 [Obsolete(
"Symbol.EndsWith is a pass-through for Symbol.Value.EndsWith")]
767 public bool EndsWith(
string value) {
return Value.EndsWithInvariant(value); }
768 [Obsolete(
"Symbol.StartsWith is a pass-through for Symbol.Value.StartsWith")]
769 public bool StartsWith(
string value) {
return Value.StartsWithInvariant(value); }
770 [Obsolete(
"Symbol.ToLower is a pass-through for Symbol.Value.ToLower")]
771 public string ToLower() {
return Value.ToLowerInvariant(); }
772 [Obsolete(
"Symbol.ToUpper is a pass-through for Symbol.Value.ToUpper")]
773 public string ToUpper() {
return Value.LazyToUpper(); }
774 #pragma warning restore 1591
789 sym = underlying.
Value;
799 sym = securityIdentifier.
Symbol;
804 return $
"?{sym.LazyToUpper()}";
807 if (sym.Length > 5) sym +=
" ";
811 sym = securityIdentifier.
Symbol;