Supported Models
Equity Model
Introduction
The EquityFillModel
is the default fill model if you trade Equity assets with the DefaultBrokerageModel. This fill model fills trades completely and immediately.
security.SetFillModel(new EquityFillModel());
security.SetFillModel(EquityFillModel())
The fill logic of each order depends on the order type, the data format of the security subscription, and the order direction. The following tables show the fill price of each order given these factors. To determine the fill price of an order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
To view the implementation of this model, see the LEAN GitHub repository.
Market Orders
The model fills buy market orders at the best effort ask price and fills sell market orders at the best effort bid price.
To get the best effort bid price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a buy quote, use the bid price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing bid price of the most recentQuoteBar
.
To get the best effort ask price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a sell quote, use the ask price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing ask price of the most recentQuoteBar
.
If neither of the preceding procedures yield a result, the model uses the following procedure to get the best effort bid or ask price:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a tick of typeTickType.Trade
, use the last trade price. - If the subscription provides
TradeBar
data, use the closing bid price of the most recentQuoteBar
.
The model only fills market orders during regular trading hours.
Limit Orders
The fill logic of limit orders depends on the data format of the security subscription and the order direction. The following table shows the fill price of limit orders given these factors. To determine the fill price of the order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
Data Format | TickType | Order Direction | Fill Condition | Fill Price |
---|---|---|---|---|
Tick | Quote | Buy | quote price < limit price | min(quote price, limit price) |
Tick | Quote | Sell | quote price > limit price | max(quote price, limit price) |
Tick | Trade | Buy | trade price < limit price | min(trade price, limit price) |
Tick | Trade | Sell | trade price > limit price | max(trade price, limit price) |
QuoteBar | Buy | ask low price < limit price | min(ask high price, limit price) | |
QuoteBar | Sell | bid high price > limit price | max(bid low price, limit price) | |
TradeBar | Buy | low price < limit price | min(high price, limit price) | |
TradeBar | Sell | high price > limit price | max(low price, limit price) |
The model won't fill limit orders with stale data.
Limit if Touched Orders
The model converts a limit if touched order to a limit order when the trigger condition is met. The following table describes the trigger condition of limit if touched orders for each data format and order direction:
Data Format | TickType | Order Direction | Trigger Condition |
---|---|---|---|
Tick | Trade | Buy | Trade price <= trigger price |
Tick | Trade | Sell | Trade price >= trigger price |
TradeBar | Buy | Low price <= trigger price | |
TradeBar | Sell | High price >= trigger price |
Once the limit if touched order triggers, to fill the order, the model checks the fill condition. The following table describes the fill condition and price of each order direction.
Order Direction | Fill Condition | Fill Price |
---|---|---|
Buy | Best effort ask price <= limit price | min(best effort ask price, limit price) |
Sell | Best effort bid price >= limit price | max(best effort bid price, limit price) |
To get the best effort bid price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a buy quote, use the bid price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing bid price of the most recentQuoteBar
.
To get the best effort ask price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a sell quote, use the ask price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing ask price of the most recentQuoteBar
.
If neither of the preceding procedures yield a result, the model uses the following procedure to get the best effort bid or ask price:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a tick of typeTickType.Trade
, use the last trade price. - If the subscription provides
TradeBar
data, use the closing bid price of the most recentQuoteBar
.
The model won't trigger or fill limit if touched orders with stale data.
Stop Market Orders
The fill logic of stop market orders depends on the data format of the security subscription and the order direction. The following table shows the fill price of stop market orders given these factors. To determine the fill price of the order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
Once the stop condition is met, the model fills the orders and sets the fill price.
Data Format | TickType | Order Direction | Stop Condition | Fill Price |
---|---|---|---|---|
Tick | Quote | Buy | quote price > stop price | max(stop price, quote price + slippage) |
Tick | Quote | Sell | quote price < stop price | min(stop price, quote price - slippage) |
Tick | Trade | Buy | trade price > stop price | max(stop price, last trade price + slippage) |
Tick | Trade | Sell | trade price < stop price | min(stop price, last trade price - slippage) |
QuoteBar | Buy | ask high price > stop price | max(stop price, ask close price + slippage) | |
QuoteBar | Sell | bid low price < stop price | min(stop price, bid close price - slippage) | |
TradeBar | Buy | high price > stop price | max(stop price, close price + slippage) | |
TradeBar | Sell | low price < stop price | min(stop price, close price - slippage) |
The model only fills stop market orders when the exchange is open. The model won't fill stop market orders with stale data.
Stop Limit Orders
The fill logic of stop limit orders depends on the data format of the security subscription and the order direction. The following table shows the fill price of stop limit orders given these factors. To determine the fill price of the order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
Once the stop condition is met, the model starts to check the fill condition. Once the fill condition is met, the model fills the orders and sets the fill price.
Data Format | TickType | Order Direction | Stop Condition | Fill Condition | Fill Price |
---|---|---|---|---|---|
Tick | Quote | Buy | quote price > stop price | quote price < limit price | min(quote price, limit price) |
Tick | Quote | Sell | quote price < stop price | quote price > limit price | max(quote price, limit price) |
Tick | Trade | Buy | trade price > stop price | trade price < limit price | min(trade price, limit price) |
Tick | Trade | Sell | trade price < stop price | trade price > limit price | max(trade price, limit price) |
QuoteBar | Buy | ask high price > stop price | ask close price < limit price | min(ask high price, limit price) | |
QuoteBar | Sell | bid low price < stop price | bid close price > limit price | max(bid low price, limit price) | |
TradeBar | Buy | high price > stop price | close price < limit price | min(high price, limit price) | |
TradeBar | Sell | low price < stop price | close price > limit price | max(low price, limit price) |
The model won't fill stop limit orders with stale data.
Market on Open Orders
The following table describes the fill price of market on open orders for each data format and order direction:
Data Format | Order Direction | Fill Price |
---|---|---|
Tick | Buy | If the model receives the official opening auction price within one minute, the order fills at official open price + slippage. After one minute, the order fills at the most recent trade price + slippage. If the security doesn't trade within the first two minutes, the order fills at the best effort ask price + slippage. |
Tick | Sell | If the model receives the official opening auction price within one minute, the order fills at the official open price - slippage. After one minute, the order fills at the most recent trade price - slippage. If the security doesn't trade within the first two minutes, the order fills at the best effort bid price - slippage. |
TradeBar | Buy | Open price + slippage |
TradeBar | Sell | Open price - slippage |
QuoteBar | Buy | Best effort ask price + slippage |
QuoteBar | Sell | Best effort bid price - slippage |
The model checks the data format in the following order:
Tick
TradeBar
QuoteBar
To get the best effort bid price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a buy quote, use the bid price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing bid price of the most recentQuoteBar
.
To get the best effort ask price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a sell quote, use the ask price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing ask price of the most recentQuoteBar
.
If neither of the preceding procedures yield a result, the model uses the following procedure to get the best effort bid or ask price:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a tick of typeTickType.Trade
, use the last trade price. - If the subscription provides
TradeBar
data, use the closing bid price of the most recentQuoteBar
.
Market on Close Orders
The following table describes the fill price of market on close orders for each data format and order direction:
Data Format | Order Direction | Fill Price |
---|---|---|
Tick | Buy | If the model receives the official opening auction price within one minute after the close, the order fills at official close price + slippage. After one minute, the order fills at the most recent trade price + slippage. If the security doesn't trade within the first two minutes, the order fills at the best effort ask price + slippage. |
Tick | Sell | If the model receives the official opening auction price within one minute after the close, the order fills at the official close price - slippage. After one minute, the order fills at the most recent trade price - slippage. If the security doesn't trade within the first two minutes after the close, the order fills at the best effort bid price - slippage. |
TradeBar | Buy | Open price + slippage |
TradeBar | Sell | Open price - slippage |
QuoteBar | Buy | Best effort ask price + slippage |
QuoteBar | Sell | Best effort bid price - slippage |
The model checks the data format in the following order:
Tick
TradeBar
QuoteBar
To get the best effort bid price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a buy quote, use the bid price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing bid price of the most recentQuoteBar
.
To get the best effort ask price, the model uses the following procedure:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a sell quote, use the ask price of the most recent quote tick. - If the subscription provides
QuoteBar
data, use the closing ask price of the most recentQuoteBar
.
If neither of the preceding procedures yield a result, the model uses the following procedure to get the best effort bid or ask price:
- If the subscription provides
Tick
data and the most recent batch of ticks contains a tick of typeTickType.Trade
, use the last trade price. - If the subscription provides
TradeBar
data, use the closing bid price of the most recentQuoteBar
.
Combo Market Orders
The fill logic of combo market orders depends on the data format of the security subscription and the order direction. The following table shows the fill price of combo market orders given these factors. To determine the fill price of the order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
Data Format | TickType | Order Direction | Fill Price |
---|---|---|---|
Tick | Quote | Buy | Ask quote price + slippage |
Tick | Quote | Sell | Bid quote price - slippage |
Tick | Trade | Buy | Trade price + slippage |
Tick | Trade | Sell | Trade price - slippage |
QuoteBar | Buy | Ask close price + slippage | |
QuoteBar | Sell | Bid close price - slippage | |
TradeBar | Buy | Close price + slippage | |
TradeBar | Sell | Close price - slippage |
The model only fills combo market orders if all the following conditions are met:
The fill quantity of each leg is the product of the leg order quantity and the combo market order quantity.
Combo Limit Orders
The fill logic of combo limit orders depends on the data format of the security subscription and the order direction. To determine the fill price of the order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
To fill combo limit orders, the fill model calculates the aggregate price of the combo order, which is the sum of prices for each security in the order legs. The price of each security is a function of the data format and order direction. Legs with a positive order quantity increase the aggregate price and legs with a negative quantity decrease the aggregate price. The following table shows how the fill model calculates the security prices.
Data Format | TickType | Combo Order Direction | Leg Order Direction | Price |
---|---|---|---|---|
Tick | Quote | Buy or sell | Buy | Ask price |
Tick | Quote | Buy or sell | Sell | Bid price |
Tick | Trade | Buy or sell | Buy or sell | Trade price |
QuoteBar | Buy | Buy | Ask low price | |
QuoteBar | Buy | Sell | Bid low price | |
QuoteBar | Sell | Buy | Ask high price | |
QuoteBar | Sell | Sell | Bid high price | |
TradeBar | Buy | Buy or sell | Low price | |
TradeBar | Sell | Buy or sell | High price |
After the fill model calculates the aggregate price of the combo order, it checks if it should fill the order. The following table describes the fill condition of the combo order and the fill price price of each leg:
Data Format | TickType | Combo Order Direction | Fill Condition | Leg Order Direction | Fill Price |
---|---|---|---|---|---|
Tick | Quote | Buy | Aggregate price < combo limit price | Buy or sell | Quote price |
Tick | Quote | Sell | Aggregate price > combo limit price | Buy or sell | Quote price |
Tick | Trade | Buy | Aggregate price < combo limit price | Buy or sell | Trade price |
Tick | Trade | Sell | Aggregate price > combo limit price | Buy or sell | Trade price |
QuoteBar | Buy | Aggregate price < combo limit price | Buy | Ask low price | |
QuoteBar | Buy | Aggregate price < combo limit price | Sell | Bid low price | |
QuoteBar | Sell | Aggregate price > combo limit price | Buy | Ask high price | |
QuoteBar | Sell | Aggregate price > combo limit price | Sell | Bid high price | |
TradeBar | Buy | Aggregate price < combo limit price | Buy or sell | Low price | |
TradeBar | Sell | Aggregate price > combo limit price | Buy or sell | High price |
The model only fills combo limit orders if the data isn't stale and all the legs can fill in the same time step. The fill quantity of each leg is the product of the leg order quantity and the combo order quantity.
Combo Leg Limit Orders
The fill logic of combo leg limit orders depends on the data format of the security subscription and the order direction. The following table shows the fill price of combo leg limit orders given these factors. To determine the fill price of the order, the fill model first checks the most recent tick for the security. If your security subscription doesn't provide tick data, the fill model checks the most recent QuoteBar
. If your security subscription doesn't provide quote data, the fill model checks the most recent TradeBar
.
The order direction in the table represents the order direction of the order leg, not the order direction of the combo order.
Data Format | TickType | Order Direction | Fill Condition | Fill Price |
---|---|---|---|---|
Tick | Quote | Buy | Ask price < limit price | min(ask price, limit price) |
Tick | Quote | Sell | Bid price > limit price | max(bid price, limit price) |
Tick | Trade | Buy | Trade price < limit price | min(trade price, limit price) |
Tick | Trade | Sell | Trade price > limit price | max(trade price, limit price) |
QuoteBar | Buy | Ask low price < limit price | min(ask high price, limit price) | |
QuoteBar | Sell | Bid high price > limit price | max(bid low price, limit price) | |
TradeBar | Buy | Low price < limit price | min(high price, limit price) | |
TradeBar | Sell | High price > limit price | max(low price, limit price) |
The model only fills combo leg limit orders if all the following conditions are met:
The fill quantity is the product of the leg order quantity and the combo order quantity.