---
id: "T:cAlgo.API.LocalStorage"
kind: "interface"
namespace: "cAlgo.API"
url: "https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/"
---

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

# LocalStorage (interface)

Represents the local storage API.

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.

## Definition

```csharp
public interface LocalStorage
```

## Examples

C#:

```csharp
using cAlgo.API;

namespace cAlgo.Robots;

public partial class TestExample : Robot
{
    protected override void OnStart()
    {
        const string key = "Key";
        const string expectedData = "Data";

        LocalStorage.SetString("Key", expectedData);

        Print($"Actual Date: {LocalStorage.GetString(key)} | Expected Data: {expectedData}");
    }
}
```

Python:

```python
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *

# Import trading wrapper functions
from robot_wrapper import *

class Test():
    def on_start(self):
        key = "Key"
        expectedData = "Data"
        api.LocalStorage.SetString("Key", expectedData)
        print(f"Actual Date: {api.LocalStorage.GetString(key)} | Expected Data: {expectedData}")
```

config.json:

```json
{
  "AccessRights": "None"
}
```

C#:

```csharp
using cAlgo.API;

namespace cAlgo.Robots;

public partial class TestExample : Robot
{
    public record Point(double X, double Y);

    protected override void OnStart()
    {
        const string key = "Key";

        var expectedPoint = new Point(10, 12);

        LocalStorage.SetObject(key, expectedPoint);

        Print($"Actual Point: {LocalStorage.GetObject<Point>(key)} | Expected Point: {expectedPoint}");

        LocalStorage.Remove(key);
        LocalStorage.Flush(LocalStorageScope.Instance);

        Print($"Point After Remove: {LocalStorage.GetObject<Point>(key)}");
    }
}
```

Python:

```python
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *

# Import trading wrapper functions
from robot_wrapper import *

class Test():
    def on_start(self):
        key = "Key"
        expectedValue = 10.2
        api.LocalStorage.SetObject(key, expectedValue)
        print(f"Actual: {api.LocalStorage.GetString(key)} | Expected: {expectedValue}")
        api.LocalStorage.Remove(key)
        api.LocalStorage.Flush(LocalStorageScope.Instance)
        print(f"After Remove: {api.LocalStorage.GetString(key)}")
```

config.json:

```json
{
  "AccessRights": "None"
}
```

## Methods

- `void Flush(LocalStorageScope localStorageScope)` — Saves all data to the disk. When using local storage, data is automatically saved every minute. Use this method if you want to save data without delays. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/Flush/index.md)
- `T 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. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/GetObject/index.md)
- `T GetObject(string key, LocalStorageScope localStorageScope)` — Gets an object from local storage. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/GetObject/index.md)
- `string GetString(string key)` — Gets a string value from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/GetString/index.md)
- `string GetString(string key, LocalStorageScope localStorageScope)` — Gets a string value from local storage. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/GetString/index.md)
- `void Reload(LocalStorageScope localStorageScope)` — Reloads all values from the disk. When calling this method, unsaved pending changes may be lost. To avoid losing information, call the Flush() method first. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/Reload/index.md)
- `void Remove(string key)` — Removes an element from local storage. This method will search all available scopes (Instance -> Type -> Device) and stops on first found value. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/Remove/index.md)
- `void Remove(string key, LocalStorageScope localStorageScope)` — Removes an element from local storage. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/Remove/index.md)
- `void SetObject(string key, object obj)` — Saves an object to local storage. The storage scope is LocalStorageScope.Instance. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/SetObject/index.md)
- `void SetObject(string key, object obj, LocalStorageScope localStorageScope)` — Saves an object to local storage. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/SetObject/index.md)
- `void SetString(string key, string value)` — Saves a string value to local storage. The storage scope is LocalStorageScope.Instance. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/SetString/index.md)
- `void SetString(string key, string value, LocalStorageScope localStorageScope)` — Saves a string value to local storage. [details](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/SetString/index.md)

