Sometimes, it is useful to be able to restrict the trading of certain assets in an algorithm. The
set_do_not_order_list method previously provided this ability, and allowed users to restrict a static list of assets or
Because of its confusing name and unclear parameters (
security_lists.leveraged_etf_list was not actually a static list),
set_do_not_order_list has been deprecated in favor of a new, more clearly defined, assets restrictions API. This new API also provides the ability to set custom dynamic restrictions on what assets are tradable.
The new method,
set_asset_restrictions, takes an object representing the point-in-time restrictions for some assets. Instead of calling
set_do_not_order_list(security_lists.leveraged_etf_list) to restrict the trading of leveraged ETFs, one should call
The ability to iterate through, or check for the inclusion of an asset in,
security_lists.leveraged_etf_list has also been deprecated. Instead,
security_lists.leveraged_etf_list.current_securities(dt) will return an iterable of currently restricted securities on the given datetime (dt).
The best way to avoid attempts to trade restricted assets, however, is to now call
data.can_trade(asset), which will return False if the asset is restricted.
set_asset_restrictions can also take custom restrictions objects. These custom restrictions can be created from
HistoricalRestrictions. For more information on how to make these custom restrictions, please refer to the documentation. The following example demonstrates how an algorithm can restrict the trading of two stocks during certain time periods using