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; // USD var btcusdtQuoteCurrency = Securities["BTCUSDT"].QuoteCurrency; // USDT
aapl_quote_currency = self.Securities["AAPL"].QuoteCurrency # USD btcusdt_quote_currency = self.Securities["BTCUSDT"].QuoteCurrency # USDT
The QuoteCurrency
is a Cash
object, which have the following properties:
You can use the ConversionRate
property to calculate the value of the minimum price movement in the account currency
var cfd = Securities["SG30SGD"]; var quoteCurrency = cfd.QuoteCurrency; // SGD var contractMutiplier = cfd.SymbolProperties.ContractMultiplier; var minimumPriceVariation = cfd.SymbolProperties.MinimumPriceVariation; // Value of a pip in account currency var pip = minimumPriceVariation * contractMutiplier * quoteCurrency.ConversionRate;
cfd = self.Securities["SG30SGD"] quote_currency = cfd.QuoteCurrency # SGD contract_mutiplier = cfd.SymbolProperties.ContractMultiplier minimum_price_variation = cfd.SymbolProperties.MinimumPriceVariation # Value of a pip in account currency pip = minimum_price_variation * contract_mutiplier * quote_currency.ConversionRate
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
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.
Tradable 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, canonical Option securities, and continuous Futures contracts 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 Custom Securities.
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.