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; } = true;
59 
60  /// <summary>
61  /// Calculates the order fee based on the security type and order parameters.
62  /// </summary>
63  /// <param name="parameters">The parameters for the order fee calculation, which include security and order details.</param>
64  /// <returns>
65  /// An <see cref="OrderFee"/> instance representing the calculated order fee.
66  /// </returns>
67  /// <exception cref="ArgumentNullException">
68  /// Thrown when <paramref name="parameters"/> is <c>null</c>.
69  /// </exception>
70  public override OrderFee GetOrderFee(OrderFeeParameters parameters)
71  {
72  if (parameters == null)
73  {
74  throw new ArgumentNullException(nameof(parameters), "Order fee parameters cannot be null.");
75  }
76 
77  switch (parameters.Security.Type)
78  {
79  case SecurityType.Option:
80  return new OrderFee(new CashAmount(CommissionPerTrade + parameters.Order.AbsoluteQuantity * _equityOptionFee, Currencies.USD));
81  case SecurityType.IndexOption:
82  return new OrderFee(new CashAmount(CommissionPerTrade + parameters.Order.AbsoluteQuantity * _indexOptionFee, Currencies.USD));
83  case SecurityType.Future:
84  return new OrderFee(new CashAmount(parameters.Order.AbsoluteQuantity * _futuresFee, Currencies.USD));
85  default:
86  return new OrderFee(new CashAmount(CommissionPerTrade, Currencies.USD));
87  }
88  }
89  }
90 }