Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion MyCustomDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace QuantConnect.Lean.DataSource.MyCustom
/// <summary>
/// Implementation of Custom Data Provider
/// </summary>
public class MyCustomDataProvider : SynchronizingHistoryProvider, IDataQueueHandler
public class MyCustomDataProvider : SynchronizingHistoryProvider, IDataQueueHandler, IDataQueueUniverseProvider
{
/// <summary>
/// <inheritdoc cref="IDataAggregator"/>
Expand Down Expand Up @@ -157,5 +157,20 @@ private bool CanSubscribe(Symbol symbol)

throw new NotImplementedException();
}

public IEnumerable<Symbol> LookupSymbols(Symbol symbol, bool includeExpired, string securityCurrency = null)
{
if (!symbol.SecurityType.IsOption())
{
throw new ArgumentException($"Unsupported security type: {symbol.SecurityType}", nameof(symbol));
}

throw new NotImplementedException();
}

public bool CanPerformSelection()
{
throw new NotImplementedException();
}
}
}
52 changes: 52 additions & 0 deletions tests/MyCustomDataQueueHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Threading.Tasks;
using QuantConnect.Data.Market;
using System.Collections.Generic;
using System.Collections.Concurrent;
using QuantConnect.Lean.DataSource.MyCustom;

namespace QuantConnect.DataLibrary.Tests
Expand Down Expand Up @@ -74,6 +75,57 @@ public void StreamsData(Symbol symbol, Resolution resolution)
Thread.Sleep(1_000);
}

[TestCaseSource(nameof(TestParameters))]
public void StreamsOptionChainData(Symbol symbol, Resolution resolution)
{
Assert.Pass();

var canonicalOption = Symbol.CreateCanonicalOption(symbol);

var dataProvider = new MyCustomDataProvider();

var configs = dataProvider.LookupSymbols(canonicalOption, true).SelectMany(optionContract => GetSubscriptionDataConfigs(optionContract, resolution)).ToList();

var symbolOpenInterest = new ConcurrentDictionary<Symbol, Dictionary<Type, int>>();

foreach (var config in configs)
{
symbolOpenInterest[config.Symbol] = new Dictionary<Type, int>
{
[typeof(QuoteBar)] = 0,
[typeof(TradeBar)] = 0
};

ProcessFeed(
dataProvider.Subscribe(config, (s, e) => { }),
(baseData) =>
{
if (baseData != null)
{
Log.Trace($"{baseData}");
switch (baseData)
{
case QuoteBar qb:
symbolOpenInterest[qb.Symbol][typeof(QuoteBar)] += 1;
break;
case TradeBar tb:
symbolOpenInterest[tb.Symbol][typeof(TradeBar)] += 1;
break;
}
}
});
}

Thread.Sleep(1_000);

foreach (var config in configs)
{
dataProvider.Unsubscribe(config);
}

Thread.Sleep(1_000);
}

private IEnumerable<SubscriptionDataConfig> GetSubscriptionDataConfigs(Symbol symbol, Resolution resolution)
{
if (resolution == Resolution.Tick)
Expand Down
Loading