Lean  $LEAN_TAG$
Messages.Orders.Fills.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.Collections.Generic;
18 using System.Linq;
19 using System.Runtime.CompilerServices;
20 
22 using QuantConnect.Orders;
25 
26 using static QuantConnect.StringExtensions;
27 
28 namespace QuantConnect
29 {
30  /// <summary>
31  /// Provides user-facing message construction methods and static messages for the <see cref="Orders.Fills"/> namespace
32  /// </summary>
33  public static partial class Messages
34  {
35  /// <summary>
36  /// Provides user-facing messages for the <see cref="Orders.Fills.FillModel"/> class and its consumers or related classes
37  /// </summary>
38  public static class FillModel
39  {
40  /// <summary>
41  /// Returns a string message warning saying the order was filled at stale price
42  /// </summary>
43  [MethodImpl(MethodImplOptions.AggressiveInlining)]
44  public static string FilledAtStalePrice(Securities.Security security, Prices prices)
45  {
46  return Invariant($"Warning: fill at stale price ({prices.EndTime.ToStringInvariant()} {security.Exchange.TimeZone})");
47  }
48 
49  /// <summary>
50  /// Returns a string message saying the market never closes for the given symbol, and that an order of the given
51  /// type cannot be submitted
52  /// </summary>
53  [MethodImpl(MethodImplOptions.AggressiveInlining)]
54  public static string MarketNeverCloses(Securities.Security security, OrderType orderType)
55  {
56  return Invariant($"Market never closes for this symbol {security.Symbol}, can no submit a {nameof(orderType)} order.");
57  }
58 
59  /// <summary>
60  /// Returns a string message containing the given subscribedTypes
61  /// </summary>
62  [MethodImpl(MethodImplOptions.AggressiveInlining)]
63  private static string SubscribedTypesToString(HashSet<Type> subscribedTypes)
64  {
65  return subscribedTypes == null
66  ? string.Empty
67  : Invariant($" SubscribedTypes: [{string.Join(",", subscribedTypes.Select(type => type.Name))}]");
68  }
69 
70  /// <summary>
71  /// Returns a string message saying it was impossible to get ask price to perform the fill for the given security symbol because
72  /// no market data was found
73  /// </summary>
74  [MethodImpl(MethodImplOptions.AggressiveInlining)]
75  public static string NoMarketDataToGetAskPriceForFilling(Securities.Security security, HashSet<Type> subscribedTypes = null)
76  {
77  return Invariant($"Cannot get ask price to perform fill for {security.Symbol} because no market data was found.") +
78  SubscribedTypesToString(subscribedTypes);
79  }
80 
81  /// <summary>
82  /// Returns a string message saying it was impossible to get bid price to perform the fill for the given security symbol because
83  /// no market data was found
84  /// </summary>
85  [MethodImpl(MethodImplOptions.AggressiveInlining)]
86  public static string NoMarketDataToGetBidPriceForFilling(Securities.Security security, HashSet<Type> subscribedTypes = null)
87  {
88  return Invariant($"Cannot get bid price to perform fill for {security.Symbol} because no market data was found.") +
89  SubscribedTypesToString(subscribedTypes);
90  }
91 
92  /// <summary>
93  /// Returns a string message saying it was impossible to perform a fill for the given security symbol because
94  /// no data subscription was found
95  /// </summary>
96  [MethodImpl(MethodImplOptions.AggressiveInlining)]
97  public static string NoDataSubscriptionFoundForFilling(Securities.Security security)
98  {
99  return Invariant($"Cannot perform fill for {security.Symbol} because no data subscription were found.");
100  }
101  }
102 
103  /// <summary>
104  /// Provides user-facing messages for the <see cref="Orders.Fills.EquityFillModel"/> class and its consumers or related classes
105  /// </summary>
106  public static class EquityFillModel
107  {
108  /// <summary>
109  /// String message saying: No trade with the OfficialOpen or OpeningPrints flag within the 1-minute timeout
110  /// </summary>
112  "No trade with the OfficialOpen or OpeningPrints flag within the 1-minute timeout.";
113 
114  /// <summary>
115  /// String message saying: No trade with the OfficialClose or ClosingPrints flag within the 1-minute timeout
116  /// </summary>
118  "No trade with the OfficialClose or ClosingPrints flag within the 1-minute timeout.";
119 
120  /// <summary>
121  /// String message saying: No trade with the OfficialClose or ClosingPrints flag for data that does not include
122  /// extended market hours
123  /// </summary>
125  "No trade with the OfficialClose or ClosingPrints flag for data that does not include extended market hours.";
126 
127  /// <summary>
128  /// Returns a string message saying the last data (of the given tick type) has been used to fill
129  /// </summary>
130  [MethodImpl(MethodImplOptions.AggressiveInlining)]
131  public static string FilledWithLastTickTypeData(Tick tick)
132  {
133  return Invariant($"Fill with last {tick.TickType} data.");
134  }
135 
136  /// <summary>
137  /// Returns a string message warnning the user that no trade information was available, so the order was filled
138  /// using quote data
139  /// </summary>
140  [MethodImpl(MethodImplOptions.AggressiveInlining)]
141  public static string FilledWithQuoteData(Securities.Security security)
142  {
143  return Invariant($@"Warning: No trade information available at {security.LocalTime.ToStringInvariant()} {
144  security.Exchange.TimeZone}, order filled using Quote data");
145  }
146 
147  /// <summary>
148  /// Returns a string message warning the user that the fill is at stale price and that the order will
149  /// be filled using quote tick data
150  /// </summary>
151  [MethodImpl(MethodImplOptions.AggressiveInlining)]
152  public static string FilledWithQuoteTickData(Securities.Security security, Tick quoteTick)
153  {
154  return Invariant($@"Warning: fill at stale price ({quoteTick.EndTime.ToStringInvariant()} {
155  security.Exchange.TimeZone}), using Quote Tick data.");
156  }
157 
158  /// <summary>
159  /// Returns a string message warning the user that no quote information was available, so the order
160  /// was filled using trade tick data
161  /// </summary>
162  [MethodImpl(MethodImplOptions.AggressiveInlining)]
163  public static string FilledWithTradeTickData(Securities.Security security, Tick tradeTick)
164  {
165  return Invariant($@"Warning: No quote information available at {tradeTick.EndTime.ToStringInvariant()} {
166  security.Exchange.TimeZone}, order filled using Trade Tick data");
167  }
168 
169  /// <summary>
170  /// Returns a string message warning the user that the fill was at stale price, so quote bar data
171  /// was used to fill the order
172  /// </summary>
173  [MethodImpl(MethodImplOptions.AggressiveInlining)]
174  public static string FilledWithQuoteBarData(Securities.Security security, QuoteBar quoteBar)
175  {
176  return Invariant($@"Warning: fill at stale price ({quoteBar.EndTime.ToStringInvariant()} {
177  security.Exchange.TimeZone}), using QuoteBar data.");
178  }
179 
180  /// <summary>
181  /// Returns a string message warning the user that no quote information was available, so that trade bar
182  /// data was used to fill the order
183  /// </summary>
184  [MethodImpl(MethodImplOptions.AggressiveInlining)]
185  public static string FilledWithTradeBarData(Securities.Security security, TradeBar tradeBar)
186  {
187  return Invariant($@"Warning: No quote information available at {tradeBar.EndTime.ToStringInvariant()} {
188  security.Exchange.TimeZone}, order filled using TradeBar data");
189  }
190 
191  /// <summary>
192  /// Returns a string message saying that the order was filled using the open price due to a favorable gap
193  /// </summary>
194  [MethodImpl(MethodImplOptions.AggressiveInlining)]
195  public static string FilledWithOpenDueToFavorableGap(Securities.Security security, TradeBar tradeBar)
196  {
197  return Invariant($@"Due to a favorable gap at {tradeBar.EndTime.ToStringInvariant()} {security.Exchange.TimeZone}, order filled using the open price ({tradeBar.Open})");
198  }
199 
200  /// <summary>
201  /// Returns a string message saying that the order was filled using the open price due to an unfavorable gap
202  /// </summary>
203  [MethodImpl(MethodImplOptions.AggressiveInlining)]
204  public static string FilledWithOpenDueToUnfavorableGap(Securities.Security security, TradeBar tradeBar)
205  {
206  return Invariant($@"Due to an unfavorable gap at {tradeBar.EndTime.ToStringInvariant()} {security.Exchange.TimeZone}, order filled using the open price ({tradeBar.Open})");
207  }
208  }
209  }
210 }