20 using Newtonsoft.Json;
30 [JsonConverter(typeof(SymbolJsonConverter))]
31 [ProtoContract(SkipConstructor =
true)]
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);
238 throw new ArgumentNullException(nameof(value));
243 throw new ArgumentException(
Messages.
Symbol.SidNotForOption(sid), nameof(value));
248 return new Symbol(sid, value);
251 if (underlying ==
null)
254 out var _, out var underlyingValue, out var _, out var _, out var _);
259 throw new ArgumentException(
Messages.
Symbol.UnderlyingSidDoesNotMatch(sid, underlying), nameof(underlying));
262 return new Symbol(sid, value, underlying);
290 market ??= underlyingSymbol.
ID.
Market;
295 optionType.DefaultOptionStyle(),
312 public static Symbol CreateFuture(
string ticker,
string market, DateTime expiry,
string alias =
null)
336 if (_canonical !=
null)
377 while (current.HasUnderlying)
379 if (current.Underlying == symbol)
384 current = current.Underlying;
396 public string Value {
get;
private set; }
410 get {
return !ReferenceEquals(
Underlying,
null); }
431 public string CUSIP {
get {
return _securityDefinitionSymbolResolver.Value.CUSIP(
this); } }
436 public string CompositeFIGI {
get {
return _securityDefinitionSymbolResolver.Value.CompositeFIGI(
this); } }
441 public string SEDOL {
get {
return _securityDefinitionSymbolResolver.Value.SEDOL(
this); } }
446 public string ISIN {
get {
return _securityDefinitionSymbolResolver.Value.ISIN(
this); } }
451 public int?
CIK {
get {
return _securityDefinitionSymbolResolver.Value.CIK(
this); } }
466 throw new ArgumentNullException(nameof(value));
491 if (mappedSymbol ==
Value)
497 var underlying =
new Symbol(
id, mappedSymbol);
498 underlying = underlying.AdjustSymbolByOffset(contractDepthOffset);
501 return new Symbol(
ID, underlying.Value, underlying);
533 return new Symbol(
ID, mappedSymbol, underlyingSymbol);
555 switch (securityType)
576 switch (securityType)
599 throw new ArgumentNullException(nameof(value));
602 Value = value.LazyToUpper();
608 #region Overrides of Object
619 if (ReferenceEquals(
null, obj))
return false;
620 if (ReferenceEquals(
this, obj))
return true;
623 if (obj is
string stringSymbol)
634 if (obj.GetType() != GetType())
return false;
660 var str = obj as string;
663 return string.Compare(
Value, str, StringComparison.OrdinalIgnoreCase);
668 return string.Compare(
Value, sym.Value, StringComparison.OrdinalIgnoreCase);
688 #region Equality members
699 if (ReferenceEquals(
this, other))
return true;
701 if (ReferenceEquals(other,
null)
702 || ReferenceEquals(other,
Empty))
706 if (!_isEmpty.HasValue)
711 return _isEmpty.Value;
726 if (ReferenceEquals(left, right))
735 return right is
null || right.
Equals(left);
738 return left.
Equals(right);
751 if (ReferenceEquals(left, right))
760 return right is
null || right.Equals(left);
763 return left.
Equals(right);
776 if (ReferenceEquals(left, right))
784 return right is
null;
787 if (left is
Symbol leftSymbol)
789 return leftSymbol.
Equals(right);
792 if (left is
string leftStr)
794 return leftStr.Equals(right?.
ToString(), StringComparison.InvariantCulture);
808 return !(left == right);
819 return !(left == right);
830 return !(left == right);
835 #region Implicit operators
842 [Obsolete(
"Symbol implicit operator to string is provided for algorithm use only.")]
843 public static implicit
operator string(
Symbol symbol)
853 [Obsolete(
"Symbol implicit operator from string is provided for algorithm use only.")]
854 public static implicit
operator Symbol(
string ticker)
867 #region String methods
871 #pragma warning disable 1591
872 [Obsolete(
"Symbol.Contains is a pass-through for Symbol.Value.Contains")]
873 public bool Contains(
string value) {
return Value.Contains(value); }
874 [Obsolete(
"Symbol.EndsWith is a pass-through for Symbol.Value.EndsWith")]
875 public bool EndsWith(
string value) {
return Value.EndsWithInvariant(value); }
876 [Obsolete(
"Symbol.StartsWith is a pass-through for Symbol.Value.StartsWith")]
877 public bool StartsWith(
string value) {
return Value.StartsWithInvariant(value); }
878 [Obsolete(
"Symbol.ToLower is a pass-through for Symbol.Value.ToLower")]
879 public string ToLower() {
return Value.ToLowerInvariant(); }
880 [Obsolete(
"Symbol.ToUpper is a pass-through for Symbol.Value.ToUpper")]
881 public string ToUpper() {
return Value.LazyToUpper(); }
882 #pragma warning restore 1591
897 sym = underlying.
Value;
907 sym = securityIdentifier.
Symbol;
912 return $
"?{sym.LazyToUpper()}";
915 if (sym.Length > 5) sym +=
" ";
919 sym = securityIdentifier.
Symbol;