Lean  $LEAN_TAG$
FTXFeeModel.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 
17 
19 {
20  /// <summary>
21  /// Provides an implementation of <see cref="FeeModel"/> that models FTX order fees
22  /// https://help.ftx.com/hc/en-us/articles/360024479432-Fees
23  /// </summary>
24  public class FTXFeeModel : FeeModel
25  {
26  /// <summary>
27  /// Tier 1 maker fees
28  /// </summary>
29  public virtual decimal MakerFee => 0.0002m;
30 
31  /// <summary>
32  /// Tier 1 taker fees
33  /// </summary>
34  public virtual decimal TakerFee => 0.0007m;
35 
36  /// <summary>
37  /// Get the fee for this order in quote currency
38  /// </summary>
39  /// <param name="parameters">A <see cref="OrderFeeParameters"/> object
40  /// containing the security and order</param>
41  /// <returns>The cost of the order in quote currency</returns>
42  public override OrderFee GetOrderFee(OrderFeeParameters parameters)
43  {
44  var order = parameters.Order;
45  var security = parameters.Security;
46  var props = order.Properties as FTXOrderProperties;
47 
48  //taker by default
49  var fee = TakerFee;
50  var unitPrice = order.Direction == OrderDirection.Buy ? security.AskPrice : security.BidPrice;
51  unitPrice *= security.SymbolProperties.ContractMultiplier;
52  var currency = security.QuoteCurrency.Symbol;
53 
54  //maker if limit
55  if (order.Type == OrderType.Limit && (props?.PostOnly == true || !order.IsMarketable))
56  {
57  fee = MakerFee;
58  if (order.Direction == OrderDirection.Buy)
59  {
60  unitPrice = 1;
61  currency = ((IBaseCurrencySymbol)security).BaseCurrency.Symbol;
62  }
63  }
64 
65  // apply fee factor, currently we do not model 30-day volume, so we use the first tier
66  return new OrderFee(new CashAmount(
67  unitPrice * order.AbsoluteQuantity * fee,
68  currency));
69  }
70  }
71 }