|
35 | 35 | using QuantConnect.Lean.Engine.HistoricalData;
|
36 | 36 | using QuantConnect.Lean.Engine.DataFeeds;
|
37 | 37 | using QuantConnect.Util;
|
| 38 | +using QuantConnect.Securities.Option; |
| 39 | +using QuantConnect.Securities.IndexOption; |
38 | 40 |
|
39 | 41 | namespace QuantConnect.Tests.Engine.RealTime
|
40 | 42 | {
|
@@ -202,6 +204,80 @@ public void RefreshesSymbolProperties(string refreshPeriodStr)
|
202 | 204 | }
|
203 | 205 | }
|
204 | 206 |
|
| 207 | + [TestCase(SecurityType.Equity, typeof(SymbolProperties))] |
| 208 | + [TestCase(SecurityType.Forex, typeof(SymbolProperties))] |
| 209 | + [TestCase(SecurityType.Future, typeof(SymbolProperties))] |
| 210 | + [TestCase(SecurityType.FutureOption, typeof(SymbolProperties))] |
| 211 | + [TestCase(SecurityType.Cfd, typeof(SymbolProperties))] |
| 212 | + [TestCase(SecurityType.Crypto, typeof(SymbolProperties))] |
| 213 | + [TestCase(SecurityType.CryptoFuture, typeof(SymbolProperties))] |
| 214 | + [TestCase(SecurityType.Index, typeof(SymbolProperties))] |
| 215 | + [TestCase(SecurityType.Option, typeof(OptionSymbolProperties))] |
| 216 | + [TestCase(SecurityType.IndexOption, typeof(IndexOptionSymbolProperties))] |
| 217 | + public void SecuritySymbolPropertiesTypeIsRespectedAfterRefresh(SecurityType securityType, Type expectedSymbolPropertiesType) |
| 218 | + { |
| 219 | + using var realTimeHandler = new SPDBTestLiveTradingRealTimeHandler(); |
| 220 | + |
| 221 | + var timeProvider = realTimeHandler.PublicTimeProvider; |
| 222 | + timeProvider.SetCurrentTimeUtc(new DateTime(2023, 5, 30)); |
| 223 | + |
| 224 | + var algorithm = new AlgorithmStub(); |
| 225 | + var refreshPeriod = TimeSpan.FromDays(1); |
| 226 | + algorithm.Settings.DatabasesRefreshPeriod = refreshPeriod; |
| 227 | + |
| 228 | + var symbol = GetSymbol(securityType); |
| 229 | + var security = algorithm.AddSecurity(symbol); |
| 230 | + |
| 231 | + Assert.IsInstanceOf(expectedSymbolPropertiesType, security.SymbolProperties); |
| 232 | + |
| 233 | + realTimeHandler.Setup(algorithm, |
| 234 | + new AlgorithmNodePacket(PacketType.AlgorithmNode), |
| 235 | + new BacktestingResultHandler(), |
| 236 | + null, |
| 237 | + new TestTimeLimitManager()); |
| 238 | + realTimeHandler.SpdbRefreshed.Reset(); |
| 239 | + realTimeHandler.SecuritySymbolPropertiesUpdated.Reset(); |
| 240 | + |
| 241 | + algorithm.SetFinishedWarmingUp(); |
| 242 | + realTimeHandler.SetTime(timeProvider.GetUtcNow()); |
| 243 | + |
| 244 | + var previousSymbolProperties = security.SymbolProperties; |
| 245 | + |
| 246 | + // Refresh the spdb |
| 247 | + timeProvider.Advance(refreshPeriod); |
| 248 | + Assert.IsTrue(realTimeHandler.SpdbRefreshed.WaitOne(1000)); |
| 249 | + Assert.IsTrue(realTimeHandler.SecuritySymbolPropertiesUpdated.WaitOne(1000)); |
| 250 | + |
| 251 | + // Access the symbol properties again |
| 252 | + // The instance must have been changed |
| 253 | + Assert.AreNotSame(security.SymbolProperties, previousSymbolProperties); |
| 254 | + Assert.IsInstanceOf(expectedSymbolPropertiesType, security.SymbolProperties); |
| 255 | + } |
| 256 | + |
| 257 | + private static Symbol GetSymbol(SecurityType securityType) |
| 258 | + { |
| 259 | + return securityType switch |
| 260 | + { |
| 261 | + SecurityType.Equity => Symbols.SPY, |
| 262 | + SecurityType.Forex => Symbols.USDJPY, |
| 263 | + SecurityType.Future => Symbols.Future_ESZ18_Dec2018, |
| 264 | + SecurityType.FutureOption => Symbol.CreateOption( |
| 265 | + Symbols.Future_ESZ18_Dec2018, |
| 266 | + Market.CME, |
| 267 | + OptionStyle.American, |
| 268 | + OptionRight.Call, |
| 269 | + 4000m, |
| 270 | + new DateTime(2023, 6, 16)), |
| 271 | + SecurityType.Cfd => Symbols.DE10YBEUR, |
| 272 | + SecurityType.Crypto => Symbols.BTCUSD, |
| 273 | + SecurityType.CryptoFuture => Symbol.Create("BTCUSD", securityType, Market.Binance), |
| 274 | + SecurityType.Index => Symbols.SPX, |
| 275 | + SecurityType.Option => Symbols.SPY_C_192_Feb19_2016, |
| 276 | + SecurityType.IndexOption => Symbol.Create("SPX", securityType, Market.USA), |
| 277 | + _ => throw new ArgumentOutOfRangeException(nameof(securityType), securityType, null) |
| 278 | + }; |
| 279 | + } |
| 280 | + |
205 | 281 | private class TestTimeLimitManager : IIsolatorLimitResultProvider
|
206 | 282 | {
|
207 | 283 | public IsolatorLimitResult IsWithinLimit()
|
|
0 commit comments