Lean  $LEAN_TAG$
RBIBrokerageModel.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  /// RBI Brokerage model
26  /// </summary>
28  {
29  /// <summary>
30  /// Array's RBI supports security types
31  /// </summary>
32  private readonly HashSet<SecurityType> _supportSecurityTypes = new (new [] { SecurityType.Equity });
33 
34  /// <summary>
35  /// Array's RBI supports order types
36  /// </summary>
37  private readonly HashSet<OrderType> _supportOrderTypes = new(new [] { OrderType.Market, OrderType.Limit, OrderType.StopMarket, OrderType.StopLimit });
38 
39  /// <summary>
40  /// Constructor for RBI brokerage model
41  /// </summary>
42  /// <param name="accountType">Cash or Margin</param>
43  public RBIBrokerageModel(AccountType accountType = AccountType.Margin) : base(accountType)
44  {
45  }
46 
47  /// <summary>
48  /// Returns true if the brokerage could accept this order. This takes into account
49  /// order type, security type, and order size limits.
50  /// </summary>
51  /// <remarks>
52  /// For example, a brokerage may have no connectivity at certain times, or an order rate/size limit
53  /// </remarks>
54  /// <param name="security">The security of the order</param>
55  /// <param name="order">The order to be processed</param>
56  /// <param name="message">If this function returns false, a brokerage message detailing why the order may not be submitted</param>
57  /// <returns>True if the brokerage could process the order, false otherwise</returns>
58  public override bool CanSubmitOrder(Security security, Order order, out BrokerageMessageEvent message)
59  {
60  if (!IsValidOrderSize(security, order.Quantity, out message))
61  {
62  return false;
63  }
64 
65  message = null;
66  if (!_supportSecurityTypes.Contains(security.Type))
67  {
68  message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
70 
71  return false;
72  }
73 
74  if (!_supportOrderTypes.Contains(order.Type))
75  {
76  message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
78 
79  return false;
80  }
81 
82  return base.CanSubmitOrder(security, order, out message);
83  }
84 
85  /// <summary>
86  /// RBI supports UpdateOrder
87  /// </summary>
88  /// <param name="security">Security</param>
89  /// <param name="order">Order that should be updated</param>
90  /// <param name="request">Update request</param>
91  /// <param name="message">Outgoing message</param>
92  /// <returns>True if the brokerage would allow updating the order, false otherwise</returns>
93  public override bool CanUpdateOrder(Security security, Order order, UpdateOrderRequest request, out BrokerageMessageEvent message)
94  {
95  message = null;
96  return true;
97  }
98 
99  /// <summary>
100  /// Provides RBI fee model
101  /// </summary>
102  /// <param name="security">Security</param>
103  /// <returns>RBI fee model</returns>
104  public override IFeeModel GetFeeModel(Security security)
105  {
106  return new RBIFeeModel();
107  }
108  }
109 }