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

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

# Compiler (interface)

Provides access to compiler for algos.

Environments: Desktop supported · CLI supported · Cloud not supported.

- Cloud: Nothing is compiled. Compile returns a failed result with no errors; CompileAsync calls back asynchronously with that failed result.

## Definition

```csharp
public interface Compiler
```

Available since cAlgo.API 5.1.

## Examples

C#:

```csharp
using cAlgo.API;

namespace cAlgo.Robots;

public partial class TestExample : Robot
{
   protected override void OnStart()
   {
       // Path is relative to Algo type data directory
       var result = Compiler.Compile(@"Test\Test\Test.csproj");

       if (result.Succeeded)
            Print("Compilation finished successfully");
       else
            Print($"Compilation failed with errors: {string.Join(", ", result.Errors)}");
   }
}
```

Python:

```python
# Path is relative to Algo type data directory
result = api.Compiler.Compile(r"Test\Test\Test.csproj")
if result.Succeeded:
    api.Print("Compilation finished successfully")
else:
    errors = ", ".join(result.Errors)
    api.Print(f"Compilation failed with errors: {errors}")
```

config.json:

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

C#:

```csharp
using cAlgo.API;

namespace cAlgo.Robots;

public partial class TestExample : Robot
{
   protected override void OnStart()
   {
       // Path is relative to Algo type data directory
       var operation = Compiler.CompileAsync(@"Test\Test\Test.csproj", result =>
       {
            if (result.Succeeded)
                Print("Compilation finished successfully");
            else
                Print($"Compilation failed with errors: {string.Join(", ", result.Errors)}");
       });

       if (operation.IsExecuting)
            Print("Compilation is running");
   }
}
```

Python:

```python
def on_start(self):
    # Path is relative to Algo type data directory
    operation = api.Compiler.CompileAsync(r"Test\Test\Test.csproj", self.on_compilation_finished)
    if operation.IsExecuting:
        api.Print("Compilation is running")

def on_compilation_finished(self, result):
    if result.Succeeded:
        api.Print("Compilation finished successfully")
    else:
        errors = ", ".join(result.Errors)
        api.Print(f"Compilation failed with errors: {errors}")
```

config.json:

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

## Methods

- `CompilationResult Compile(string csprojFilePath)` — Compiles an algo. [details](https://help.ctrader.com/ctrader-algo/references/Compilation/Compiler/Compile/index.md)
- `CompilationResult Compile(string csprojFilePath, CompilationOptions options)` — Compiles an algo. [details](https://help.ctrader.com/ctrader-algo/references/Compilation/Compiler/Compile/index.md)
- `CompilationOperation CompileAsync(string csprojFilePath, Action<CompilationResult> callback)` — Compiles an algo asynchronously and calls the passed callback when compilation finishes. [details](https://help.ctrader.com/ctrader-algo/references/Compilation/Compiler/CompileAsync/index.md)
- `CompilationOperation CompileAsync(string csprojFilePath, Action<CompilationResult> callback, CompilationOptions options)` — Compiles an algo asynchronously and calls the passed callback when compilation finishes. [details](https://help.ctrader.com/ctrader-algo/references/Compilation/Compiler/CompileAsync/index.md)

