Skip to content

LocalStorage.GetObject

method · LocalStorage · cAlgo.API

DesktopCLICloud

Gets an object from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value.

Environment behaviour

Cloud — works differently. Key not set in this run returns default and sends LocalStorageException 'Getting local storage data from file is not supported in cloud environment.' to OnException.

Overloads

Signature Description
GetObject(string key) Gets an object from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value.
GetObject(string key, LocalStorageScope localStorageScope) Gets an object from local storage.

GetObject(string key)

Gets an object from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value.

T GetObject(string key)
api.LocalStorage.GetObject(key: str) -> T

Parameters

Name C# type Python type Description
key string str The key of the element to get, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end

Returns T — The deserialized object or default value of type if the provided key is not found or the object cannot be deserialized

Examples

LocalStorage.SetObject("Trades Count", 5);
var tradesCount = LocalStorage.GetObject<int>("Trades Count");
Print("Trades count: {0}", tradesCount);
from System import Int32

api.LocalStorage.SetObject("Trades Count", 5)
tradesCount = api.LocalStorage.GetObject[Int32]("Trades Count")
api.Print(f"Trades count: {tradesCount}")

GetObject(string key, LocalStorageScope localStorageScope)

Gets an object from local storage.

T GetObject(string key, LocalStorageScope localStorageScope)
api.LocalStorage.GetObject(key: str, localStorageScope: LocalStorageScope) -> T

Parameters

Name C# type Python type Description
key string str The key of the element to get, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end
localStorageScope LocalStorageScope LocalStorageScope The storage scope of the element

Returns T — The deserialized object or default value of type if the provided key is not found or the object cannot be deserialized

Examples

LocalStorage.SetObject("Trades Count", 5, LocalStorageScope.Type);
var tradesCount = LocalStorage.GetObject<int>("Trades Count", LocalStorageScope.Type);
Print("Trades count across instances: {0}", tradesCount);
from System import Int32

api.LocalStorage.SetObject("Trades Count", 5, LocalStorageScope.Type)
tradesCount = api.LocalStorage.GetObject[Int32]("Trades Count", LocalStorageScope.Type)
api.Print(f"Trades count across instances: {tradesCount}")