Lean  $LEAN_TAG$
CharlesSchwabBrokerageModel.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 
17 using QuantConnect.Orders;
20 using System.Collections.Generic;
21 
23 {
24  /// <summary>
25  /// Represents a brokerage model specific to Charles Schwab.
26  /// </summary>
28  {
29  /// <summary>
30  /// HashSet containing the security types supported by TradeStation.
31  /// </summary>
32  private readonly HashSet<SecurityType> _supportSecurityTypes = new(
33  new[]
34  {
35  SecurityType.Equity,
36  SecurityType.Option,
37  SecurityType.IndexOption
38  });
39 
40  /// <summary>
41  /// HashSet containing the order types supported by the <see cref="CanSubmitOrder"/> operation in TradeStation.
42  /// </summary>
43  private readonly HashSet<OrderType> _supportOrderTypes = new(
44  new[]
45  {
46  OrderType.Market,
47  OrderType.Limit,
48  OrderType.StopMarket,
49  OrderType.ComboMarket,
50  OrderType.ComboLimit,
51  OrderType.MarketOnClose
52  });
53 
54  /// <summary>
55  /// Constructor for Charles Schwab brokerage model
56  /// </summary>
57  /// <param name="accountType">Cash or Margin</param>
59  : base(accountType)
60  {
61  }
62 
63  /// <summary>
64  /// Provides TradeStation fee model
65  /// </summary>
66  /// <param name="security">Security</param>
67  /// <returns>TradeStation fee model</returns>
68  public override IFeeModel GetFeeModel(Security security)
69  {
70  return new CharlesSchwabFeeModel();
71  }
72 
73  /// <summary>
74  /// Returns true if the brokerage could accept this order. This takes into account
75  /// order type, security type, and order size limits.
76  /// </summary>
77  /// <remarks>
78  /// For example, a brokerage may have no connectivity at certain times, or an order rate/size limit
79  /// </remarks>
80  /// <param name="security">The security of the order</param>
81  /// <param name="order">The order to be processed</param>
82  /// <param name="message">If this function returns false, a brokerage message detailing why the order may not be submitted</param>
83  /// <returns>True if the brokerage could process the order, false otherwise</returns>
84  public override bool CanSubmitOrder(Security security, Order order, out BrokerageMessageEvent message)
85  {
86  message = default;
87 
88  if (!_supportSecurityTypes.Contains(security.Type))
89  {
90  message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
92 
93  return false;
94  }
95 
96  if (!_supportOrderTypes.Contains(order.Type))
97  {
98  message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported", Messages.DefaultBrokerageModel.UnsupportedOrderType(this, order, _supportOrderTypes));
99  return false;
100  }
101 
102  return base.CanSubmitOrder(security, order, out message);
103  }
104  }
105 }