Skip to content

Commit 9e8c220

Browse files
authored
OrderCommand should use default order properties (#9274)
1 parent 541513b commit 9e8c220

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,11 @@ public void SetTags(HashSet<string> tags)
12971297
/// <returns>The command result</returns>
12981298
public CommandResultPacket RunCommand(CallbackCommand command) => _baseAlgorithm.RunCommand(command);
12991299

1300+
/// <summary>
1301+
/// Gets the default order properties
1302+
/// </summary>
1303+
public IOrderProperties DefaultOrderProperties => _baseAlgorithm.DefaultOrderProperties;
1304+
13001305
/// <summary>
13011306
/// Dispose of this instance
13021307
/// </summary>

Common/Commands/OrderCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class OrderCommand : BaseCommand
7676
public override CommandResultPacket Run(IAlgorithm algorithm)
7777
{
7878
Symbol = GetSymbol(Ticker, SecurityType, Market, Symbol);
79-
var request = new SubmitOrderRequest(OrderType, Symbol.SecurityType, Symbol, Quantity, StopPrice, LimitPrice, DateTime.UtcNow, Tag);
79+
var request = new SubmitOrderRequest(OrderType, Symbol.SecurityType, Symbol, Quantity, StopPrice, LimitPrice, DateTime.UtcNow, Tag, algorithm.DefaultOrderProperties);
8080
var ticket = algorithm.SubmitOrderRequest(request);
8181
var response = ticket.GetMostRecentOrderResponse();
8282
var message = Messages.OrderCommand.CommandInfo(OrderType, Symbol, Quantity, response);

Common/Interfaces/IAlgorithm.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,5 +952,10 @@ Security AddSecurity(Symbol symbol, Resolution? resolution = null, bool fillForw
952952
/// <param name="command">The callback command instance</param>
953953
/// <returns>The command result</returns>
954954
CommandResultPacket RunCommand(CallbackCommand command);
955+
956+
/// <summary>
957+
/// Gets the default order properties
958+
/// </summary>
959+
IOrderProperties DefaultOrderProperties { get; }
955960
}
956961
}

Tests/Common/Commands/OrderCommandTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using QuantConnect.Commands;
1919
using QuantConnect.Data.Market;
2020
using QuantConnect.Tests.Engine.DataFeeds;
21+
using System.Linq;
2122

2223
namespace QuantConnect.Tests.Common.Commands
2324
{
@@ -73,5 +74,29 @@ public void RunOrderCommand(bool warminUp, bool hasData, bool securityAdded, int
7374
Assert.IsFalse(response.Success);
7475
}
7576
}
77+
78+
[Test]
79+
public void OrderCommandUsesDefaultOrderProperties()
80+
{
81+
var command = new OrderCommand
82+
{
83+
Symbol = Symbols.AAPL,
84+
Quantity = 10,
85+
OrderType = OrderType.Market,
86+
};
87+
88+
var algorithm = new AlgorithmStub();
89+
algorithm.SetFinishedWarmingUp();
90+
var security = algorithm.AddEquity("AAPL");
91+
security.SetMarketPrice(new Tick { Value = 100 });
92+
93+
var response = command.Run(algorithm);
94+
Assert.IsTrue(response.Success);
95+
var ticket = algorithm.Transactions.GetOrderTickets().FirstOrDefault();
96+
Assert.NotNull(ticket);
97+
var orderProperties = ticket.SubmitRequest.OrderProperties;
98+
Assert.NotNull(orderProperties);
99+
Assert.AreEqual(TimeInForce.GoodTilCanceled, orderProperties.TimeInForce);
100+
}
76101
}
77102
}

0 commit comments

Comments
 (0)