Skip to content

LatestPriceFillModel

QuantConnect.Orders.Fills.LatestPriceFillModel

Bases: ImmediateFillModel

This fill model is provided for cases where the trade/quote distinction should be ignored and the fill price should be determined from the latest pricing information.

parameters

parameters: FillModelParameters

The parameters instance to be used by the different XxxxFill() implementations

This Property is protected.

python_wrapper

python_wrapper: FillModelPythonWrapper

This is required due to a limitation in PythonNet to resolved overriden methods. When Python calls a C# method that calls a method that's overriden in python it won't run the python implementation unless the call is performed through python too.

This Property is protected.

get_prices

get_prices(
    asset: Security, direction: OrderDirection
) -> Prices

Get the minimum and maximum price for this security in the last bar Ignore the Trade/Quote distinction - fill with the latest pricing information

This Class is protected.

Parameters:

Name Type Description Default
asset Security

Security asset we're checking

required
direction OrderDirection

The order direction, decides whether to pick bid or ask

required

fill

fill(parameters: FillModelParameters) -> Fill

Return an order event with the fill details

Parameters:

Name Type Description Default
parameters FillModelParameters

A FillModelParameters object containing the security and order

required

Returns:

Type Description
Fill

Order fill information detailing the average price and quantity filled.

combo_leg_limit_fill

combo_leg_limit_fill(
    order: Order, parameters: FillModelParameters
) -> List[OrderEvent]

Default combo limit fill model for the base security class. Fills at the limit price for each leg

Parameters:

Name Type Description Default
order Order

Order to fill

required
parameters FillModelParameters

Fill parameters for the order

required

Returns:

Type Description
List[OrderEvent]

Order fill information detailing the average price and quantity filled for each leg. If any of the fills fails, none of the orders will be filled and the returned list will be empty.

combo_limit_fill

combo_limit_fill(
    order: Order, parameters: FillModelParameters
) -> List[OrderEvent]

Default combo limit fill model for the base security class. Fills at the sum of prices for the assets of every leg.

Parameters:

Name Type Description Default
order Order

Order to fill

required
parameters FillModelParameters

Fill parameters for the order

required

Returns:

Type Description
List[OrderEvent]

Order fill information detailing the average price and quantity filled for each leg. If any of the fills fails, none of the orders will be filled and the returned list will be empty.

combo_market_fill

combo_market_fill(
    order: Order, parameters: FillModelParameters
) -> List[OrderEvent]

Default combo market fill model for the base security class. Fills at the last traded price for each leg.

Parameters:

Name Type Description Default
order Order

Order to fill

required
parameters FillModelParameters

Fill parameters for the order

required

Returns:

Type Description
List[OrderEvent]

Order fill information detailing the average price and quantity filled for each leg. If any of the fills fails, none of the orders will be filled and the returned list will be empty.

get_market_fill_price

get_market_fill_price(
    asset: Security,
    order: Order,
    prices: Prices,
    subscription_configs: List[
        SubscriptionDataConfig
    ] = None,
) -> float

Gets the fill price for a market order. A hour/daily market order that was resting before the current bar opened - it predates the bar, e.g. it was placed after the previous close or while waiting for fresh data - fills at the bar open (the price when trading resumed, like a MarketOnOpenOrder) instead of the bar close. An order placed during the bar still fills at the current price.

This Class is protected.

Parameters:

Name Type Description Default
asset Security

Security being filled

required
order Order

Order being filled

required
prices Prices

The prices for the bar being filled on

required
subscription_configs List[SubscriptionDataConfig]

The subscription configs for the security, including internal configurations. When not provided, they are fetched from the configuration provider

None

get_prices_checking_python_wrapper

get_prices_checking_python_wrapper(
    asset: Security, direction: OrderDirection
) -> Prices

This is required due to a limitation in PythonNet to resolved overriden methods. get_prices

This Class is protected.

get_subscribed_types

get_subscribed_types(asset: Security) -> HashSet[Type]

Get data types the Security is subscribed to

This Class is protected.

Parameters:

Name Type Description Default
asset Security

Security which has subscribed data types

required

get_subscription_data_configs

get_subscription_data_configs(
    asset: Security,
) -> List[SubscriptionDataConfig]

Gets the subscription data configs for the security, including internal configurations. Even though data from internal configurations is not sent to the algorithm.OnData, it still drives the security cache and the data used for the fill. This is specially relevant for the continuous contract underlying mapped contracts, which are internal configurations.

This Class is protected.

Parameters:

Name Type Description Default
asset Security

Security to get the subscription configs for

required

is_exchange_open

is_exchange_open(
    asset: Security, is_extended_market_hours: bool
) -> bool

Determines if the exchange is open using the current time of the asset

This Class is protected.

