Skip to content

Slice

QuantConnect.Data.Slice

Slice(
    time: Union[datetime, date],
    data: List[BaseData],
    utc_time: Union[datetime, date],
)
Slice(slice: Slice)
Slice(
    time: Union[datetime, date],
    data: List[BaseData],
    trade_bars: TradeBars,
    quote_bars: QuoteBars,
    ticks: Ticks,
    option_chains: OptionChains,
    futures_chains: FuturesChains,
    splits: Splits,
    dividends: Dividends,
    delistings: Delistings,
    symbol_changes: SymbolChangedEvents,
    margin_interest_rates: MarginInterestRates,
    utc_time: Union[datetime, date],
    has_data: Optional[bool] = None,
)

Bases: ExtendedDictionary[Symbol, Any], Iterable[KeyValuePair[Symbol, BaseData]]

Provides a data structure for all of an algorithm's data at a single time step

Signature descriptions:

  • Initializes a new instance of the Slice class, lazily instantiating the Slice.bars and Slice.ticks collections on demand

  • Initializes a new instance used by the PythonSlice

  • Initializes a new instance of the Slice class

Parameters:

Name Type Description Default
time Optional[Union[datetime, date]]

The timestamp for this slice of data

None
data Optional[List[BaseData]]

The raw data in this slice

None
utc_time Optional[Union[datetime, date]]

The timestamp for this slice of data in UTC

None
slice Optional[Slice]

slice object to wrap

None
trade_bars Optional[TradeBars]

The trade bars for this slice

None
quote_bars Optional[QuoteBars]

The quote bars for this slice

None
ticks Optional[Ticks]

This ticks for this slice

None
option_chains Optional[OptionChains]

The option chains for this slice

None
futures_chains Optional[FuturesChains]

The futures chains for this slice

None
splits Optional[Splits]

The splits for this slice

None
dividends Optional[Dividends]

The dividends for this slice

None
delistings Optional[Delistings]

The delistings for this slice

None
symbol_changes Optional[SymbolChangedEvents]

The symbol changed events for this slice

None
margin_interest_rates Optional[MarginInterestRates]

The margin interest rates for this slice

None
has_data Optional[Optional[bool]]

true if this slice contains data

None

all_data

all_data: List[BaseData]

All the data hold in this slice

time

time: datetime

Gets the timestamp for this slice of data

utc_time

utc_time: datetime

Gets the timestamp for this slice of data in UTC

has_data

has_data: bool

Gets whether or not this slice has data

bars

bars: TradeBars

Gets the TradeBars for this slice of data

quote_bars

quote_bars: QuoteBars

Gets the quote_bars for this slice of data

ticks

ticks: Ticks

Gets the ticks for this slice of data

option_chains

option_chains: OptionChains

Gets the option_chains for this slice of data

futures_chains

futures_chains: FuturesChains

Gets the futures_chains for this slice of data

future_chains

future_chains: FuturesChains

Gets the futures_chains for this slice of data

splits

splits: Splits

Gets the splits for this slice of data

dividends

dividends: Dividends

Gets the dividends for this slice of data

delistings

delistings: Delistings

Gets the delistings for this slice of data

symbol_changed_events

symbol_changed_events: SymbolChangedEvents

Gets the Market.SymbolChangedEvents for this slice of data

margin_interest_rates

margin_interest_rates: MarginInterestRates

Gets the Market.MarginInterestRates for this slice of data

count

count: int

Gets the number of symbols held in this slice

get_keys

get_keys: Iterable[Symbol]

Gets an System.Collections.Generic.ICollection1 containing the Symbol objects of the System.Collections.Generic.IDictionary2.

This codeEntityType is protected.

get_values

get_values: Iterable[Any]

Gets an System.Collections.Generic.ICollection1 containing the values in the System.Collections.Generic.IDictionary2.

This codeEntityType is protected.

is_read_only

is_read_only: bool

Gets a value indicating whether the IDictionary object is read-only.

__contains__

__contains__(
    symbol: Union[Symbol, str, BaseContract],
) -> bool
__contains__(key: Union[Symbol, str, BaseContract]) -> bool

Signature descriptions:

  • Determines whether this instance contains data for the specified symbol

  • Checks if the dictionary contains the specified key.

Parameters:

Name Type Description Default
symbol Optional[Union[Symbol, str, BaseContract]]

The symbol we seek data for

None
key Optional[Union[Symbol, str, BaseContract]]

The key to locate in the dictionary

None

Returns:

Type Description
bool

Depends on the signature used. Case 1: [True if this instance contains data for the symbol, false otherwise.]; Case 2: [true if the dictionary contains an element with the specified key; otherwise, false.]

__getitem__

