From ddc36164562f26f2357910dacfe52e5ed560cffa Mon Sep 17 00:00:00 2001 From: Roman Yavnikov <45608740+Romazes@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:43:04 +0200 Subject: [PATCH] feat: generic example of GetHistory (#18) feat: several test cases where specific implementation should validate it --- .../TemplateBrokerageHistoryProviderTests.cs | 13 ++++++++++-- .../TemplateBrokerage.cs | 20 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/QuantConnect.TemplateBrokerage.Tests/TemplateBrokerageHistoryProviderTests.cs b/QuantConnect.TemplateBrokerage.Tests/TemplateBrokerageHistoryProviderTests.cs index bad5c82..09e5574 100644 --- a/QuantConnect.TemplateBrokerage.Tests/TemplateBrokerageHistoryProviderTests.cs +++ b/QuantConnect.TemplateBrokerage.Tests/TemplateBrokerageHistoryProviderTests.cs @@ -42,6 +42,15 @@ private static TestCaseData[] TestParameters new TestCaseData(Symbols.BTCUSD, Resolution.Tick, TimeSpan.FromMinutes(1), TickType.Trade, typeof(Tick), false), new TestCaseData(Symbols.BTCUSD, Resolution.Minute, TimeSpan.FromMinutes(10), TickType.Trade, typeof(TradeBar), false), new TestCaseData(Symbols.BTCUSD, Resolution.Daily, TimeSpan.FromDays(10), TickType.Trade, typeof(TradeBar), false), + + // invalid parameter, validate SecurityType more accurate + new TestCaseData(Symbols.SPY, Resolution.Hour, TimeSpan.FromHours(14), TickType.Quote, typeof(QuoteBar), true), + + /// New Listed Symbol on Brokerage + new TestCaseData(Symbol.Create("SUSHIGBP", SecurityType.Crypto, Market.Coinbase), Resolution.Minute, TimeSpan.FromHours(2), TickType.Trade, typeof(TradeBar), false), + + /// Symbol was delisted form Brokerage (can return history data or not) + new TestCaseData(Symbol.Create("SNTUSD", SecurityType.Crypto, Market.Coinbase), Resolution.Daily, TimeSpan.FromDays(14), TickType.Trade, typeof(TradeBar), true), }; } } @@ -87,11 +96,11 @@ public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, T Log.Debug($"{tick}"); } } - else if(slice.QuoteBars.TryGetValue(symbol, out var quoteBar)) + else if (slice.QuoteBars.TryGetValue(symbol, out var quoteBar)) { Log.Debug($"{quoteBar}"); } - else if(slice.Bars.TryGetValue(symbol, out var tradeBar)) + else if (slice.Bars.TryGetValue(symbol, out var tradeBar)) { Log.Debug($"{tradeBar}"); } diff --git a/QuantConnect.TemplateBrokerage/TemplateBrokerage.cs b/QuantConnect.TemplateBrokerage/TemplateBrokerage.cs index 673bdf4..dce9bcb 100644 --- a/QuantConnect.TemplateBrokerage/TemplateBrokerage.cs +++ b/QuantConnect.TemplateBrokerage/TemplateBrokerage.cs @@ -47,8 +47,8 @@ public TemplateBrokerage() } /// - /// Creates a new instance - /// + /// Creates a new instance + /// /// consolidate ticks public TemplateBrokerage(IDataAggregator aggregator) : base("TemplateBrokerage") { @@ -241,5 +241,21 @@ private bool Unsubscribe(IEnumerable symbols) { throw new NotImplementedException(); } + + /// + /// Gets the history for the requested symbols + /// + /// + /// The historical data request + /// An enumerable of bars covering the span specified in the request + public override IEnumerable GetHistory(Data.HistoryRequest request) + { + if (!CanSubscribe(request.Symbol)) + { + return null; // Should consistently return null instead of an empty enumerable + } + + throw new NotImplementedException(); + } } }