Tracking and managing orders is an important part of an algorithmic trading strategy. Intelligent order management encourages discipline and a deep understanding of your algorithm. Through the QuantConnect API you can get order fields, update their values and cancel pending orders. This can be useful for lowering trading costs and improving order fills.
When you place a trade you receive an
OrderTicket for you to access the order. This allows you to safely (asynchronously) update and cancel the order while in live trading. In live trading you cannot assume order updates are processed successfully as the brokerage may have already filled the trade.
You can place several types of orders including:
|Supported Order Types
var ticket = LimitOrder("SPY", 100, 100.10m);
|Stop Market Order
var ticket = StopMarketOrder("SPY", 100, 100.10m);
|Stop Limit Order
var ticket = StopLimitOrder("SPY", 100, 100.12m, 99.5m);
|Market On Open Order
var ticket = MarketOnOpen("SPY", 100);
|Market On Close Order
var ticket = MarketOnClose("SPY", 100);
Once you have an order ticket you can use it to get order fields:
var currentStopPrice = _ticket.Get(OrderField.StopPrice);
Or update the order fields (LimitPrice, StopPrice, Tag or Quantity):
LimitPrice = newLongLimit,
Tag = "Update #" + (longOrder.UpdateRequests.Count + 1)
You can also cancel your order if required:
In the video below we demonstrate putting it all together to create a moving take-profit order which gradually decreases its profit target as time passes.