/// <summary> /// Get the Lean <see cref = "Symbol"/> object given its ticker, security type and market. /// </summary> /// <param name="ticker">The asset symbol name</param> /// <param name="type">The asset security type</param> /// <param name="market">The asset market</param> /// <returns><see cref = "Symbol"/> object wrapped in a <see cref = "PyObject"/></returns> public PyObject GetSymbol(string ticker, string type = "Equity", string market = null) { var securityType = (SecurityType)Enum.Parse(typeof(SecurityType), type, true); SecurityIdentifier sid; if (securityType == SecurityType.Cfd) { sid = SecurityIdentifier.GenerateCfd(ticker, market ?? Market.Oanda); } else if (securityType == SecurityType.Equity) { sid = SecurityIdentifier.GenerateEquity(ticker, market ?? Market.USA); } else if (securityType == SecurityType.Forex) { sid = SecurityIdentifier.GenerateForex(ticker, market ?? Market.FXCM); } else { return("Invalid security type. Use Equity, Forex or Cfd.".ToPython()); } // Add symbol to cache SymbolCache.Set(ticker, new Symbol(sid, ticker)); return(SymbolCache.GetSymbol(ticker).ToPython()); }
/// <summary> /// Creates a user defined universe symbol /// </summary> /// <param name="securityType">The security</param> /// <param name="market">The market</param> /// <returns>A symbol for user defined universe of the specified security type and market</returns> public static Symbol CreateSymbol(SecurityType securityType, string market) { var ticker = string.Format("qc-universe-userdefined-{0}-{1}", market.ToLower(), securityType); SecurityIdentifier sid; switch (securityType) { case SecurityType.Base: sid = SecurityIdentifier.GenerateBase(ticker, market); break; case SecurityType.Equity: sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); break; case SecurityType.Option: sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, ticker, market, 0, 0, 0); break; case SecurityType.Forex: sid = SecurityIdentifier.GenerateForex(ticker, market); break; case SecurityType.Cfd: sid = SecurityIdentifier.GenerateCfd(ticker, market); break; case SecurityType.Commodity: case SecurityType.Future: default: throw new NotImplementedException("The specified security type is not implemented yet: " + securityType); } return(new Symbol(sid, ticker)); }
/// <summary> /// Creates a user defined universe symbol /// </summary> /// <param name="securityType">The security</param> /// <param name="market">The market</param> /// <returns>A symbol for user defined universe of the specified security type and market</returns> public static Symbol CreateSymbol(SecurityType securityType, string market) { var ticker = $"qc-universe-userdefined-{market.ToLowerInvariant()}-{securityType}"; SecurityIdentifier sid; switch (securityType) { case SecurityType.Base: sid = SecurityIdentifier.GenerateBase(null, ticker, market); break; case SecurityType.Equity: sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); break; case SecurityType.Option: var underlying = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlying, market, 0, 0, 0); break; case SecurityType.FutureOption: var underlyingFuture = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market); sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingFuture, market, 0, 0, 0); break; case SecurityType.IndexOption: var underlyingIndex = SecurityIdentifier.GenerateIndex(ticker, market); sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingIndex, market, 0, 0, OptionStyle.European); break; case SecurityType.Forex: sid = SecurityIdentifier.GenerateForex(ticker, market); break; case SecurityType.Cfd: sid = SecurityIdentifier.GenerateCfd(ticker, market); break; case SecurityType.Index: sid = SecurityIdentifier.GenerateIndex(ticker, market); break; case SecurityType.Future: sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market); break; case SecurityType.Crypto: sid = SecurityIdentifier.GenerateCrypto(ticker, market); break; case SecurityType.Commodity: default: throw new NotImplementedException($"The specified security type is not implemented yet: {securityType}"); } return(new Symbol(sid, ticker)); }
private static Symbol ConvertSymbol(string instrument, SecurityType securityType) { if (securityType == SecurityType.Forex) { return(new Symbol(SecurityIdentifier.GenerateForex(instrument, Market.Oanda), instrument)); } if (securityType == SecurityType.Cfd) { return(new Symbol(SecurityIdentifier.GenerateCfd(instrument, Market.Oanda), instrument)); } throw new NotImplementedException("The specfied security type has not been implemented yet: " + securityType); }
static SecurityIdentifier GetSid(string symbol, SecurityType securityType) { if (securityType == SecurityType.Forex) { return(SecurityIdentifier.GenerateForex(symbol, Market.Dukascopy)); } if (securityType == SecurityType.Cfd) { return(SecurityIdentifier.GenerateCfd(symbol, Market.Dukascopy)); } throw new NotImplementedException("The specfied security type has not been implemented yet: " + securityType); }
/// <summary> /// Converts an FXCM symbol to a QuantConnect symbol /// </summary> private static Symbol ConvertSymbol(Instrument instrument) { var symbol = instrument.getSymbol().Replace("/", ""); var securityType = GetSecurityType(instrument); switch (securityType) { case SecurityType.Forex: return(new Symbol(SecurityIdentifier.GenerateForex(symbol, Market.FXCM), symbol)); case SecurityType.Cfd: return(new Symbol(SecurityIdentifier.GenerateCfd(symbol, Market.FXCM), symbol)); } throw new ArgumentException("The specified security type is not supported: " + securityType); }