Skip to content

Security

QuantConnect.Securities.Security

Security(
    exchange_hours: SecurityExchangeHours,
    config: SubscriptionDataConfig,
    quote_currency: Cash,
    symbol_properties: SymbolProperties,
    currency_converter: ICurrencyConverter,
    registered_types_provider: IRegisteredSecurityDataTypesProvider,
    cache: SecurityCache,
)
Security(
    symbol: Union[Symbol, str, BaseContract],
    exchange_hours: SecurityExchangeHours,
    quote_currency: Cash,
    symbol_properties: SymbolProperties,
    currency_converter: ICurrencyConverter,
    registered_types_provider: IRegisteredSecurityDataTypesProvider,
    cache: SecurityCache,
)
Security(
    symbol: Union[Symbol, str, BaseContract],
    quote_currency: Cash,
    symbol_properties: SymbolProperties,
    exchange: SecurityExchange,
    cache: SecurityCache,
    portfolio_model: ISecurityPortfolioModel,
    fill_model: IFillModel,
    fee_model: IFeeModel,
    slippage_model: ISlippageModel,
    settlement_model: ISettlementModel,
    volatility_model: IVolatilityModel,
    buying_power_model: IBuyingPowerModel,
    data_filter: ISecurityDataFilter,
    price_variation_model: IPriceVariationModel,
    currency_converter: ICurrencyConverter,
    registered_types_provider: IRegisteredSecurityDataTypesProvider,
    margin_interest_rate_model: IMarginInterestRateModel,
)
Security(
    config: SubscriptionDataConfig,
    quote_currency: Cash,
    symbol_properties: SymbolProperties,
    exchange: SecurityExchange,
    cache: SecurityCache,
    portfolio_model: ISecurityPortfolioModel,
    fill_model: IFillModel,
    fee_model: IFeeModel,
    slippage_model: ISlippageModel,
    settlement_model: ISettlementModel,
    volatility_model: IVolatilityModel,
    buying_power_model: IBuyingPowerModel,
    data_filter: ISecurityDataFilter,
    price_variation_model: IPriceVariationModel,
    currency_converter: ICurrencyConverter,
    registered_types_provider: IRegisteredSecurityDataTypesProvider,
    margin_interest_rate_model: IMarginInterestRateModel,
)

Bases: DynamicObject, ISecurityPrice

A base vehicle properties class for providing a common interface to all assets in QuantConnect.

Signature descriptions:

  • Construct a new security vehicle based on the user options.

  • Temporary convenience constructor

shortable_provider

shortable_provider: IShortableProvider

This securities IShortableProvider

NULL_LEVERAGE

NULL_LEVERAGE: float = 0

A null security leverage value

subscriptions

subscriptions: Iterable[SubscriptionDataConfig]

Gets all the subscriptions for this security

symbol

symbol: Symbol

symbol for the asset.

quote_currency

quote_currency: Cash

Gets the Cash object used for converting the quote currency to the account currency

symbol_properties

symbol_properties: SymbolProperties

Gets the symbol properties for this security

type

Type of the security.

resolution

resolution: Resolution

Resolution of data requested for this security.

This property is obsolete. Use the 'SubscriptionDataConfig' exposed by 'SubscriptionManager'

is_fill_data_forward

is_fill_data_forward: bool

Indicates the data will use previous bars when there was no trading in this time period. This was a configurable datastream setting set in initialization.

This property is obsolete. Use the 'SubscriptionDataConfig' exposed by 'SubscriptionManager'

is_extended_market_hours

is_extended_market_hours: bool

Indicates the security will continue feeding data after the primary market hours have closed. This was a configurable setting set in initialization.

This property is obsolete. Use the 'SubscriptionDataConfig' exposed by 'SubscriptionManager'

data_normalization_mode

data_normalization_mode: DataNormalizationMode

Gets the data normalization mode used for this security

This property is obsolete. Use the 'SubscriptionDataConfig' exposed by 'SubscriptionManager'

subscription_data_config

subscription_data_config: SubscriptionDataConfig

Gets the subscription configuration for this security

This property returns only the first subscription. Use the 'Subscriptions' property for all of this security's subscriptions.

has_data

has_data: bool

There has been at least one datapoint since our algorithm started running for us to determine price.

is_tradable

is_tradable: bool

Gets or sets whether or not this security should be considered tradable

is_delisted

is_delisted: bool

True if the security has been delisted from exchanges and is no longer tradable

cache

Data cache for the security to store previous price information.

holdings

holdings: SecurityHolding

Holdings class contains the portfolio, cash and processes order fills.

exchange

exchange: SecurityExchange

Exchange class contains the market opening hours, along with pre-post market hours.

fee_model

fee_model: IFeeModel

Fee model used to compute order fees for this security

fill_model

fill_model: IFillModel

Fill model used to produce fill events for this security

