Lean  $LEAN_TAG$
MarketsReportElement.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.Linq;
17 using QuantConnect.Orders;
18 using QuantConnect.Packets;
19 using System.Collections.Generic;
20 
22 {
23  internal sealed class MarketsReportElement : ReportElement
24  {
25  private LiveResult _live;
26  private BacktestResult _backtest;
27 
28  /// <summary>
29  /// Get the markets of the strategy.
30  /// </summary>
31  /// <param name="name">Name of the widget</param>
32  /// <param name="key">Location of injection</param>
33  /// <param name="backtest">Backtest result object</param>
34  /// <param name="live">Live result object</param>
35  public MarketsReportElement(string name, string key, BacktestResult backtest, LiveResult live)
36  {
37  _live = live;
38  _backtest = backtest;
39  Name = name;
40  Key = key;
41  }
42 
43  /// <summary>
44  /// The generated output string to be injected
45  /// </summary>
46  public override string Render()
47  {
48  var liveOrders = _live?.Orders?.Values.ToList();
49  if (liveOrders == null)
50  {
51  liveOrders = new List<Order>();
52  }
53 
54  var orders = new List<Order>();
55  var backtestOrders = _backtest?.Orders?.Values;
56  if (backtestOrders != null)
57  {
58  orders = backtestOrders.ToList();
59  }
60 
61  orders = orders.Union(liveOrders).ToList();
62 
63  var securityTypes = orders.DistinctBy(o => o.SecurityType).Select(s => s.SecurityType.ToString()).ToList();
64  Result = securityTypes;
65 
66  return string.Join(",", securityTypes);
67  }
68  }
69 }