|
16 | 16 | using System;
|
17 | 17 | using System.Collections.Generic;
|
18 | 18 | using System.Linq;
|
19 |
| -using Python.Runtime; |
20 | 19 | using Newtonsoft.Json;
|
21 | 20 | using NodaTime;
|
22 | 21 | using NUnit.Framework;
|
@@ -645,6 +644,33 @@ public void DoesNotCauseCollision_WhenRegisteringMultipleDifferentCustomDataType
|
645 | 644 | Assert.AreNotSame(unlinkedData, bitcoin);
|
646 | 645 | }
|
647 | 646 |
|
| 647 | + [TestCase(SecurityType.Equity)] |
| 648 | + [TestCase(SecurityType.Index)] |
| 649 | + [TestCase(SecurityType.Future)] |
| 650 | + public void AddOptionContractWithDelistedUnderlyingThrows(SecurityType underlyingSecurityType) |
| 651 | + { |
| 652 | + var algorithm = Algorithm(); |
| 653 | + algorithm.SetStartDate(2007, 05, 25); |
| 654 | + |
| 655 | + Security underlying = underlyingSecurityType switch |
| 656 | + { |
| 657 | + SecurityType.Equity => algorithm.AddEquity("SPY"), |
| 658 | + SecurityType.Index => algorithm.AddIndex("SPX"), |
| 659 | + SecurityType.Future => algorithm.AddFuture("ES"), |
| 660 | + _ => throw new ArgumentException($"Invalid test underlying security type {underlyingSecurityType}") |
| 661 | + }; |
| 662 | + |
| 663 | + underlying.IsDelisted = true; |
| 664 | + // let's remove the underlying since it's delisted |
| 665 | + algorithm.RemoveSecurity(underlying.Symbol); |
| 666 | + |
| 667 | + var optionContractSymbol = Symbol.CreateOption(underlying.Symbol, Market.USA, OptionStyle.American, OptionRight.Call, 100, |
| 668 | + new DateTime(2007, 06, 15)); |
| 669 | + |
| 670 | + var exception = Assert.Throws<ArgumentException>(() => algorithm.AddOptionContract(optionContractSymbol)); |
| 671 | + Assert.IsTrue(exception.Message.Contains("is delisted"), $"Unexpected exception message: {exception.Message}"); |
| 672 | + } |
| 673 | + |
648 | 674 | private static SubscriptionDataConfig GetMatchingSubscription(QCAlgorithm algorithm, Symbol symbol, Type type)
|
649 | 675 | {
|
650 | 676 | // find a subscription matchin the requested type with a higher resolution than requested
|
|
0 commit comments