__getitem__(
    symbol: Union[Symbol, str, BaseContract],
) -> Union[TradeBar, QuoteBar, List[Tick], Any]
__getitem__(key: Union[Symbol, str, BaseContract]) -> Any

Signature descriptions:

  • Gets the data corresponding to the specified symbol. If the requested data is of MarketDataType.TICK, then a List{Tick} will be returned, otherwise, it will be the subscribed type, for example, TradeBar or event UnlinkedData for custom data.

  • Indexer method for the base dictioanry to access the objects by their symbol.

Parameters:

Name Type Description Default
symbol Optional[Union[Symbol, str, BaseContract]]

The data's symbols

None
key Optional[Union[Symbol, str, BaseContract]]

Key object indexer

None

Returns:

Type Description
Union[TradeBar, QuoteBar, List[Tick], Any] | Any

Depends on the signature used. Case 1: [The data for the specified symbol.]; Case 2: [Object of t_value.]

__setitem__

__setitem__(
    key: Union[Symbol, str, BaseContract], value: Any
) -> None
__setitem__(
    symbol: Union[Symbol, str, BaseContract],
    value: Union[TradeBar, QuoteBar, List[Tick], Any],
) -> None

Signature descriptions:

  • Indexer method for the base dictioanry to access the objects by their symbol.

  • Gets the data corresponding to the specified symbol. If the requested data is of MarketDataType.TICK, then a List{Tick} will be returned, otherwise, it will be the subscribed type, for example, TradeBar or event UnlinkedData for custom data.

Parameters:

Name Type Description Default
key Optional[Union[Symbol, str, BaseContract]]

Key object indexer

None
symbol Optional[Union[Symbol, str, BaseContract]]

The data's symbols

None

Returns:

Type Description
Optional[None]

Depends on the signature used. Case 1: [Object of t_value.]; Case 2: [The data for the specified symbol.]

contains_key

contains_key(
    symbol: Union[Symbol, str, BaseContract],
) -> bool
contains_key(key: Union[Symbol, str, BaseContract]) -> bool

Signature descriptions:

  • Determines whether this instance contains data for the specified symbol

  • Checks if the dictionary contains the specified key.

Parameters:

Name Type Description Default
symbol Optional[Union[Symbol, str, BaseContract]]

The symbol we seek data for

None
key Optional[Union[Symbol, str, BaseContract]]

The key to locate in the dictionary

None

Returns:

Type Description
bool

Depends on the signature used. Case 1: [True if this instance contains data for the symbol, false otherwise.]; Case 2: [true if the dictionary contains an element with the specified key; otherwise, false.]

get

get(
    key: Union[Symbol, str, BaseContract], value: Any
) -> Any
get(key: Union[Symbol, str, BaseContract]) -> Any
get(
    type: Any, symbol: Union[Symbol, str, BaseContract]
) -> Any
get(type: Any) -> Any
get(type: Type) -> Any

Signature descriptions:

  • Returns the value for the specified key if key is in dictionary.

  • Gets the data of the specified symbol and type.

  • Gets the data of the specified data type.

  • Gets the data of the specified type.

Parameters:

Name Type Description Default
key Optional[Union[Symbol, str, BaseContract]]

key to be searched in the dictionary

None
value Optional[Any]

Value to be returned if the key is not found. The default value is null.

None
type Optional[Any | Type]

The type of data we seek

None
symbol Optional[Union[Symbol, str, BaseContract]]

The specific symbol was seek

None

Returns:

Type Description
Any

Depends on the signature used. Case 1: [The value for the specified key if key is in dictionary.]; Case 2: [The data point for the requested symbol.]; Case 3: [The data dictionary for the requested data type.]; Case 4: [The DataDictionary{T} instance for the requested type.]

pop

pop(
    key: Union[Symbol, str, BaseContract],
    default_value: Any,
) -> Any
pop(key: Union[Symbol, str, BaseContract]) -> Any

Removes and returns an element from a dictionary having the given key.

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract]

Key which is to be searched for removal

required
default_value Optional[Any]

Value which is to be returned when the key is not in the dictionary

None

Returns:

Type Description
Any

If key is found - removed/popped element from the dictionary

setdefault

setdefault(
    key: Union[Symbol, str, BaseContract],
    default_value: Any,
) -> Any
setdefault(key: Union[Symbol, str, BaseContract]) -> Any

Returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract]

Key with a value default_value is inserted to the dictionary if key is not in the dictionary.

required
default_value Optional[Any]

Default value

None

Returns:

Type Description
Any

The value of the key if it is in the dictionary

try_get_value

