/// <summary> /// Provides a convenience method for creating a future Symbol. /// </summary> /// <param name="ticker">The ticker</param> /// <param name="market">The market the future resides in</param> /// <param name="expiry">The future expiry date</param> /// <param name="alias">An alias to be used for the symbol cache. Required when /// adding the same security from different markets</param> /// <returns>A new Symbol object for the specified future contract</returns> public static Symbol CreateFuture(string ticker, string market, DateTime expiry, string alias = null) { var sid = SecurityIdentifier.GenerateFuture(expiry, ticker, market); if (expiry == SecurityIdentifier.DefaultDate) { alias = alias ?? "/" + ticker.ToUpper(); } else { var sym = sid.Symbol; alias = alias ?? SymbolRepresentation.GenerateFutureTicker(sym, sid.Date); } return(new Symbol(sid, alias)); }
#pragma warning restore 1591 #endregion /// <summary> /// Centralized helper method to resolve alias for a symbol /// </summary> public static string GetAlias(SecurityIdentifier securityIdentifier, Symbol underlying = null) { string sym; switch (securityIdentifier.SecurityType) { case SecurityType.FutureOption: case SecurityType.Option: case SecurityType.IndexOption: if (securityIdentifier.Date == SecurityIdentifier.DefaultDate) { return($"?{underlying.Value.LazyToUpper()}"); } sym = underlying.Value; if (securityIdentifier.Symbol != underlying.ID.Symbol) { // If we have changed the SID and it does not match the underlying, // we've mapped a future into another Symbol. We want to have a value // representing the mapped ticker, not of the underlying. // e.g. we want: // OG C3200...|GC18Z20 // NOT // GC C3200...|GC18Z20 sym = securityIdentifier.Symbol; } if (sym.Length > 5) { sym += " "; } return(SymbolRepresentation.GenerateOptionTickerOSI(sym, securityIdentifier.OptionRight, securityIdentifier.StrikePrice, securityIdentifier.Date)); case SecurityType.Future: sym = securityIdentifier.Symbol; if (securityIdentifier.Date == SecurityIdentifier.DefaultDate) { return($"/{sym}"); } return(SymbolRepresentation.GenerateFutureTicker(sym, securityIdentifier.Date)); default: return(null); } }
/// <summary> /// Provides a convenience method for creating a futures Symbol. /// </summary> /// <param name="underlying">The underlying ticker</param> /// <param name="market">The market the underlying resides in</param> /// <param name="expiry">The option expiry date</param> /// <param name="alias">An alias to be used for the symbol cache. Required when /// adding the same security from different markets</param> /// <returns>A new Symbol object for the specified option contract</returns> public static Symbol CreateFuture(string underlying, string market, DateTime expiry, string alias = null) { var underlyingSid = SecurityIdentifier.GenerateBase(underlying, market); var sid = SecurityIdentifier.GenerateFuture(expiry, underlyingSid, market); var underlyingSymbol = new Symbol(underlyingSid, underlying); if (expiry == SecurityIdentifier.DefaultDate) { alias = alias ?? "/" + underlying.ToUpper(); } else { var sym = sid.Symbol; alias = alias ?? SymbolRepresentation.GenerateFutureTicker(sym, sid.Date); } return(new Symbol(sid, alias, underlyingSymbol)); }