ObjectStore
QuantConnect.Storage.ObjectStore
ObjectStore(
store: IObjectStore, warn: Callable[[str], Any] = None
)
Bases: Object, IObjectStore, Iterable[KeyValuePair[str, List[int]]]
Helper class for easier access to IObjectStore methods. A key that does not follow the key format (english letters, numbers, spaces and the characters '.', '/', '\', '_', '#', '-', '$' and '=', never two '.' in a row, e.g. 'folder/trade_log-2024.v2.csv') is saved under its sanitized version, then found and listed by either name, with a warning the first time it happens. An object already stored under an unsupported name is read as is until a save through that name creates the sanitized one
Initializes a new instance of the ObjectStore class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
IObjectStore
|
The IObjectStore instance to wrap |
required |
warn
|
Callable[[str], Any]
|
Receives the warnings about sanitized keys, the engine log by default |
None
|
max_size
max_size: int
Gets the maximum storage limit in bytes
max_files
max_files: int
Gets the maximum number of files allowed
error_raised
error_raised: _EventContainer[
Callable[
[Object, ObjectStoreErrorRaisedEventArgs], Any
],
Any,
]
Event raised each time there's an error
keys
keys: ICollection[str]
Returns the file paths present in the object store. This is specially useful not to load the object store into memory. An unsupported key saved in this run is listed next to the sanitized name its object is stored under. The store is listed on first use, and Contains finds a key the way contains_key does, without listing it
read_json
read_json(
path: str,
encoding: Encoding = None,
settings: Any = None,
) -> QuantConnect_Storage_ObjectStore_ReadJson_T
Returns the JSON deserialized object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
settings
|
Any
|
The settings used by the JSON deserializer |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_Storage_ObjectStore_ReadJson_T
|
An object containing the data. |
read_xml
read_xml(
path: str, encoding: Encoding = None
) -> QuantConnect_Storage_ObjectStore_ReadXml_T
Returns the XML deserialized object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_Storage_ObjectStore_ReadXml_T
|
An object containing the data. |
save
save(path: str) -> bool
save(
path: str, text: str, encoding: Encoding = None
) -> bool
Signature descriptions:
-
Saves the data from a local file path associated with the specified path
-
Saves the object data in text format for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object key: english letters, numbers, spaces and the characters '.', '/', '', '', '#', '-', '$' and '=', never '..', e.g. 'folder/trade_log-2024.v2.csv'. Other characters are replaced by '' |
required |
text
|
Optional[str]
|
The string object to be saved |
None
|
encoding
|
Optional[Encoding]
|
The string encoding used, Encoding.UTF8 by default |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the object was saved successfully. |
save_json
save_json(
path: str,
obj: QuantConnect_Storage_ObjectStore_SaveJson_T,
encoding: Encoding = None,
settings: Any = None,
) -> bool
Saves the object data in JSON format for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object key: english letters, numbers, spaces and the characters '.', '/', '', '', '#', '-', '$' and '=', never '..', e.g. 'folder/trade_log-2024.v2.csv'. Other characters are replaced by '' |
required |
obj
|
QuantConnect_Storage_ObjectStore_SaveJson_T
|
The object to be saved |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
settings
|
Any
|
The settings used by the JSON serializer |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the object was saved successfully. |
save_xml
save_xml(
path: str,
obj: QuantConnect_Storage_ObjectStore_SaveXml_T,
encoding: Encoding = None,
) -> bool
Saves the object data in XML format for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object key: english letters, numbers, spaces and the characters '.', '/', '', '', '#', '-', '$' and '=', never '..', e.g. 'folder/trade_log-2024.v2.csv'. Other characters are replaced by '' |
required |
obj
|
QuantConnect_Storage_ObjectStore_SaveXml_T
|
The object to be saved |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the object was saved successfully. |
__iter__
__iter__() -> Iterator[KeyValuePair[str, List[int]]]
clear
clear() -> None
Will clear the object store state cache. This is useful when the object store is used concurrently by nodes which want to share information
contains_key
contains_key(path: str) -> bool
Determines whether the store contains data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the key was found. |
delete
delete(path: str) -> bool
Deletes the object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the delete operation was successful. |
dispose
dispose() -> None
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
get_enumerator
get_enumerator() -> (
IEnumerator[KeyValuePair[str, List[int]]]
)
Returns an enumerator that iterates through the collection.
Returns:
| Type | Description |
|---|---|
IEnumerator[KeyValuePair[str, List[int]]]
|
A System.Collections.Generic.IEnumerator`1 that can be used to iterate through the collection. |
get_file_path
get_file_path(path: str) -> str
Returns the file path for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
Returns:
| Type | Description |
|---|---|
str
|
The path for the file. |
initialize
initialize(
user_id: int,
project_id: int,
user_token: str,
controls: Controls,
algorithm_mode: AlgorithmMode,
) -> None
Initializes the object store
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The user id |
required |
project_id
|
int
|
The project id |
required |
user_token
|
str
|
The user token |
required |
controls
|
Controls
|
The job controls instance |
required |
algorithm_mode
|
AlgorithmMode
|
The algorithm mode |
required |
read
read(path: str, encoding: Encoding = None) -> str
Returns the string object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string containing the data. |
read_bytes
read_bytes(path: str) -> List[int]
Returns the object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
A byte array containing the data. |
read_string
read_string(path: str, encoding: Encoding = None) -> str
Returns the string object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string containing the data. |
read_text
read_text(path: str, encoding: Encoding = None) -> str
Returns the object data for the specified path as a string. Alias of read(string, Encoding)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object path |
required |
encoding
|
Encoding
|
The string encoding used, Encoding.UTF8 by default |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string containing the data. |
save_bytes
save_bytes(path: str, contents: List[int]) -> bool
Saves the object data for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object key: english letters, numbers, spaces and the characters '.', '/', '\', '', '#', '-', '$' and '=', never '..', e.g. 'folder/trade_log-2024.v2.csv'. Other characters are replaced by '' |
required |
contents
|
List[int]
|
The object data |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the save operation was successful. |
save_string
save_string(
path: str, text: str, encoding: Encoding = None
) -> bool
Saves the object data in text format for the specified path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object key: english letters, numbers, spaces and the characters '.', '/', '\', '', '#', '-', '$' and '=', never '..', e.g. 'folder/trade_log-2024.v2.csv'. Other characters are replaced by '' |
required |
text
|
str
|
The string object to be saved |
required |
encoding
|
Encoding
|
The string encoding used |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the object was saved successfully. |
save_text
save_text(
path: str, text: str, encoding: Encoding = None
) -> bool
Saves the object data in text format for the specified path. Alias of save(string, string, Encoding)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The object key: english letters, numbers, spaces and the characters '.', '/', '\', '', '#', '-', '$' and '=', never '..', e.g. 'folder/trade_log-2024.v2.csv'. Other characters are replaced by '' |
required |
text
|
str
|
The string object to be saved |
required |
encoding
|
Encoding
|
The string encoding used, Encoding.UTF8 by default |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the object was saved successfully. |