slippage_model

slippage_model: ISlippageModel

Slippage model use to compute slippage of market orders

portfolio_model

portfolio_model: ISecurityPortfolioModel

Gets the portfolio model used by this security

buying_power_model

buying_power_model: IBuyingPowerModel

Gets the buying power model used for this security

margin_model

margin_model: IBuyingPowerModel

Gets the buying power model used for this security, an alias for buying_power_model

margin_interest_rate_model

margin_interest_rate_model: IMarginInterestRateModel

Gets or sets the margin interest rate model

settlement_model

settlement_model: ISettlementModel

Gets the settlement model used for this security

volatility_model

volatility_model: IVolatilityModel

Gets the volatility model used for this security

data_filter

data_filter: ISecurityDataFilter

Customizable data filter to filter outlier ticks before they are passed into user event handlers. By default all ticks are passed into the user algorithms.

price_variation_model

price_variation_model: IPriceVariationModel

Customizable price variation model used to define the minimum price variation of this security. By default minimum price variation is a constant find in the symbol-properties-database.

data

Provides dynamic access to data in the cache

session

session: Session

Gets the current session of this security

hold_stock

hold_stock: bool

Read only property that checks if we currently own stock in the company.

invested

invested: bool

Alias for HoldStock - Do we have any of this security

local_time

local_time: datetime

Local time for this market

price

price: float

Get the current value of the security.

leverage

leverage: float

Leverage for this Security.

high

high: float

If this uses tradebar data, return the most recent high.

low

low: float

If this uses tradebar data, return the most recent low.

close

close: float

If this uses tradebar data, return the most recent close.

open

open: float

If this uses tradebar data, return the most recent open.

volume

volume: float

Access to the volume of the equity today

bid_price

bid_price: float

Gets the most recent bid price if available

bid_size

bid_size: float

Gets the most recent bid size if available

ask_price

ask_price: float

Gets the most recent ask price if available

ask_size

ask_size: float

Gets the most recent ask size if available

open_interest

open_interest: int

Access to the open interest of the security today

fundamentals

fundamentals: Fundamental

Gets the fundamental data associated with the security if there is any, otherwise null.

set_buying_power_model

set_buying_power_model(py_object: Any) -> None
set_buying_power_model(
    buying_power_model: IBuyingPowerModel,
) -> None

Sets the buying power model

Parameters:

Name Type Description Default
py_object Optional[Any]

Model that represents a security's model of buying power

None
buying_power_model Optional[IBuyingPowerModel]

Model that represents a security's model of buying power

None

set_data_filter

set_data_filter(py_object: Any) -> None
set_data_filter(data_filter: ISecurityDataFilter) -> None

Set Security Data Filter

Parameters:

Name Type Description Default
py_object Optional[Any]

Python class that represents a custom Security Data Filter

None
data_filter Optional[ISecurityDataFilter]

Security Data Filter

None

set_fee_model

set_fee_model(feel_model: Any) -> None
set_fee_model(feel_model: IFeeModel) -> None

Sets the fee model

Parameters:

Name Type Description Default
feel_model Any | IFeeModel

Model that represents a fee model

required

set_fill_model

set_fill_model(fill_model: Any) -> None
set_fill_model(fill_model: IFillModel) -> None

Sets the fill model

Parameters:

Name Type Description Default
fill_model Any | IFillModel

Model that represents a fill model

required

set_margin_interest_rate_model

set_margin_interest_rate_model(py_object: Any) -> None
set_margin_interest_rate_model(
    margin_interest_rate_model: IMarginInterestRateModel,
) -> None

Sets the margin interests rate model

Parameters:

Name Type Description Default
py_object Optional[Any]

Model that represents a security's model of margin interest rate

None
margin_interest_rate_model Optional[IMarginInterestRateModel]

Model that represents a security's model of margin interest rate

None

set_margin_model

set_margin_model(py_object: Any) -> None
set_margin_model(margin_model: IBuyingPowerModel) -> None

Sets the margin model

Parameters:

Name Type Description Default
py_object Optional[Any]

Model that represents a security's model of buying power

None
margin_model Optional[IBuyingPowerModel]

Model that represents a security's model of buying power

None

set_settlement_model

set_settlement_model(settlement_model: Any) -> None
set_settlement_model(
    settlement_model: ISettlementModel,
) -> None

Sets the settlement model

Parameters:

Name Type Description Default
settlement_model Any | ISettlementModel

Model that represents a settlement model

required

set_shortable_provider

set_shortable_provider(py_object: Any) -> None
set_shortable_provider(
    shortable_provider: IShortableProvider,
) -> None

Signature descriptions:

  • Set Python Shortable Provider for this Security

  • Set Shortable Provider for this Security

Parameters:

Name Type Description Default
py_object Optional[Any]

Python class that represents a custom shortable provider

