Trading and Orders

Order Properties

Introduction

Order properties enable you to customize how the brokerage executes your orders. The DefaultOrderProperties of your algorithm sets the order properties for all of your orders. To adjust the order properties of an order, you can change the DefaultOrderProperties or pass an order properties object to the order method.

Time In Force

The TimeInForce property determines how long an order should remain open if it doesn't fill. This property doesn't apply to market orders since they usually fill immediately. Time in force is useful to automatically cancel old trades. The following table describes the available TimeInForce options:

MemberExampleDescription
GoodTilCanceledTimeInForce.GoodTilCanceledOrder is valid until filled (default)
DayTimeInForce.DayOrder is valid until filled or the market closes
GoodTilDate(DateTime expiry)GoodTilDate(expiry: datetime)TimeInForce.GoodTilDate(new DateTime(2019, 6, 19, 12, 0, 0))GoodTilDate(datetime(2019, 6, 19, 12, 0, 0))Order is valid until filled or the specified expiration time

By default, orders remain open until they are canceled (TimeInForce.GoodTilCanceled). To update the value, set the DefaultOrderProperties.TimeInForce before you place an order or pass an orderProperties argument to the order method.

// Set a Limit Order to be good until market close
DefaultOrderProperties.TimeInForce = TimeInForce.Day;
LimitOrder("IBM", 100, 120);

// Set a Limit Order to be good until noon
LimitOrder("IBM", 100, 120, orderProperties: new OrderProperties 
{
    TimeInForce = TimeInForce.GoodTilDate(new DateTime(2019, 6, 19, 12, 0, 0))
});
# Set a Limit Order to be good until market close
self.default_order_properties.time_in_force = TimeInForce.DAY
self.limit_order("IBM", 100, 120)

# Set a Limit Order to be good until noon
order_properties = OrderProperties()
order_properties.time_in_force = TimeInForce.good_til_date(datetime(2019, 6, 19, 12, 0, 0))
self.limit_order("IBM", 100, 120, order_properties=order_properties)

If you trade a market that's open 24 hours a day with daily data, TimeInForce.Day won't work because the order cancels at the market close time but your algorithm receives daily data at midnight.

Market on open (MOO) and market on close (MOC) orders don't support the GoodTilDate time in force. If you submit a MOO or MOC order with the GoodTilDate time in force, LEAN automatically adjusts the time in force to be GoodTilCanceled.

The brokerage you use may not support all of the TimeInForce options. To see the options that your brokerage supports, see the Orders section of the brokerage model documentation.

Brokerage-Specific Properties

Some brokerages support additional order properties so you can customize how your orders execute. Some examples include the following order properties:

  • Financial Advisor group orders
  • An OutsideRegularTradingHours property to let orders fill during pre-market and post-market trading hours
  • A PostOnly property to force an order to only add liquidity to a market
  • A Hidden property to make an order not show on the order book
  • A ReduceOnly property to signal the order must only decrease your position size
  • FeeInBase and FeeInQuote properties to set which currency you pay fees in for a Crypto trade

To view the order properties your brokerage supports, see the Orders section of the brokerage model documentation.

Tags

You can tag orders to aid your strategy development. Tags can be any string of up to 100 characters. Tags aren't part of the OrderProperties object, but they are a property of the Order class you can set. To set an order tag, pass it as an argument when you create the order or use the order update methods.

// Tag an order on creation
var ticket = LimitOrder("SPY", 100, 221.05, tag: "Original tag");

// Update the tag with UpdateTag
ticket.UpdateTag("Updated tag");

// Update the tag with UpdateOrderFields
ticket.Update(new() { Tag = "Another tag" });
 # Tag an order on creation
ticket = self.limit_order("SPY", 100, 221.05, "Original tag")

# Update the tag with UpdateTag
ticket.update_tag("Updated tag")

# Update the tag with UpdateOrderFields
update_settings = UpdateOrderFields()
update_settings.tag = "Another tag"
ticket.update(update_settings)

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: