20 using Newtonsoft.Json;
31 [JsonConverter(typeof(SymbolJsonConverter))]
32 [ProtoContract(SkipConstructor =
true)]
40 private bool? _isEmpty;
64 public static Symbol Create(
string ticker,
SecurityType securityType,
string market,
string alias =
null, Type baseDataType =
null)
122 return new Symbol(sid, alias ?? ticker);
140 return CreateBase(baseType.CreateType(), underlying, market);
168 return new Symbol(sid, underlying.
Value, underlying);
187 var underlyingSymbol =
new Symbol(underlyingSid, underlying);
189 return CreateOption(underlyingSymbol, market, style, right, strike, expiry, alias);
206 return CreateOption(underlyingSymbol,
null, market, style, right, strike, expiry, alias);
226 return new Symbol(sid, alias ??
GetAlias(sid, underlyingSymbol), underlyingSymbol);
240 throw new ArgumentNullException(nameof(value));
245 throw new ArgumentException(
Messages.
Symbol.SidNotForOption(sid), nameof(value));
250 return new Symbol(sid, value);
253 if (underlying ==
null)
256 out var _, out var underlyingValue, out var _, out var _, out var _);
261 throw new ArgumentException(
Messages.
Symbol.UnderlyingSidDoesNotMatch(sid, underlying), nameof(underlying));
264 return new Symbol(sid, value, underlying);
292 market ??= underlyingSymbol.
ID.
Market;
297 optionType.DefaultOptionStyle(),
314 public static Symbol CreateFuture(
string ticker,
string market, DateTime expiry,
string alias =
null)
338 if (_canonical !=
null)
379 while (current.HasUnderlying)
381 if (current.Underlying == symbol)
386 current = current.Underlying;
398 public string Value {
get;
private set; }
412 get {
return !ReferenceEquals(
Underlying,
null); }
433 public string CUSIP {
get {
return _securityDefinitionSymbolResolver.Value.CUSIP(
this); } }
438 public string CompositeFIGI {
get {
return _securityDefinitionSymbolResolver.Value.CompositeFIGI(
this); } }
443 public string SEDOL {
get {
return _securityDefinitionSymbolResolver.Value.SEDOL(
this); } }
448 public string ISIN {
get {
return _securityDefinitionSymbolResolver.Value.ISIN(
this); } }
453 public int?
CIK {
get {
return _securityDefinitionSymbolResolver.Value.CIK(
this); } }
468 throw new ArgumentNullException(nameof(value));
493 if (mappedSymbol ==
Value)
499 var underlying =
new Symbol(
id, mappedSymbol);
500 underlying = underlying.AdjustSymbolByOffset(contractDepthOffset);
503 return new Symbol(
ID, underlying.Value, underlying);
535 return new Symbol(
ID, mappedSymbol, underlyingSymbol);
557 switch (securityType)
578 switch (securityType)
601 throw new ArgumentNullException(nameof(value));
604 Value = value.LazyToUpper();
610 #region Overrides of Object
621 if (ReferenceEquals(
null, obj))
return false;
622 if (ReferenceEquals(
this, obj))
return true;
625 if (obj is
string stringSymbol)
636 if (obj.GetType() != GetType())
return false;
662 var str = obj as string;
665 return string.Compare(
Value, str, StringComparison.OrdinalIgnoreCase);
670 return string.Compare(
Value, sym.Value, StringComparison.OrdinalIgnoreCase);
690 #region Equality members
701 if (ReferenceEquals(
this, other))
return true;
703 if (ReferenceEquals(other,
null)
704 || ReferenceEquals(other,
Empty))
708 if (!_isEmpty.HasValue)
713 return _isEmpty.Value;
728 if (ReferenceEquals(left, right))
737 return right is
null || right.
Equals(left);
740 return left.
Equals(right);
753 if (ReferenceEquals(left, right))
762 return right is
null || right.Equals(left);
765 return left.
Equals(right);
778 if (ReferenceEquals(left, right))
786 return right is
null;
789 if (left is
Symbol leftSymbol)
791 return leftSymbol.
Equals(right);
794 if (left is
string leftStr)
796 return leftStr.Equals(right?.
ToString(), StringComparison.InvariantCulture);
810 return !(left == right);
821 return !(left == right);
832 return !(left == right);
837 #region Implicit operators
844 [Obsolete(
"Symbol implicit operator to string is provided for algorithm use only.")]
845 public static implicit
operator string(
Symbol symbol)
855 [Obsolete(
"Symbol implicit operator from string is provided for algorithm use only.")]
856 public static implicit
operator Symbol(
string ticker)
869 #region String methods
873 #pragma warning disable 1591
874 [Obsolete(
"Symbol.Contains is a pass-through for Symbol.Value.Contains")]
875 public bool Contains(
string value) {
return Value.Contains(value); }
876 [Obsolete(
"Symbol.EndsWith is a pass-through for Symbol.Value.EndsWith")]
877 public bool EndsWith(
string value) {
return Value.EndsWithInvariant(value); }
878 [Obsolete(
"Symbol.StartsWith is a pass-through for Symbol.Value.StartsWith")]
879 public bool StartsWith(
string value) {
return Value.StartsWithInvariant(value); }
880 [Obsolete(
"Symbol.ToLower is a pass-through for Symbol.Value.ToLower")]
881 public string ToLower() {
return Value.ToLowerInvariant(); }
882 [Obsolete(
"Symbol.ToUpper is a pass-through for Symbol.Value.ToUpper")]
883 public string ToUpper() {
return Value.LazyToUpper(); }
884 #pragma warning restore 1591
899 sym = underlying.
Value;
909 sym = securityIdentifier.
Symbol;
914 return $
"?{sym.LazyToUpper()}";
917 if (sym.Length > 5) sym +=
" ";
921 sym = securityIdentifier.
Symbol;