Lean  $LEAN_TAG$
LiveFutureChainProvider.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using System.Linq;
18 using QuantConnect.Logging;
20 using System.Collections.Generic;
21 
23 {
24  /// <summary>
25  /// An implementation of <see cref="IFutureChainProvider"/> that fetches the list of contracts
26  /// from an external source
27  /// </summary>
29  {
30  /// <summary>
31  /// Creates a new instance
32  /// </summary>
33  /// <param name="dataCacheProvider">The data cache provider instance to use</param>
34  public LiveFutureChainProvider(IDataCacheProvider dataCacheProvider) : base(dataCacheProvider)
35  {
36  }
37 
38  /// <summary>
39  /// Gets the list of future contracts for a given underlying symbol
40  /// </summary>
41  /// <param name="symbol">The underlying symbol</param>
42  /// <param name="date">The date for which to request the future chain (only used in backtesting)</param>
43  /// <returns>The list of future contracts</returns>
44  public override IEnumerable<Symbol> GetFutureContractList(Symbol symbol, DateTime date)
45  {
46  var result = Enumerable.Empty<Symbol>();
47  try
48  {
49  result = base.GetFutureContractList(symbol, date);
50  }
51  catch (Exception ex)
52  {
53  // this shouldn't happen but just in case let's log it
54  Log.Error(ex);
55  }
56 
57  bool yielded = false;
58  foreach (var symbols in result)
59  {
60  yielded = true;
61  yield return symbols;
62  }
63 
64  if (!yielded)
65  {
66  throw new NotImplementedException("LiveFutureChainProvider.GetFutureContractList() has not been implemented yet.");
67  }
68  }
69  }
70 }