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  [MethodImpl(MethodImplOptions.AggressiveInlining)]
41  public static string FilledAtStalePrice(Securities.Security security, Prices prices)
42  {
43  return Invariant($"Warning: fill at stale price ({prices.EndTime.ToStringInvariant()} {security.Exchange.TimeZone})");
44  }
45 
46  [MethodImpl(MethodImplOptions.AggressiveInlining)]
47  public static string MarketNeverCloses(Securities.Security security, OrderType orderType)
48  {
49  return Invariant($"Market never closes for this symbol {security.Symbol}, can no submit a {nameof(orderType)} order.");
50  }
51 
52  [MethodImpl(MethodImplOptions.AggressiveInlining)]
53  private static string SubscribedTypesToString(HashSet<Type> subscribedTypes)
54  {
55  return subscribedTypes == null
56  ? string.Empty
57  : Invariant($" SubscribedTypes: [{string.Join(",", subscribedTypes.Select(type => type.Name))}]");
58  }
59 
60  [MethodImpl(MethodImplOptions.AggressiveInlining)]
61  public static string NoMarketDataToGetAskPriceForFilling(Securities.Security security, HashSet<Type> subscribedTypes = null)
62  {
63  return Invariant($"Cannot get ask price to perform fill for {security.Symbol} because no market data was found.") +
64  SubscribedTypesToString(subscribedTypes);
65  }
66 
67  [MethodImpl(MethodImplOptions.AggressiveInlining)]
68  public static string NoMarketDataToGetBidPriceForFilling(Securities.Security security, HashSet<Type> subscribedTypes = null)
69  {
70  return Invariant($"Cannot get bid price to perform fill for {security.Symbol} because no market data was found.") +
71  SubscribedTypesToString(subscribedTypes);
72  }
73 
74  [MethodImpl(MethodImplOptions.AggressiveInlining)]
75  public static string NoDataSubscriptionFoundForFilling(Securities.Security security)
76  {
77  return Invariant($"Cannot perform fill for {security.Symbol} because no data subscription were found.");
78  }
79  }
80 
81  /// <summary>
82  /// Provides user-facing messages for the <see cref="Orders.Fills.EquityFillModel"/> class and its consumers or related classes
83  /// </summary>
84  public static class EquityFillModel
85  {
86  public static string MarketOnOpenFillNoOfficialOpenOrOpeningPrintsWithinOneMinute =
87  "No trade with the OfficialOpen or OpeningPrints flag within the 1-minute timeout.";
88 
89  public static string MarketOnCloseFillNoOfficialCloseOrClosingPrintsWithinOneMinute =
90  "No trade with the OfficialClose or ClosingPrints flag within the 1-minute timeout.";
91 
92  public static string MarketOnCloseFillNoOfficialCloseOrClosingPrintsWithoutExtendedMarketHours =
93  "No trade with the OfficialClose or ClosingPrints flag for data that does not include extended market hours.";
94 
95  [MethodImpl(MethodImplOptions.AggressiveInlining)]
96  public static string FilledWithLastTickTypeData(Tick tick)
97  {
98  return Invariant($"Fill with last {tick.TickType} data.");
99  }
100 
101  [MethodImpl(MethodImplOptions.AggressiveInlining)]
102  public static string FilledWithQuoteData(Securities.Security security)
103  {
104  return Invariant($@"Warning: No trade information available at {security.LocalTime.ToStringInvariant()} {
105  security.Exchange.TimeZone}, order filled using Quote data");
106  }
107 
108  [MethodImpl(MethodImplOptions.AggressiveInlining)]
109  public static string FilledWithQuoteTickData(Securities.Security security, Tick quoteTick)
110  {
111  return Invariant($@"Warning: fill at stale price ({quoteTick.EndTime.ToStringInvariant()} {
112  security.Exchange.TimeZone}), using Quote Tick data.");
113  }
114 
115  [MethodImpl(MethodImplOptions.AggressiveInlining)]
116  public static string FilledWithTradeTickData(Securities.Security security, Tick tradeTick)
117  {
118  return Invariant($@"Warning: No quote information available at {tradeTick.EndTime.ToStringInvariant()} {
119  security.Exchange.TimeZone}, order filled using Trade Tick data");
120  }
121 
122  [MethodImpl(MethodImplOptions.AggressiveInlining)]
123  public static string FilledWithQuoteBarData(Securities.Security security, QuoteBar quoteBar)
124  {
125  return Invariant($@"Warning: fill at stale price ({quoteBar.EndTime.ToStringInvariant()} {
126  security.Exchange.TimeZone}), using QuoteBar data.");
127  }
128 
129  [MethodImpl(MethodImplOptions.AggressiveInlining)]
130  public static string FilledWithTradeBarData(Securities.Security security, TradeBar tradeBar)
131  {
132  return Invariant($@"Warning: No quote information available at {tradeBar.EndTime.ToStringInvariant()} {
133  security.Exchange.TimeZone}, order filled using TradeBar data");
134  }
135 
136  [MethodImpl(MethodImplOptions.AggressiveInlining)]
137  public static string FilledWithOpenDueToFavorableGap(Securities.Security security, TradeBar tradeBar)
138  {
139  return Invariant($@"Due to a favorable gap at {tradeBar.EndTime.ToStringInvariant()} {security.Exchange.TimeZone}, order filled using the open price ({tradeBar.Open})");
140  }
141 
142  [MethodImpl(MethodImplOptions.AggressiveInlining)]
143  public static string FilledWithOpenDueToUnfavorableGap(Securities.Security security, TradeBar tradeBar)
144  {
145  return Invariant($@"Due to an unfavorable gap at {tradeBar.EndTime.ToStringInvariant()} {security.Exchange.TimeZone}, order filled using the open price ({tradeBar.Open})");
146  }
147  }
148  }
149 }