None
shortable_provider Optional[IShortableProvider]

Provider to use

None

set_slippage_model

set_slippage_model(slippage_model: Any) -> None
set_slippage_model(slippage_model: ISlippageModel) -> None

Sets the slippage model

Parameters:

Name Type Description Default
slippage_model Any | ISlippageModel

Model that represents a slippage model

required

set_volatility_model

set_volatility_model(volatility_model: Any) -> None
set_volatility_model(
    volatility_model: IVolatilityModel,
) -> None

Sets the volatility model

Parameters:

Name Type Description Default
volatility_model Any | IVolatilityModel

Model that represents a volatility model

required

__getitem__

__getitem__(key: str) -> Any

Gets or sets the specified custom property through the indexer. This is a wrapper around the Get{T}(string) and add(string,object) methods.

Parameters:

Name Type Description Default
key str

The property key

required

__setitem__

__setitem__(key: str, value: Any) -> None

Gets or sets the specified custom property through the indexer. This is a wrapper around the Get{T}(string) and add(string,object) methods.

Parameters:

Name Type Description Default
key str

The property key

required

add

add(key: str, value: Any) -> None

Adds the specified custom property. This allows us to use the security object as a dynamic object for quick storage.

Parameters:

Name Type Description Default
key str

The property key

required
value Any

The property value

required

clear

clear() -> None

Removes every custom property that had been set.

get_last_data

get_last_data() -> BaseData

Get the last price update set to the security if any else null

Returns:

Type Description
BaseData

BaseData object for this security.

is_custom_data

is_custom_data() -> bool

Returns true if the security contains at least one subscription that represents custom data

This method is obsolete. Use the 'SubscriptionDataConfig' exposed by 'SubscriptionManager' and the 'IsCustomData()' extension method

refresh_data_normalization_mode_property

refresh_data_normalization_mode_property() -> None

This method will refresh the value of the data_normalization_mode property. This is required for backward-compatibility. TODO: to be deleted with the DataNormalizationMode property

remove

remove(key: str) -> bool

Removes a custom property.

Parameters:

Name Type Description Default
key str

The property key

required

Returns:

Type Description
bool

True if the property is successfully removed.

reset

reset() -> None

Resets the security to its initial state by marking it as uninitialized and non-tradable and clearing the subscriptions.

set

set(key: str, value: Any) -> None

Sets the specified custom property. This allows us to use the security object as a dynamic object for quick storage.

Parameters:

Name Type Description Default
key str

The property key

required
value Any

The property value

required

set_data_normalization_mode

set_data_normalization_mode(
    mode: DataNormalizationMode,
) -> None

Sets the data normalization mode to be used by this security

This method is obsolete. Use the 'SubscriptionDataConfig' exposed by 'SubscriptionManager' and the 'SetDataNormalizationMode()' extension method

set_leverage

set_leverage(leverage: float) -> None

Set the leverage parameter for this security

Parameters:

Name Type Description Default
leverage float

Leverage for this asset

required

set_local_time_keeper

set_local_time_keeper(
    local_time_keeper: LocalTimeKeeper,
) -> None

Sets the LocalTimeKeeper to be used for this Security. This is the source of this instance's time.

Parameters:

Name Type Description Default
local_time_keeper LocalTimeKeeper

The source of this Security's time.

required

set_market_price

set_market_price(data: BaseData) -> None

Update any security properties based on the latest market data and time

Parameters:

Name Type Description Default
data BaseData

New data packet from LEAN

required

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.

try_get_member

try_get_member(
    binder: Any, result: Optional[Any]
) -> Tuple[bool, Any]

This is a DynamicObject override. Not meant for external use.

try_invoke_member

try_invoke_member(
    binder: Any, args: List[Object], result: Optional[Any]
) -> Tuple[bool, Any]

This is a DynamicObject override. Not meant for external use.

try_set_member

try_set_member(binder: Any, value: Any) -> bool

This is a DynamicObject override. Not meant for external use.

update

update(
    data: Sequence[BaseData],
    data_type: Type,
    contains_fill_forward_data: Optional[bool] = None,
    is_internal_config: bool = False,
) -> None

Updates all of the security properties, such as price/OHLCV/bid/ask based on the data provided. Data is also stored into the security's data cache

Parameters:

Name Type Description Default
data Sequence[BaseData]

The security update data

required
data_type Type

The data type

required
contains_fill_forward_data Optional[bool]

Flag indicating whether True if this update data corresponds to an internal subscription such as currency or security benchmarkdata contains any fill forward bar or not

None
is_internal_config bool

True if this update data corresponds to an internal subscription such as currency or security benchmark

False

update_consumers_market_price

update_consumers_market_price(data: BaseData) -> None

Update market price of this Security

This codeEntityType is protected.

Parameters:

Name Type Description Default
data BaseData

Data to pull price from

required