limit_fill

limit_fill(
    asset: Security, order: LimitOrder
) -> OrderEvent

Default limit order fill model in the base security class.

Parameters:

Name Type Description Default
asset Security

Security asset we're filling

required
order LimitOrder

Order packet to model

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

limit_if_touched_fill

limit_if_touched_fill(
    asset: Security, order: LimitIfTouchedOrder
) -> OrderEvent

Default limit if touched fill model implementation in base class security. (Limit If Touched Order Type)

Parameters:

Name Type Description Default
asset Security
required
order LimitIfTouchedOrder
required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

market_fill

market_fill(
    asset: Security, order: MarketOrder
) -> OrderEvent

Default market fill model for the base security class. Fills at the last traded price.

Parameters:

Name Type Description Default
asset Security

Security asset we're filling

required
order MarketOrder

Order packet to model

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

market_on_close_fill

market_on_close_fill(
    asset: Security, order: MarketOnCloseOrder
) -> OrderEvent

Market on Close Fill Model. Return an order event with the fill details

Parameters:

Name Type Description Default
asset Security

Asset we're trading with this order

required
order MarketOnCloseOrder

Order to be filled

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

market_on_open_fill

market_on_open_fill(
    asset: Security, order: MarketOnOpenOrder
) -> OrderEvent

Market on Open Fill Model. Return an order event with the fill details

Parameters:

Name Type Description Default
asset Security

Asset we're trading with this order

required
order MarketOnOpenOrder

Order to be filled

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

set_python_wrapper

set_python_wrapper(
    python_wrapper: FillModelPythonWrapper,
) -> None

Used to set the FillModelPythonWrapper instance if any

should_wait_for_fresh_data

should_wait_for_fresh_data(
    asset: Security,
    subscription_configs: List[
        SubscriptionDataConfig
    ] = None,
) -> bool

Determines whether a market order filling on stale data should wait for fresh data instead of filling on the stale price. This is only done for coarse resolutions (hour/daily), where the stale bar is the previous close and a fresh bar (the next close/open) is expected. For minute/second/tick subscriptions the previous behavior is kept (fill on the stale price with a warning), since stale data there represents a genuine gap rather than a bar still forming.

This Class is protected.

Parameters:

Name Type Description Default
asset Security

Security being filled

required
subscription_configs List[SubscriptionDataConfig]

The subscription configs for the security, including internal configurations. When not provided, they are fetched from the configuration provider

None

should_wait_for_fresh_data_on_stale

should_wait_for_fresh_data_on_stale(
    asset: Security,
    data_end_time_utc: Union[datetime, date],
    order_time_utc: Union[datetime, date],
    subscription_configs: List[
        SubscriptionDataConfig
    ] = None,
) -> bool

Determines whether a market order that would be filled on stale data should wait for fresh data instead of filling on the stale price. The order waits when the latest available data is more than one subscribed resolution span behind the order submission time, i.e. the data is older than a single bar so a newer one is still expected. This is independent of the time of day: it covers the market open (the first bar of the session has not been emitted yet) as well as any intraday data gap larger than the resolution.

Coarse resolutions (hour/daily) always wait, since there the stale bar is the previous close and the gap to the order time can be smaller than the resolution while a fresh bar is still expected. Tick subscriptions never wait, since there is no bar to expect.

This Class is protected.

Parameters:

Name Type Description Default
asset Security

Security being filled

required
data_end_time_utc Union[datetime, date]

End time, in UTC, of the latest data available for the fill

required
order_time_utc Union[datetime, date]

Order submission time, in UTC

required
subscription_configs List[SubscriptionDataConfig]

The subscription configs for the security, including internal configurations. When not provided, they are fetched from the configuration provider

None

stop_limit_fill

stop_limit_fill(
    asset: Security, order: StopLimitOrder
) -> OrderEvent

Default stop limit fill model implementation in base class security. (Stop Limit Order Type)

Parameters:

Name Type Description Default
asset Security

Security asset we're filling

required
order StopLimitOrder

Order packet to model

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

stop_market_fill

stop_market_fill(
    asset: Security, order: StopMarketOrder
) -> OrderEvent

Default stop fill model implementation in base class security. (Stop Market Order Type)

Parameters:

Name Type Description Default
asset Security

Security asset we're filling

required
order StopMarketOrder

Order packet to model

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.

trailing_stop_fill

trailing_stop_fill(
    asset: Security, order: TrailingStopOrder
) -> OrderEvent

Default trailing stop fill model implementation in base class security. (Trailing Stop Order Type)

Parameters:

Name Type Description Default
asset Security

Security asset we're filling

required
order TrailingStopOrder

Order packet to model

required

Returns:

Type Description
OrderEvent

Order fill information detailing the average price and quantity filled.