Lean  $LEAN_TAG$
TradeStationFeeModel.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 System;
19 
21 {
22  /// <summary>
23  /// Represents a fee model specific to TradeStation.
24  /// </summary>
25  /// <see href="https://www.tradestation.com/pricing"/>
26  /// <remarks>
27  /// It is $0 for domestic and $5 for international clients for normal equities trades up to 10,000 shares, then $0.005 per share after.
28  /// Options are $0.60 per contract, per side, and an extra $1 for index options
29  /// </remarks>
31  {
32  /// <summary>
33  /// Represents the fee associated with equity options transactions (per contract).
34  /// </summary>
35  private const decimal _equityOptionFee = 0.6m;
36 
37  /// <summary>
38  /// Represents the fee associated with index options transactions (per contract).
39  /// </summary>
40  private const decimal _indexOptionFee = 1m;
41 
42  /// <summary>
43  /// Represents the fee associated with futures transactions (per contract, per side).
44  /// </summary>
45  private const decimal _futuresFee = 1.5m;
46 
47  /// <summary>
48  /// Gets the commission per trade based on the residency status of the entity or person.
49  /// </summary>
50  private decimal CommissionPerTrade => USResident ? 0m : 5.0m;
51 
52  /// <summary>
53  /// Gets or sets a value indicating whether the entity or person is a resident of the United States.
54  /// </summary>
55  /// <value>
56  /// <c>true</c> if the entity or person is a US resident; otherwise, <c>false</c>.
57  /// </value>
58  public bool USResident { get; set; }
59 
60  /// <summary>
61  /// Initializes a new instance of the <see cref="TradeStationFeeModel"/> class.
62  /// </summary>
63  /// <param name="usResident">
64  /// A boolean value indicating whether the entity or person is a US resident.
65  /// Default is <c>true</c>.
66  /// </param>
67  public TradeStationFeeModel(bool usResident = true)
68  {
69  USResident = usResident;
70  }
71 
72  /// <summary>
73  /// Calculates the order fee based on the security type and order parameters.
74  /// </summary>
75  /// <param name="parameters">The parameters for the order fee calculation, which include security and order details.</param>
76  /// <returns>
77  /// An <see cref="OrderFee"/> instance representing the calculated order fee.
78  /// </returns>
79  /// <exception cref="ArgumentNullException">
80  /// Thrown when <paramref name="parameters"/> is <c>null</c>.
81  /// </exception>
82  public override OrderFee GetOrderFee(OrderFeeParameters parameters)
83  {
84  if (parameters == null)
85  {
86  throw new ArgumentNullException(nameof(parameters), "Order fee parameters cannot be null.");
87  }
88 
89  switch (parameters.Security.Type)
90  {
91  case SecurityType.Option:
92  return new OrderFee(new CashAmount(CommissionPerTrade + parameters.Order.AbsoluteQuantity * _equityOptionFee, Currencies.USD));
93  case SecurityType.IndexOption:
94  return new OrderFee(new CashAmount(CommissionPerTrade + parameters.Order.AbsoluteQuantity * _indexOptionFee, Currencies.USD));
95  case SecurityType.Future:
96  return new OrderFee(new CashAmount(parameters.Order.AbsoluteQuantity * _futuresFee, Currencies.USD));
97  default:
98  return new OrderFee(new CashAmount(CommissionPerTrade, Currencies.USD));
99  }
100  }
101  }
102 }