-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Implementation Trade Station Brokerage (#8031)
* refactor: make public futuresMonth Collection * feat: TradeStation brokerage * feat: PositionSide for Option in TradeStationOrderProperties * feat: missed market TradeStation name * feat: missed config TradeStation * remove: extra TradeStation code * remove: pragrma warning * feat: implement TradeStationFeeModel
- Loading branch information
Showing
7 changed files
with
277 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using QuantConnect.Orders; | ||
using QuantConnect.Securities; | ||
using QuantConnect.Orders.Fees; | ||
using System.Collections.Generic; | ||
|
||
namespace QuantConnect.Brokerages | ||
{ | ||
/// <summary> | ||
/// Represents a brokerage model specific to TradeStation. | ||
/// </summary> | ||
public class TradeStationBrokerageModel : DefaultBrokerageModel | ||
{ | ||
/// <summary> | ||
/// HashSet containing the security types supported by TradeStation. | ||
/// </summary> | ||
private readonly HashSet<SecurityType> _supportSecurityTypes = new( | ||
new[] | ||
{ | ||
SecurityType.Equity, | ||
SecurityType.Option, | ||
SecurityType.Future | ||
}); | ||
|
||
/// <summary> | ||
/// HashSet containing the order types supported by TradeStation. | ||
/// </summary> | ||
private readonly HashSet<OrderType> _supportOrderTypes = new( | ||
new[] | ||
{ | ||
OrderType.Market, | ||
OrderType.Limit, | ||
OrderType.StopMarket, | ||
OrderType.StopLimit | ||
}); | ||
|
||
/// <summary> | ||
/// Constructor for TradeStation brokerage model | ||
/// </summary> | ||
/// <param name="accountType">Cash or Margin</param> | ||
public TradeStationBrokerageModel(AccountType accountType = AccountType.Margin) | ||
: base(accountType) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Provides TradeStation fee model | ||
/// </summary> | ||
/// <param name="security">Security</param> | ||
/// <returns>TradeStation fee model</returns> | ||
public override IFeeModel GetFeeModel(Security security) | ||
{ | ||
return new TradeStationFeeModel(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the brokerage could accept this order. This takes into account | ||
/// order type, security type, and order size limits. | ||
/// </summary> | ||
/// <remarks> | ||
/// For example, a brokerage may have no connectivity at certain times, or an order rate/size limit | ||
/// </remarks> | ||
/// <param name="security">The security of the order</param> | ||
/// <param name="order">The order to be processed</param> | ||
/// <param name="message">If this function returns false, a brokerage message detailing why the order may not be submitted</param> | ||
/// <returns>True if the brokerage could process the order, false otherwise</returns> | ||
public override bool CanSubmitOrder(Security security, Order order, out BrokerageMessageEvent message) | ||
{ | ||
message = default; | ||
|
||
if (!_supportSecurityTypes.Contains(security.Type)) | ||
{ | ||
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported", | ||
Messages.DefaultBrokerageModel.UnsupportedSecurityType(this, security)); | ||
|
||
return false; | ||
} | ||
|
||
if (!_supportOrderTypes.Contains(order.Type)) | ||
{ | ||
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported", | ||
Messages.DefaultBrokerageModel.UnsupportedOrderType(this, order, _supportOrderTypes)); | ||
|
||
return false; | ||
} | ||
|
||
return base.CanSubmitOrder(security, order, out message); | ||
} | ||
|
||
/// <summary> | ||
/// TradeStation support Update Order | ||
/// </summary> | ||
/// <param name="security">Security</param> | ||
/// <param name="order">Order that should be updated</param> | ||
/// <param name="request">Update request</param> | ||
/// <param name="message">Outgoing message</param> | ||
/// <returns>True if the brokerage would allow updating the order, false otherwise</returns> | ||
public override bool CanUpdateOrder(Security security, Order order, UpdateOrderRequest request, out BrokerageMessageEvent message) | ||
{ | ||
message = null; | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System; | ||
using QuantConnect.Securities; | ||
|
||
namespace QuantConnect.Orders.Fees | ||
{ | ||
/// <summary> | ||
/// Represents a fee model specific to TradeStation. | ||
/// </summary> | ||
/// <see href="https://www.tradestation.com/pricing"/> | ||
/// <remarks> | ||
/// 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. | ||
/// Options are $0.60 per contract, per side, and an extra $1 for index options | ||
/// </remarks> | ||
public class TradeStationFeeModel : FeeModel | ||
{ | ||
/// <summary> | ||
/// Represents the fee associated with equity options transactions (per contract). | ||
/// </summary> | ||
private const decimal _equityOptionFee = 0.6m; | ||
|
||
/// <summary> | ||
/// Represents the fee associated with futures transactions (per contract, per side). | ||
/// </summary> | ||
private const decimal _futuresFee = 1.5m; | ||
|
||
/// <summary> | ||
/// Gets the commission per trade based on the residency status of the entity or person. | ||
/// </summary> | ||
private decimal CommissionPerTrade => USResident ? 0m : 5.0m; | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the entity or person is a resident of the United States. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if the entity or person is a US resident; otherwise, <c>false</c>. | ||
/// </value> | ||
public bool USResident { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Calculates the order fee based on the security type and order parameters. | ||
/// </summary> | ||
/// <param name="parameters">The parameters for the order fee calculation, which include security and order details.</param> | ||
/// <returns> | ||
/// An <see cref="OrderFee"/> instance representing the calculated order fee. | ||
/// </returns> | ||
/// <exception cref="ArgumentNullException"> | ||
/// Thrown when <paramref name="parameters"/> is <c>null</c>. | ||
/// </exception> | ||
public override OrderFee GetOrderFee(OrderFeeParameters parameters) | ||
{ | ||
if (parameters == null) | ||
{ | ||
throw new ArgumentNullException(nameof(parameters), "Order fee parameters cannot be null."); | ||
} | ||
|
||
switch (parameters.Security.Type) | ||
{ | ||
case SecurityType.Option: | ||
return new OrderFee(new CashAmount(CommissionPerTrade + parameters.Order.AbsoluteQuantity * _equityOptionFee, Currencies.USD)); | ||
case SecurityType.Future: | ||
return new OrderFee(new CashAmount(parameters.Order.AbsoluteQuantity * _futuresFee, Currencies.USD)); | ||
default: | ||
return new OrderFee(new CashAmount(CommissionPerTrade, Currencies.USD)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
namespace QuantConnect.Orders | ||
{ | ||
/// <summary> | ||
/// Represents the properties of an order in TradeStation. | ||
/// </summary> | ||
public class TradeStationOrderProperties : OrderProperties | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters