SecurityIdentifier
QuantConnect.SecurityIdentifier
SecurityIdentifier(symbol: str, properties: int)
SecurityIdentifier(
symbol: str,
properties: int,
underlying: SecurityIdentifier,
)
Bases: Object, IEquatable[QuantConnect_SecurityIdentifier], IComparable[QuantConnect_SecurityIdentifier]
Defines a unique identifier for securities
Initializes a new instance of the SecurityIdentifier class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The base36 string encoded as a long using alpha <0-9A-Z> |
required |
properties
|
int
|
Other data defining properties of the symbol including market, |
required |
underlying
|
Optional[SecurityIdentifier]
|
Specifies a SecurityIdentifier that represents the underlying security |
None
|
EMPTY
EMPTY: SecurityIdentifier = ...
Gets an instance of SecurityIdentifier that is empty, that is, one with no symbol specified
NONE
NONE: SecurityIdentifier = ...
Gets an instance of SecurityIdentifier that is explicitly no symbol
DEFAULT_DATE
DEFAULT_DATE: datetime = ...
Gets the date to be used when it does not apply.
INVALID_SYMBOL_CHARACTERS
INVALID_SYMBOL_CHARACTERS: HashSet[str] = ...
Gets the set of invalids symbol characters
has_underlying
has_underlying: bool
Gets whether or not this SecurityIdentifier is a derivative, that is, it has a valid underlying property
underlying
underlying: SecurityIdentifier
Gets the underlying security identifier for this security identifier. When there is no underlying, this property will return a value of EMPTY.
date
date: datetime
Gets the date component of this identifier. For equities this is the first date the security traded. Technically speaking, in LEAN, this is the first date mentioned in the map_files. For futures and options this is the expiry date of the contract. For other asset classes, this property will throw an exception as the field is not specified.
symbol
symbol: str
Gets the original symbol used to generate this security identifier. For equities, by convention this is the first ticker symbol for which the security traded
market
market: str
Gets the market component of this security identifier. If located in the internal mappings, the full string is returned. If the value is unknown, the integer value is returned as a string.
security_type
security_type: SecurityType
Gets the security type component of this security identifier.
strike_price
strike_price: float
Gets the option strike price. This only applies if SecurityType is Option, IndexOption or FutureOption and will thrown anexception if accessed otherwise.
option_right
option_right: OptionRight
Gets the option type component of this security identifier. This only applies if SecurityType is Option, IndexOption or FutureOption and will throw an exception if accessed otherwise.
option_style
option_style: OptionStyle
Gets the option style component of this security identifier. This only applies if SecurityType is Option, IndexOption or FutureOption and will throw an exception if accessed otherwise.
compare_to
compare_to(obj: Any) -> int
compare_to(other: SecurityIdentifier) -> int
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Optional[Any]
|
An object to compare with this instance. |
None
|
other
|
Optional[SecurityIdentifier]
|
An object to compare with this instance. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Depends on the signature used. Case 1: [A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes obj in the sort order. Zero This instance occurs in the same position in the sort order as obj. Greater than zero This instance follows obj in the sort order.]; Case 2: [A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes other in the sort order. Zero This instance occurs in the same position in the sort order as other. Greater than zero This instance follows other in the sort order.] |
equals
equals(obj: Any) -> bool
equals(other: SecurityIdentifier) -> bool
Signature descriptions:
-
Determines whether the specified System.Object is equal to the current System.Object.
-
Indicates whether the current object is equal to another object of the same type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Optional[Any]
|
The object to compare with the current object. |
None
|
other
|
Optional[SecurityIdentifier]
|
An object to compare with this object. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Depends on the signature used. Case 1: [true if the specified object is equal to the current object; otherwise, false.]; Case 2: [true if the current object is equal to the other parameter; otherwise, false.] |
generate_equity
generate_equity(
symbol: str,
market: str,
map_symbol: bool = True,
map_file_provider: IMapFileProvider = None,
mapping_resolve_date: Optional[datetime] = None,
) -> SecurityIdentifier
generate_equity(
date: Union[datetime, date], symbol: str, market: str
) -> SecurityIdentifier
Signature descriptions:
-
Helper overload that will search the mapfiles to resolve the first date. This implementation uses the configured IMapFileProvider via the Composer.INSTANCE
-
Generates a new SecurityIdentifier for an equity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The symbol as it is known today |
required |
market
|
str
|
The market |
required |
map_symbol
|
Optional[bool]
|
Specifies if symbol should be mapped using map file provider |
True
|
map_file_provider
|
Optional[IMapFileProvider]
|
Specifies the IMapFileProvider to use for resolving symbols, specify null to load from Composer |
None
|
mapping_resolve_date
|
Optional[Optional[datetime]]
|
The date to use to resolve the map file. Default value is DateTime.Today |
None
|
date
|
Optional[Union[datetime, date]]
|
The first date this security traded (in LEAN this is the first date in the map_file |
None
|
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
Depends on the signature used. Case 1: [A new SecurityIdentifier representing the specified symbol today.]; Case 2: [A new SecurityIdentifier representing the specified equity security.] |
generate_option
generate_option(
expiry: Union[datetime, date],
underlying: SecurityIdentifier,
market: str,
strike: float,
option_right: OptionRight,
option_style: OptionStyle,
) -> SecurityIdentifier
generate_option(
expiry: Union[datetime, date],
underlying: SecurityIdentifier,
target_option: str,
market: str,
strike: float,
option_right: OptionRight,
option_style: OptionStyle,
) -> SecurityIdentifier
Generates a new SecurityIdentifier for an option
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expiry
|
Union[datetime, date]
|
The date the option expires |
required |
underlying
|
SecurityIdentifier
|
The underlying security's symbol |
required |
market
|
str
|
The market |
required |
strike
|
float
|
The strike price |
required |
option_right
|
OptionRight
|
The option type, call or put |
required |
option_style
|
OptionStyle
|
The option style, American or European |
required |
target_option
|
Optional[str]
|
The target option ticker. This is useful when the option ticker does not match the underlying, e.g. SPX index and the SPXW weekly option. If null is provided will use underlying |
None
|
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified option security. |
generate_base
generate_base(
data_type: Type,
symbol: str,
market: str,
map_symbol: bool = False,
date: Optional[datetime] = None,
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a custom security with the option of providing the first date
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_type
|
Type
|
The custom data type |
required |
symbol
|
str
|
The ticker symbol of this security |
required |
market
|
str
|
The security's market |
required |
map_symbol
|
bool
|
Whether or not we should map this symbol |
False
|
date
|
Optional[datetime]
|
First date that the security traded on |
None
|
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified base security. |
generate_base_symbol
generate_base_symbol(data_type: Type, symbol: str) -> str
Generates the symbol property for QuantConnect.SecurityType.Base security identifiers
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_type
|
Type
|
The base data custom data type if namespacing is required, null otherwise |
required |
symbol
|
str
|
The ticker symbol |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value used for the security identifier's symbol. |
generate_cfd
generate_cfd(
symbol: str, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a CFD security
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The CFD contract symbol |
required |
market
|
str
|
The security's market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified CFD security. |
generate_constituent_identifier
generate_constituent_identifier(
symbol: str, security_type: SecurityType, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a ConstituentsUniverseData. Note that the symbol ticker is case sensitive here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The ticker to use for this constituent identifier |
required |
security_type
|
SecurityType
|
The security type of this constituent universe |
required |
market
|
str
|
The security's market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified constituent universe. |
generate_crypto
generate_crypto(
symbol: str, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a Crypto pair
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The currency pair in the format similar to: 'EURUSD' |
required |
market
|
str
|
The security's market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified Crypto pair. |
generate_crypto_future
generate_crypto_future(
expiry: Union[datetime, date], symbol: str, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a CryptoFuture pair
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expiry
|
Union[datetime, date]
|
The date the future expires |
required |
symbol
|
str
|
The currency pair in the format similar to: 'EURUSD' |
required |
market
|
str
|
The security's market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified CryptoFuture pair. |
generate_forex
generate_forex(
symbol: str, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a forex pair
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The currency pair in the format similar to: 'EURUSD' |
required |
market
|
str
|
The security's market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified forex pair. |
generate_future
generate_future(
expiry: Union[datetime, date], symbol: str, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a future
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expiry
|
Union[datetime, date]
|
The date the future expires |
required |
symbol
|
str
|
The security's symbol |
required |
market
|
str
|
The market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified futures security. |
generate_index
generate_index(
symbol: str, market: str
) -> SecurityIdentifier
Generates a new SecurityIdentifier for a INDEX security
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The Index contract symbol |
required |
market
|
str
|
The security's market |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier representing the specified INDEX security. |
get_hash_code
get_hash_code() -> int
Serves as a hash function for a particular type.
Returns:
| Type | Description |
|---|---|
int
|
A hash code for the current System.Object. |
parse
parse(value: str) -> SecurityIdentifier
Parses the specified string into a SecurityIdentifier The string must be a 40 digit number. The first 20 digits must be parseable to a 64 bit unsigned integer and contain ancillary data about the security. The second 20 digits must also be parseable as a 64 bit unsigned integer and contain the symbol encoded from base36, this provides for 12 alpha numeric case insensitive characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string value to be parsed |
required |
Returns:
| Type | Description |
|---|---|
SecurityIdentifier
|
A new SecurityIdentifier instance if the value is able to be parsed. |
ticker
ticker(
symbol: Union[Symbol, str, BaseContract],
date: Union[datetime, date],
) -> str
For the given symbol will resolve the ticker it used at the requested date
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract]
|
The symbol to get the ticker for |
required |
date
|
Union[datetime, date]
|
The date to map the symbol to |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ticker for a date and symbol. |
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_custom_data_type
try_get_custom_data_type(
symbol: str, type: Optional[str]
) -> Tuple[bool, str]
Tries to fetch the custom data type associated with a symbol
try_get_custom_data_type_instance
try_get_custom_data_type_instance(
symbol: str, type: Optional[Type]
) -> Tuple[bool, Type]
Tries to fetch the custom data type associated with a symbol
try_parse
try_parse(
value: str, identifier: Optional[SecurityIdentifier]
) -> Tuple[bool, SecurityIdentifier]
Attempts to parse the specified value as a SecurityIdentifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string value to be parsed |
required |
identifier
|
Optional[SecurityIdentifier]
|
The result of parsing, when this function returns true, identifier was properly created and reflects the input string, when this function returns false identifier will equal default(SecurityIdentifier) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, SecurityIdentifier]
|
True on success, otherwise false. |