Skip to content

LocalStorage.SetObject

method · LocalStorage · cAlgo.API

DesktopCLICloud

Saves an object to local storage. The storage scope is LocalStorageScope.Instance.

Environment behaviour

Cloud — works differently. Values are kept in memory for the current run only; nothing is saved to or read from disk, and auto-flush is off.

Overloads

Signature Description
SetObject(string key, object obj) Saves an object to local storage. The storage scope is LocalStorageScope.Instance.
SetObject(string key, object obj, LocalStorageScope localStorageScope) Saves an object to local storage.

SetObject(string key, object obj)

Saves an object to local storage. The storage scope is LocalStorageScope.Instance.

void SetObject(string key, object obj)
api.LocalStorage.SetObject(key: str, obj: object) -> None

Parameters

Name C# type Python type Description
key string str The key of the element to add, 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
obj object object The object of the element to add

Examples

LocalStorage.SetObject("Last Price", Symbol.Bid);
Print("Stored price: {0}", LocalStorage.GetObject<double>("Last Price"));
from System import Double

api.LocalStorage.SetObject("Last Price", api.Symbol.Bid)
api.Print(f"Stored price: {api.LocalStorage.GetObject[Double]('Last Price')}")

SetObject(string key, object obj, LocalStorageScope localStorageScope)

Saves an object to local storage.

void SetObject(string key, object obj, LocalStorageScope localStorageScope)
api.LocalStorage.SetObject(key: str, obj: object, localStorageScope: LocalStorageScope) -> None

Parameters

Name C# type Python type Description
key string str The key of the element to add, 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
obj object object The object of the element to add
localStorageScope LocalStorageScope LocalStorageScope The storage scope of the element

Examples

LocalStorage.SetObject("Last Price", Symbol.Bid, LocalStorageScope.Device);
Print("Stored price: {0}", LocalStorage.GetObject<double>("Last Price", LocalStorageScope.Device));
from System import Double

api.LocalStorage.SetObject("Last Price", api.Symbol.Bid, LocalStorageScope.Device)
api.Print(f"Stored price: {api.LocalStorage.GetObject[Double]('Last Price', LocalStorageScope.Device)}")