---
id: "M:cAlgo.API.LocalStorage.SetObject(System.String,System.Object)"
kind: "method"
type: "T:cAlgo.API.LocalStorage"
url: "https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/SetObject/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# LocalStorage.SetObject

Member of [LocalStorage](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/index.md).

## SetObject(string key, object obj)

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

Environments: Desktop supported · CLI supported · Cloud works differently.

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

C#:

```csharp
void SetObject(string key, object obj)
```

Python:

```python
api.LocalStorage.SetObject(key: str, obj: object) -> None
```

### Parameters

- `key` (`string`, Python `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`, Python `object`): The object of the element to add

### Examples

C#:

```csharp
LocalStorage.SetObject("Last Price", Symbol.Bid);
Print("Stored price: {0}", LocalStorage.GetObject<double>("Last Price"));
```

Python:

```python
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.

Environments: Desktop supported · CLI supported · Cloud works differently.

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

C#:

```csharp
void SetObject(string key, object obj, LocalStorageScope localStorageScope)
```

Python:

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

### Parameters

- `key` (`string`, Python `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`, Python `object`): The object of the element to add
- `localStorageScope` (`LocalStorageScope`, Python `LocalStorageScope`): The storage scope of the element

### Examples

C#:

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

Python:

```python
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)}")
```

