Securities

Key Concepts

Introduction

A security is an individual financial asset that you might trade on an exchange. LEAN models these unique assets with a Security object, which the AddEquity, AddCrypto, and similar methods return. The Securities property of the QCAlgorithm class is a dictionary where the keys are Symbol objects and the values are Security objects. The Securities dictionary contains all of the securities that have been in the algorithm during its lifetime.

Quote Currency

The quote currency is the currency you must give the seller to buy an asset. For currency trades, the quote currency is the currency ticker on the right side of the currency pair. For other types of assets, the quote currency is usually USD, but the quote currency for India Equities is INR. To get the quote currency of a Security, use the QuoteCurrency property.

var aaplQuoteCurrency = Securities["AAPL"].QuoteCurrency;
var btcusdtQuoteCurrency = Securities["BTCUSDT"].QuoteCurrency; // USDT
aapl_quote_currency = self.Securities["AAPL"].QuoteCurrency
btcusdt_quote_currency = self.Securities["BTCUSDT"].QuoteCurrency # USDT

Security Listing

The Exchange property of a Security object contains information about the exchange that lists the security.

var exchange = Securities["SPY"].Exchange;
exchange = self.Securities["SPY"].Exchange

Security Market

The Market enumeration has the following members:

LEAN groups all of the US Equity exchanges under Market.USA. In live mode, the brokerage routes the orders to the exchange that provides the best price.

Active Securities

The ActiveSecurities property of the algorithm class contains all of the assets currently in your universe. It is a dictionary where the key is a Symbol and the value is a Security. When you remove an asset from a universe, LEAN usually removes the security from the ActiveSecurities collection and removes the security subscription. However, it won't remove the security in any of the following situations:

  • You own the security.
  • You have an open order for the security.
  • The security wasn't in the universe long enough to meet the MinimumTimeInUniverse setting.

When LEAN removes the security, the Security object remains in the Securities collection for record-keeping purposes, like tracking fees and trading volume.

Tradeable Status

The IsTradable property shows whether you can trade a security. The property value is true when the security is in the universe, even if the data starts at a later day. Indices and canonical securities are not tradable. In live mode, custom data objects are also not tradable, even if the custom data represents a tradable asset.

var tradable = Securities["SPY"].IsTradable;
tradable = self.Securities["SPY"].IsTradable

Linked Custom Data

Linked custom data is custom data that's linked to individual assets. In contrast, unlinked data is not linked to specific assets. An example of an unlinked dataset is the US Regulatory Alerts dataset. LEAN passes custom data objects to the OnData method. For more information about custom data, see Processing Samples.

Security Types

LEAN uses the SecurityType enumeration as a synonym for asset classes. The SecurityType enumeration has the following members:

The Base type is for non-financial assets like custom and alternative data objects.

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: