Lean  $LEAN_TAG$
Messages.Brokerages.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.Runtime.CompilerServices;
18 
21 using QuantConnect.Orders;
22 
23 using static QuantConnect.StringExtensions;
24 using System.Collections.Generic;
26 
27 namespace QuantConnect
28 {
29  /// <summary>
30  /// Provides user-facing message construction methods and static messages for the <see cref="Brokerages"/> namespace
31  /// </summary>
32  public static partial class Messages
33  {
34  /// <summary>
35  /// Provides user-facing messages for the <see cref="Brokerages.DefaultBrokerageModel"/> class and its consumers or related classes
36  /// </summary>
37  public static class DefaultBrokerageModel
38  {
39  public static string UnsupportedMarketOnOpenOrdersForFuturesAndFutureOptions =
40  "MarketOnOpen orders are not supported for futures and future options.";
41 
42  public static string NoDataForSymbol =
43  "There is no data for this symbol yet, please check the security.HasData flag to ensure there is at least one data point.";
44 
45  public static string OrderUpdateNotSupported = "Brokerage does not support update. You must cancel and re-create instead.";
46 
47  [MethodImpl(MethodImplOptions.AggressiveInlining)]
48  public static string UnsupportedSecurityType(IBrokerageModel brokerageModel, Securities.Security security)
49  {
50  return Invariant($"The {brokerageModel.GetType().Name} does not support {security.Type} security type.");
51  }
52 
53  [MethodImpl(MethodImplOptions.AggressiveInlining)]
54  public static string InvalidSecurityTypeToGetFillModel(IBrokerageModel brokerageModel, Securities.Security security)
55  {
56  return Invariant($"{brokerageModel.GetType().Name}.GetFillModel: Invalid security type {security.Type}");
57  }
58 
59  [MethodImpl(MethodImplOptions.AggressiveInlining)]
60  public static string InvalidOrderQuantity(Securities.Security security, decimal quantity)
61  {
62  return Invariant($@"The minimum order size (in quote currency) for {security.Symbol.Value} is {
63  security.SymbolProperties.MinimumOrderSize}. Order quantity was {quantity}.");
64  }
65 
66  [MethodImpl(MethodImplOptions.AggressiveInlining)]
67  public static string InvalidOrderSize(Securities.Security security, decimal quantity, decimal price)
68  {
69  return Invariant($@"The minimum order size (in quote currency) for {security.Symbol.Value} is {security.SymbolProperties.MinimumOrderSize}. Order size was {quantity * price}.");
70  }
71 
72  [MethodImpl(MethodImplOptions.AggressiveInlining)]
73  public static string UnsupportedOrderType(IBrokerageModel brokerageModel, Orders.Order order, IEnumerable<OrderType> supportedOrderTypes)
74  {
75  return Invariant($"The {brokerageModel.GetType().Name} does not support {order.Type} order type. Only supports [{string.Join(',', supportedOrderTypes)}]");
76  }
77 
78  [MethodImpl(MethodImplOptions.AggressiveInlining)]
79  public static string UnsupportedTimeInForce(IBrokerageModel brokerageModel, Orders.Order order)
80  {
81  return Invariant($@"The {brokerageModel.GetType().Name} does not support {
82  order.TimeInForce.GetType().Name} time in force.");
83  }
84 
85  [MethodImpl(MethodImplOptions.AggressiveInlining)]
86  public static string InvalidSecurityTypeForLeverage(Securities.Security security)
87  {
88  return Invariant($"Invalid security type: {security.Type}");
89  }
90  }
91 
92  /// <summary>
93  /// Provides user-facing messages for the <see cref="Brokerages.AlphaStreamsBrokerageModel"/> class and its consumers or related classes
94  /// </summary>
95  public static class AlphaStreamsBrokerageModel
96  {
97  public static string UnsupportedAccountType = "The Alpha Streams brokerage does not currently support Cash trading.";
98  }
99 
100  /// <summary>
101  /// Provides user-facing messages for the <see cref="Brokerages.AxosClearingBrokerageModel"/> class and its consumers or related classes
102  /// </summary>
103  public static class AxosBrokerageModel
104  {
105  [MethodImpl(MethodImplOptions.AggressiveInlining)]
106  public static string NonIntegerOrderQuantity(Orders.Order order)
107  {
108  return Invariant($"Order Quantity must be Integer, but provided {order.Quantity}.");
109  }
110  }
111 
112  /// <summary>
113  /// Provides user-facing messages for the <see cref="Brokerages.BinanceBrokerageModel"/> class and its consumers or related classes
114  /// </summary>
115  public static class BinanceBrokerageModel
116  {
117  [MethodImpl(MethodImplOptions.AggressiveInlining)]
118  public static string UnsupportedOrderTypeForSecurityType(Orders.Order order, Securities.Security security)
119  {
120  return Invariant($"{order.Type} orders are not supported for this symbol ${security.Symbol}");
121  }
122 
123  [MethodImpl(MethodImplOptions.AggressiveInlining)]
124  public static string UnsupportedOrderTypeWithLinkToSupportedTypes(Orders.Order order, Securities.Security security)
125  {
126  return Invariant($@"{order.Type} orders are not supported for this symbol. Please check 'https://api.binance.com/api/v3/exchangeInfo?symbol={
127  security.SymbolProperties.MarketTicker}' to see supported order types.");
128  }
129  }
130 
131  /// <summary>
132  /// Provides user-facing messages for the <see cref="Brokerages.BinanceUSBrokerageModel"/> class and its consumers or related classes
133  /// </summary>
134  public static class BinanceUSBrokerageModel
135  {
136  public static string UnsupportedAccountType = "The Binance.US brokerage does not currently support Margin trading.";
137  }
138 
139  /// <summary>
140  /// Provides user-facing messages for the <see cref="Brokerages.BrokerageMessageEvent"/> class and its consumers or related classes
141  /// </summary>
142  public static class BrokerageMessageEvent
143  {
144  public static string DisconnectCode = "Disconnect";
145 
146  public static string ReconnectCode = "Reconnect";
147 
148  [MethodImpl(MethodImplOptions.AggressiveInlining)]
149  public static string ToString(Brokerages.BrokerageMessageEvent messageEvent)
150  {
151  return Invariant($"{messageEvent.Type} - Code: {messageEvent.Code} - {messageEvent.Message}");
152  }
153  }
154 
155  /// <summary>
156  /// Provides user-facing messages for the <see cref="Brokerages.DefaultBrokerageMessageHandler"/> class and its consumers or related classes
157  /// </summary>
158  public static class DefaultBrokerageMessageHandler
159  {
160  public static string BrokerageErrorContext = "Brokerage Error";
161 
162  public static string Disconnected = "DefaultBrokerageMessageHandler.Handle(): Disconnected.";
163 
164  public static string Reconnected = "DefaultBrokerageMessageHandler.Handle(): Reconnected.";
165 
166  public static string DisconnectedWhenExchangesAreClosed =
167  "DefaultBrokerageMessageHandler.Handle(): Disconnect when exchanges are closed, checking back before exchange open.";
168 
169  public static string StillDisconnected = "DefaultBrokerageMessageHandler.Handle(): Still disconnected, goodbye.";
170 
171  public static string BrokerageDisconnectedShutDownContext = "Brokerage Disconnect";
172 
173  [MethodImpl(MethodImplOptions.AggressiveInlining)]
174  public static string BrokerageInfo(Brokerages.BrokerageMessageEvent messageEvent)
175  {
176  return $"Brokerage Info: {messageEvent.Message}";
177  }
178 
179  [MethodImpl(MethodImplOptions.AggressiveInlining)]
180  public static string BrokerageWarning(Brokerages.BrokerageMessageEvent messageEvent)
181  {
182  return $"Brokerage Warning: {messageEvent.Message}";
183  }
184 
185  [MethodImpl(MethodImplOptions.AggressiveInlining)]
186  public static string DisconnectedWhenExchangesAreOpen(TimeSpan reconnectionTimeout)
187  {
188  return Invariant($@"DefaultBrokerageMessageHandler.Handle(): Disconnect when exchanges are open, trying to reconnect for {
189  reconnectionTimeout.TotalMinutes} minutes.");
190  }
191 
192  [MethodImpl(MethodImplOptions.AggressiveInlining)]
193  public static string TimeUntilNextMarketOpen(TimeSpan timeUntilNextMarketOpen)
194  {
195  return Invariant($"DefaultBrokerageMessageHandler.Handle(): TimeUntilNextMarketOpen: {timeUntilNextMarketOpen}");
196  }
197  }
198 
199  /// <summary>
200  /// Provides user-facing messages for the <see cref="Brokerages.ExanteBrokerageModel"/> class and its consumers or related classes
201  /// </summary>
202  public static class ExanteBrokerageModel
203  {
204  public static string NullOrder = "Order is null.";
205 
206  public static string PriceNotSet = "Price is not set.";
207  }
208 
209  /// <summary>
210  /// Provides user-facing messages for the <see cref="Brokerages.FTXBrokerageModel"/> class and its consumers or related classes
211  /// </summary>
212  public static class FTXBrokerageModel
213  {
214  public static string TriggerPriceTooHigh = "Trigger price too high: must be below current market price.";
215 
216  public static string TriggerPriceTooLow = "Trigger price too low: must be above current market price.";
217  }
218 
219  /// <summary>
220  /// Provides user-facing messages for the <see cref="Brokerages.FxcmBrokerageModel"/> class and its consumers or related classes
221  /// </summary>
222  public static class FxcmBrokerageModel
223  {
224  public static string InvalidOrderPrice =
225  "Limit Buy orders and Stop Sell orders must be below market, Limit Sell orders and Stop Buy orders must be above market.";
226 
227  [MethodImpl(MethodImplOptions.AggressiveInlining)]
228  public static string InvalidOrderQuantityForLotSize(Securities.Security security)
229  {
230  return Invariant($"The order quantity must be a multiple of LotSize: [{security.SymbolProperties.LotSize}].");
231  }
232 
233  [MethodImpl(MethodImplOptions.AggressiveInlining)]
234  public static string PriceOutOfRange(OrderType orderType, OrderDirection orderDirection, decimal orderPrice, decimal currentPrice)
235  {
236  return Invariant($@"The {orderType} {orderDirection} order price ({
237  orderPrice}) is too far from the current market price ({currentPrice}).");
238  }
239  }
240 
241  /// <summary>
242  /// Provides user-facing messages for the <see cref="Brokerages.CoinbaseBrokerageModel"/> class and its consumers or related classes
243  /// </summary>
244  public static class CoinbaseBrokerageModel
245  {
246  public static string UnsupportedAccountType = "The Coinbase brokerage does not currently support Margin trading.";
247 
248  [MethodImpl(MethodImplOptions.AggressiveInlining)]
249  public static string StopMarketOrdersNoLongerSupported(DateTime stopMarketOrderSupportEndDate)
250  {
251  return Invariant($"Stop Market orders are no longer supported since {stopMarketOrderSupportEndDate}.");
252  }
253  }
254 
255  /// <summary>
256  /// Provides user-facing messages for the <see cref="Brokerages.InteractiveBrokersBrokerageModel"/> class and its consumers or related classes
257  /// </summary>
259  {
260  [MethodImpl(MethodImplOptions.AggressiveInlining)]
261  public static string UnsupportedExerciseForIndexAndCashSettledOptions(Brokerages.InteractiveBrokersBrokerageModel brokerageModel,
262  Orders.Order order)
263  {
264  return Invariant($@"The {brokerageModel.GetType().Name} does not support {
265  order.Type} exercises for index and cash-settled options.");
266  }
267 
268  [MethodImpl(MethodImplOptions.AggressiveInlining)]
269  public static string InvalidForexOrderSize(decimal min, decimal max, string currency)
270  {
271  return Invariant($"The minimum and maximum limits for the allowable order size are ({min}, {max}){currency}.");
272  }
273  }
274 
275  /// <summary>
276  /// Provides user-facing messages for the <see cref="Brokerages.TradierBrokerageModel"/> class and its consumers or related classes
277  /// </summary>
278  public static class TradierBrokerageModel
279  {
280  public static string UnsupportedSecurityType = "This model only supports equities and options.";
281 
282  public static string UnsupportedTimeInForceType = $"This model only supports orders with the following time in force types: {typeof(DayTimeInForce)} and {typeof(GoodTilCanceledTimeInForce)}";
283 
284  public static string ExtendedMarketHoursTradingNotSupported =
285  "Tradier does not support extended market hours trading. Your order will be processed at market open.";
286 
287  public static string OrderQuantityUpdateNotSupported = "Tradier does not support updating order quantities.";
288 
289  public static string OpenOrdersCancelOnReverseSplitSymbols = "Tradier Brokerage cancels open orders on reverse split symbols";
290 
291  public static string ShortOrderIsGtc = "You cannot place short stock orders with GTC, only day orders are allowed";
292 
293  public static string SellShortOrderLastPriceBelow5 = "Sell Short order cannot be placed for stock priced below $5";
294 
295  public static string IncorrectOrderQuantity = "Quantity should be between 1 and 10,000,000";
296  }
297 
298  /// <summary>
299  /// Provides user-facing messages for the <see cref="Brokerages.TradingTechnologiesBrokerageModel"/> class and its consumers or related classes
300  /// </summary>
302  {
303  public static string InvalidStopMarketOrderPrice =
304  "StopMarket Sell orders must be below market, StopMarket Buy orders must be above market.";
305 
306  public static string InvalidStopLimitOrderPrice =
307  "StopLimit Sell orders must be below market, StopLimit Buy orders must be above market.";
308 
309  public static string InvalidStopLimitOrderLimitPrice =
310  "StopLimit Buy limit price must be greater than or equal to stop price, StopLimit Sell limit price must be smaller than or equal to stop price.";
311  }
312 
313  /// <summary>
314  /// Provides user-facing messages for the <see cref="Brokerages.WolverineBrokerageModel"/> class and its consumers or related classes
315  /// </summary>
316  public static class WolverineBrokerageModel
317  {
318  [MethodImpl(MethodImplOptions.AggressiveInlining)]
319  public static string UnsupportedOrderType(Orders.Order order)
320  {
321  return Invariant($"{order.Type} order is not supported by Wolverine. Currently, only Market Order is supported.");
322  }
323  }
324 
325  /// <summary>
326  /// Provides user-facing messages for the <see cref="Brokerages.RBIBrokerageModel"/> class and its consumers or related classes
327  /// </summary>
328  public static class RBIBrokerageModel
329  {
330  [MethodImpl(MethodImplOptions.AggressiveInlining)]
331  public static string UnsupportedOrderType(Orders.Order order)
332  {
333  return Invariant($"{order.Type} order is not supported by RBI. Currently, only Market Order, Limit Order, StopMarket Order and StopLimit Order are supported.");
334  }
335  }
336  }
337 }