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 futures transactions (per contract, per side).
39  /// </summary>
40  private const decimal _futuresFee = 1.5m;
41 
42  /// <summary>
43  /// Gets the commission per trade based on the residency status of the entity or person.
44  /// </summary>
45  private decimal CommissionPerTrade => USResident ? 0m : 5.0m;
46 
47  /// <summary>
48  /// Gets or sets a value indicating whether the entity or person is a resident of the United States.
49  /// </summary>
50  /// <value>
51  /// <c>true</c> if the entity or person is a US resident; otherwise, <c>false</c>.
52  /// </value>
53  public bool USResident { get; set; } = true;
54 
55  /// <summary>
56  /// Calculates the order fee based on the security type and order parameters.
57  /// </summary>
58  /// <param name="parameters">The parameters for the order fee calculation, which include security and order details.</param>
59  /// <returns>
60  /// An <see cref="OrderFee"/> instance representing the calculated order fee.
61  /// </returns>
62  /// <exception cref="ArgumentNullException">
63  /// Thrown when <paramref name="parameters"/> is <c>null</c>.
64  /// </exception>
65  public override OrderFee GetOrderFee(OrderFeeParameters parameters)
66  {
67  if (parameters == null)
68  {
69  throw new ArgumentNullException(nameof(parameters), "Order fee parameters cannot be null.");
70  }
71 
72  switch (parameters.Security.Type)
73  {
74  case SecurityType.Option:
75  return new OrderFee(new CashAmount(CommissionPerTrade + parameters.Order.AbsoluteQuantity * _equityOptionFee, Currencies.USD));
76  case SecurityType.Future:
77  return new OrderFee(new CashAmount(parameters.Order.AbsoluteQuantity * _futuresFee, Currencies.USD));
78  default:
79  return new OrderFee(new CashAmount(CommissionPerTrade, Currencies.USD));
80  }
81  }
82  }
83 }