2020using QuantConnect . Util ;
2121using QuantConnect . Interfaces ;
2222using System . Collections . Generic ;
23- using QuantConnect . Lean . Engine . DataFeeds ;
24- using QuantConnect . Lean . Engine . HistoricalData ;
2523using QuantConnect . Configuration ;
2624using QuantConnect . Logging ;
2725using QuantConnect . Packets ;
@@ -38,7 +36,8 @@ public class DataBentoProvider : IDataQueueHandler
3836 /// <summary>
3937 /// <inheritdoc cref="IDataAggregator"/>
4038 /// </summary>
41- private IDataAggregator _dataAggregator = null ! ;
39+ private readonly IDataAggregator _dataAggregator = Composer . Instance . GetExportedValueByTypeName < IDataAggregator > (
40+ Config . Get ( "data-aggregator" , "QuantConnect.Lean.Engine.DataFeeds.AggregationManager" ) , forceTypeNameOnExisting : false ) ;
4241
4342 /// <summary>
4443 /// <inheritdoc cref="EventBasedDataQueueHandlerSubscriptionManager"/>
@@ -67,7 +66,6 @@ public class DataBentoProvider : IDataQueueHandler
6766 private bool _unsupportedSecurityTypeMessageLogged ;
6867 private bool _unsupportedDataTypeMessageLogged ;
6968 private bool _potentialUnsupportedResolutionMessageLogged ;
70- private bool _potentialUnsupportedTickTypeMessageLogged ;
7169
7270
7371 /// <summary>
@@ -80,6 +78,7 @@ public class DataBentoProvider : IDataQueueHandler
8078 /// </summary>
8179 public DataBentoProvider ( )
8280 {
81+ Log . Trace ( "From Plugin DataBentoProvider.DataBentoProvider() being initialized 1" ) ;
8382 _apiKey = Config . Get ( "databento-api-key" ) ;
8483 if ( string . IsNullOrEmpty ( _apiKey ) )
8584 {
@@ -96,6 +95,7 @@ public DataBentoProvider()
9695 /// <param name="apiKey">DataBento API key</param>
9796 public DataBentoProvider ( string apiKey )
9897 {
98+ Log . Trace ( "From Plugin DataBentoProvider.DataBentoProvider() being initialized 2" ) ;
9999 _apiKey = apiKey ?? throw new ArgumentNullException ( nameof ( apiKey ) ) ;
100100 _dataDownloader = new DataBentoDataDownloader ( _apiKey ) ;
101101 Initialize ( ) ;
@@ -106,58 +106,101 @@ public DataBentoProvider(string apiKey)
106106 /// </summary>
107107 private void Initialize ( )
108108 {
109- _dataAggregator = Composer . Instance . GetExportedValueByTypeName < IDataAggregator > ( "DataAggregator" ) ;
109+ Log . Trace ( "DataBentoProvider.Initialize(): Starting initialization" ) ;
110+
110111 _subscriptionManager = new EventBasedDataQueueHandlerSubscriptionManager ( ) ;
111112 _subscriptionManager . SubscribeImpl = ( symbols , tickType ) =>
112113 {
114+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): Received subscription request for { symbols . Count ( ) } symbols, TickType={ tickType } ") ;
115+
113116 foreach ( var symbol in symbols )
114117 {
118+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): Processing symbol { symbol } ") ;
119+
115120 if ( _subscriptionConfigs . TryGetValue ( symbol , out var config ) )
116121 {
122+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): Found config for { symbol } , Resolution={ config . Resolution } , TickType={ config . TickType } ") ;
123+
117124 if ( _client ? . IsConnected == true )
118125 {
126+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): Client is connected, attempting async subscribe for { symbol } ") ;
119127 Task . Run ( ( ) =>
120128 {
121129 var success = _client . Subscribe ( config . Symbol , config . Resolution , config . TickType ) ;
122- if ( ! success )
130+ if ( success )
123131 {
124- Log . Error ( $ "DataBentoProvider.Subscribe(): Failed to subscribe to live data for { config . Symbol } ") ;
132+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): Successfully subscribed to { config . Symbol } ") ;
133+ }
134+ else
135+ {
136+ Log . Error ( $ "DataBentoProvider.SubscribeImpl(): Failed to subscribe to live data for { config . Symbol } ") ;
125137 }
126138 } ) ;
127139 }
140+ else
141+ {
142+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): Client not connected, skipping subscription for { symbol } ") ;
143+ }
144+ }
145+ else
146+ {
147+ Log . Trace ( $ "DataBentoProvider.SubscribeImpl(): No config found for { symbol } , skipping") ;
128148 }
129149 }
150+
130151 return true ;
131152 } ;
153+
132154 _subscriptionManager . UnsubscribeImpl = ( symbols , tickType ) =>
133155 {
156+ Log . Trace ( $ "DataBentoProvider.UnsubscribeImpl(): Received unsubscribe request for { symbols . Count ( ) } symbols, TickType={ tickType } ") ;
157+
134158 foreach ( var symbol in symbols )
135159 {
160+ Log . Trace ( $ "DataBentoProvider.UnsubscribeImpl(): Processing symbol { symbol } ") ;
161+
136162 if ( _client ? . IsConnected == true )
137163 {
164+ Log . Trace ( $ "DataBentoProvider.UnsubscribeImpl(): Client is connected, unsubscribing from { symbol } ") ;
138165 Task . Run ( ( ) =>
139166 {
140167 _client . Unsubscribe ( symbol ) ;
168+ Log . Trace ( $ "DataBentoProvider.UnsubscribeImpl(): Unsubscribed from { symbol } ") ;
141169 } ) ;
142170 }
171+ else
172+ {
173+ Log . Trace ( $ "DataBentoProvider.UnsubscribeImpl(): Client not connected, skipping unsubscribe for { symbol } ") ;
174+ }
143175 }
176+
144177 return true ;
145178 } ;
146179
147180 // Initialize the live client
181+ Log . Trace ( "DataBentoProvider.Initialize(): Creating DatabentoRawClient" ) ;
148182 _client = new DatabentoRawClient ( _apiKey ) ;
149183 _client . DataReceived += OnDataReceived ;
150184 _client . ConnectionStatusChanged += OnConnectionStatusChanged ;
151185
152186 // Connect to live gateway
187+ Log . Trace ( "DataBentoProvider.Initialize(): Attempting async connection to DataBento live gateway" ) ;
153188 Task . Run ( async ( ) =>
154189 {
155190 var connected = await _client . ConnectAsync ( ) ;
156- if ( ! connected )
191+ Log . Trace ( $ "DataBentoProvider.Initialize(): ConnectAsync() returned { connected } ") ;
192+
193+ if ( connected )
194+ {
195+ Log . Trace ( "DataBentoProvider.Initialize(): Successfully connected to DataBento live gateway" ) ;
196+ }
197+ else
157198 {
158199 Log . Error ( "DataBentoProvider.Initialize(): Failed to connect to DataBento live gateway" ) ;
159200 }
160201 } ) ;
202+
203+ Log . Trace ( "DataBentoProvider.Initialize(): Initialization complete" ) ;
161204 }
162205
163206 /// <summary>
@@ -168,6 +211,7 @@ private void Initialize()
168211 /// <returns>The new enumerator for this subscription request</returns>
169212 public IEnumerator < BaseData > ? Subscribe ( SubscriptionDataConfig dataConfig , EventHandler newDataAvailableHandler )
170213 {
214+ Log . Trace ( "From Plugin Subscribed ENTER" ) ;
171215 if ( ! CanSubscribe ( dataConfig ) ) {
172216 return null ;
173217 }
@@ -177,6 +221,7 @@ private void Initialize()
177221 _subscriptionManager . Subscribe ( dataConfig ) ;
178222 _activeSubscriptionConfigs . Add ( dataConfig ) ;
179223
224+ Log . Trace ( "From Plugin Subscribed DONE" ) ;
180225 return enumerator ;
181226 }
182227
@@ -298,7 +343,8 @@ private bool IsSupported(SecurityType securityType, Type dataType, TickType tick
298343 // Check supported data types
299344 if ( dataType != typeof ( TradeBar ) &&
300345 dataType != typeof ( QuoteBar ) &&
301- dataType != typeof ( Tick ) )
346+ dataType != typeof ( Tick ) &&
347+ dataType != typeof ( OpenInterest ) )
302348 {
303349 if ( ! _unsupportedDataTypeMessageLogged )
304350 {
@@ -310,30 +356,22 @@ private bool IsSupported(SecurityType securityType, Type dataType, TickType tick
310356
311357 // Warn about potential limitations for tick data
312358 // I'm mimicing polygon implementation with this
313- if ( resolution < Resolution . Second && ! _potentialUnsupportedResolutionMessageLogged )
359+ if ( ! _potentialUnsupportedResolutionMessageLogged )
314360 {
315361 _potentialUnsupportedResolutionMessageLogged = true ;
316362 Log . Trace ( "DataBentoDataProvider.IsSupported(): " +
317363 $ "Subscription for { securityType } -{ dataType } -{ tickType } -{ resolution } will be attempted. " +
318364 $ "An Advanced DataBento subscription plan is required to stream tick data.") ;
319365 }
320366
321- // Warn about potential limitations for quote data
322- if ( tickType == TickType . Quote && ! _potentialUnsupportedTickTypeMessageLogged )
323- {
324- _potentialUnsupportedTickTypeMessageLogged = true ;
325- Log . Trace ( "DataBentoDataProvider.IsSupported(): " +
326- $ "Subscription for { securityType } -{ dataType } -{ tickType } -{ resolution } will be attempted. " +
327- $ "An Advanced DataBento subscription plan is required to stream quote data.") ;
328- }
329-
330367 return true ;
331368 }
332369 // <summary>
333370 /// Handles data received from the live client
334371 /// </summary>
335372 private void OnDataReceived ( object ? sender , BaseData data )
336373 {
374+ Log . Trace ( $ "DataBentoProvider.OnDataReceived(): Received data: { data } ") ;
337375 try
338376 {
339377 _dataAggregator . Update ( data ) ;
@@ -349,7 +387,7 @@ private void OnDataReceived(object? sender, BaseData data)
349387 /// </summary>
350388 private void OnConnectionStatusChanged ( object ? sender , bool isConnected )
351389 {
352- Log . Debug ( $ "DataBentoProvider.OnConnectionStatusChanged(): Connection status changed to: { isConnected } ") ;
390+ Log . Trace ( $ "DataBentoProvider.OnConnectionStatusChanged(): Connection status changed to: { isConnected } ") ;
353391
354392 if ( isConnected )
355393 {
0 commit comments