try_get_value(
    symbol: Union[Symbol, str, BaseContract],
    data: Optional[Any],
) -> Tuple[bool, Any]
try_get_value(
    key: Union[Symbol, str, BaseContract],
    value: Optional[Any],
) -> Tuple[bool, Any]

Signature descriptions:

  • Gets the data associated with the specified symbol

  • Gets the value associated with the specified key.

Parameters:

Name Type Description Default
symbol Optional[Union[Symbol, str, BaseContract]]

The symbol we want data for

None
data Optional[Optional[Any]]

The data for the specifed symbol, or null if no data was found

None
key Optional[Union[Symbol, str, BaseContract]]

The key whose value to get.

None
value Optional[Optional[Any]]

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

None

Returns:

Type Description
Tuple[bool, Any]

Depends on the signature used. Case 1: [True if data was found, false otherwise.]; Case 2: [true if the object that implements System.Collections.Generic.IDictionary`2 contains an element with the specified key; otherwise, false.]

__iter__

__iter__() -> Iterator[KeyValuePair[Symbol, BaseData]]

__len__

__len__() -> int

get_enumerator

get_enumerator() -> (
    IEnumerator[KeyValuePair[Symbol, BaseData]]
)

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[KeyValuePair[Symbol, BaseData]]

A System.Collections.Generic.IEnumerator`1 that can be used to iterate through the collection.

get_items

get_items() -> Iterable[KeyValuePair[Symbol, Any]]

Gets all the items in the dictionary

Returns:

Type Description
Iterable[KeyValuePair[Symbol, Any]]

All the items in the dictionary.

merge_slice

merge_slice(input_slice: Slice) -> None

Merge two slice with same Time

Parameters:

Name Type Description Default
input_slice Slice

slice instance

required

remove

remove(key: Union[Symbol, str, BaseContract]) -> bool

Removes the value with the specified key

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract]

The key object of the element to remove.

required

Returns:

Type Description
bool

true if the element is successfully found and removed; otherwise, false.

fromkeys

fromkeys(
    sequence: List[QuantConnect_ExtendedDictionary_TKey],
) -> Dict[Any, Any]
fromkeys(
    sequence: List[QuantConnect_ExtendedDictionary_TKey],
    value: QuantConnect_ExtendedDictionary_TValue,
) -> Dict[Any, Any]

Signature descriptions:

  • Creates a new dictionary from the given sequence of elements.

  • Creates a new dictionary from the given sequence of elements with a value provided by the user.

Parameters:

Name Type Description Default
sequence List[QuantConnect_ExtendedDictionary_TKey]

Sequence of elements which is to be used as keys for the new dictionary

required
value Optional[QuantConnect_ExtendedDictionary_TValue]

Value which is set to each each element of the dictionary

None

Returns:

Type Description
Dict[Any, Any]

Returns a new dictionary with the given sequence of elements as the keys of the dictionary.

clear

clear() -> None

Removes all items from the System.Collections.Generic.ICollection`1.

copy

copy() -> Dict[Any, Any]

Creates a shallow copy of the IExtendedDictionary{TKey, TValue}.

Returns:

Type Description
Dict[Any, Any]

Returns a shallow copy of the dictionary. It doesn't modify the original dictionary.

items

items() -> List[Any]

Returns a view object that displays a list of dictionary's (key, value) tuple pairs.

Returns:

Type Description
List[Any]

Returns a view object that displays a list of a given dictionary's (key, value) tuple pair.

keys

keys() -> List[Any]

Returns a view object that displays a list of all the key objects in the dictionary

Returns:

Type Description
List[Any]

Returns a view object that displays a list of all the key objects. When the dictionary is changed, the view object also reflect these changes.

popitem

popitem() -> Any

Returns and removes an arbitrary element (key, value) pair from the dictionary.

Returns:

Type Description
Any

Returns an arbitrary element (key, value) pair from the dictionary removes an arbitrary element(the same element which is returned) from the dictionary. Note: Arbitrary elements and random elements are not same.The popitem() doesn't return a random element.

update

update(other: Any) -> None

Updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs. The update() method adds element(s) to the dictionary if the key is not in the dictionary.If the key is in the dictionary, it updates the key with the new value.

Parameters:

Name Type Description Default
other Any

Takes either a dictionary or an iterable object of key/value pairs (generally tuples).

required

values

values() -> List[Any]

Returns a view object that displays a list of all the values in the dictionary.

Returns:

Type Description
List[Any]

Returns a view object that displays a list of all values in a given dictionary.

check_for_implicitly_created_symbol

check_for_implicitly_created_symbol(
    symbol: Union[Symbol, str, BaseContract],
) -> None

Checks if the symbol is implicitly created from a string, in which case it is not in the symbol cache, and throws a KeyNotFoundException.

This codeEntityType is protected.