SliceExtensions
QuantConnect.Data.SliceExtensions
Bases: Object
Provides extension methods to slices and slice enumerables
get
get(
slices: List[Slice],
type: Type,
symbol: Union[Symbol, str, BaseContract] = None,
) -> Iterable[Any]
get(
slices: List[Slice],
symbol: Union[Symbol, str, BaseContract],
) -> Iterable[TradeBar]
get(
slices: List[Slice],
symbol: Union[Symbol, str, BaseContract],
field: Callable[[BaseData], float],
) -> Iterable[float]
Signature descriptions:
-
Gets the data dictionaries or points of the requested type in each slice
-
Gets an enumerable of TradeBar for the given symbol. This method does not verify that the specified symbol points to a TradeBar
-
Gets an enumerable of decimal by accessing the slice for the symbol and then retrieving the specified field on each piece of data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slices
|
List[Slice]
|
The enumerable of slice |
required |
type
|
Optional[Type]
|
Data type of the data that will be fetched |
None
|
symbol
|
Union[Symbol, str, BaseContract]
|
The symbol to retrieve |
None
|
field
|
Optional[Callable[[BaseData], float]]
|
The field selector used to access the dats |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Any] | Iterable[TradeBar] | Iterable[float]
|
Depends on the signature used. Case 1: [An enumerable of data dictionary or data point of the requested type.]; Case 2: [An enumerable of TradeBar for the matching symbol, of no TradeBar found for symbol, empty enumerable is returned.]; Case 3: [An enumerable of decimal.] |
push_through_consolidators
push_through_consolidators(
slices: List[Slice],
consolidators_by_symbol: Dictionary[
Symbol, IDataConsolidator
],
) -> None
push_through_consolidators(
slices: List[Slice],
consolidators_provider: Callable[
[Symbol], IDataConsolidator
],
) -> None
Loops through the specified slices and pushes the data into the consolidators. This can be used to easily warm up indicators from a history call that returns slice objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slices
|
List[Slice]
|
The data to send into the consolidators, likely result of a history request |
required |
consolidators_by_symbol
|
Optional[Dictionary[Symbol, IDataConsolidator]]
|
Dictionary of consolidators keyed by symbol |
None
|
consolidators_provider
|
Optional[Callable[[Symbol], IDataConsolidator]]
|
Delegate that fetches the consolidators by a symbol |
None
|
get_universe_data
get_universe_data(
slices: List[Slice],
) -> Iterable[DataDictionary[BaseDataCollection]]
Gets the data dictionaries or points of the requested type in each slice
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slices
|
List[Slice]
|
The enumerable of slice |
required |
Returns:
| Type | Description |
|---|---|
Iterable[DataDictionary[BaseDataCollection]]
|
An enumerable of data dictionary or data point of the requested type. |
push_through
push_through(
slices: List[Slice],
handler: Callable[[BaseData], Any],
data_type: Type = None,
) -> None
Loops through the specified slices and pushes the data into the consolidators. This can be used to easily warm up indicators from a history call that returns slice objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slices
|
List[Slice]
|
The data to send into the consolidators, likely result of a history request |
required |
handler
|
Callable[[BaseData], Any]
|
Delegate handles each data piece from the slice |
required |
data_type
|
Type
|
Defines the type of the data that should be pushed |
None
|
ticks
to_double_array
to_double_array(decimals: List[float]) -> List[float]
Converts the specified enumerable of decimals into a double array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimals
|
List[float]
|
The enumerable of decimal |
required |
Returns:
| Type | Description |
|---|---|
List[float]
|
Double array representing the enumerable of decimal. |
trade_bars
try_get
try_get(
slice: Slice,
type: Type,
symbol: Union[Symbol, str, BaseContract],
data: Optional[Any],
) -> Tuple[bool, Any]
Tries to get the data for the specified symbol and type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice
|
Slice
|
The slice |
required |
type
|
Type
|
The type of data we seek |
required |
symbol
|
Union[Symbol, str, BaseContract]
|
The symbol data is sought for |
required |
data
|
Optional[Any]
|
The found data |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, Any]
|
True if data was found for the specified type and symbol. |