QuantConnect API

Projects

Introduction

This page explains how to create and manage projects in the research environment.

Prerequisites

Working knowledge of C#.

Working knowledge of Python.

Create Projects

Follow these steps to create projects by using the QuantConnect Api.

  1. Load the required assembly files and data types.
  2. #load "../Initialize.csx"
    #load "../QuantConnect.csx"
    
    using QuantConnect;
  3. Call CreateProject with a custom project name, the programming language and (optional) the selected organization ID. This will return a ProjectResponse.
  4. var newProject = api.CreateProject(name: "Project", 
                                       language: Language.CSharp,
                                       organizationId: "<yourOrganizationName>");
    new_project = api.CreateProject(name="Project", 
                                    language=Language.Python,
                                    organizationId="<your_organization_name>")
  5. Call Success attribute to check if the creation request is successful.
  6. Console.WriteLine($"{newProject.Success}");
    print(f"{new_project.Success}")

Read Projects

Follow these instructions to read details of a project by the QuantConnect Api.

  1. Call ReadProject with the project ID.
  2. var projectId = newProject.Projects.First().ProjectId;
    var readProject = api.ReadProject(projectId);
    project_id = new_project.Projects[0].ProjectId
    read_project = api.ReadProject(project_id)
  3. Call Projects attribute.
  4. var project = readProject.Projects.First();
    project = read_project.Projects[0]
  5. Display the project's details.
  6. Console.WriteLine($@"Project ID: {project.ProjectId}
    Name: {project.Name}
    Created Time: {project.Created}
    Last Modified Time: {project.Modified}
    Language: {project.Language}")
    lang = {0: "C#", 4: "Python"}
    
    print(f"""Project ID: {project.ProjectId}
    Name: {project.Name}
    Created Time: {project.Created.strftime("%Y/%m/%d %H:%M:%S")}
    Last Modified Time: {project.Modified.strftime("%Y/%m/%d %H:%M:%S")}
    Language: {lang[project.Language]}""")

Note that this would be a snapshot of the project at this instance. You'll need to re-read it to update the information.

Compile Projects

Create Compile

Follow these steps to create compilation task for a project.

  1. Call CreateCompile with the project ID.
  2. var newCompile = api.CreateCompile(projectId);
    new_compile = api.CreateCompile(project_id)
  3. Display the compilation result.
  4. Console.WriteLine($@"Compile ID: {newCompile.CompileId}
    State: {newCompile.State}
    Logs: [{string.Join(", ", compile.Logs)}]");
    states = {0: "In Queue", 1: "Build Success", 2: "Build Error"}
    print(f"""Compile ID: {new_compile.CompileId}
    State: {states[new_compile.State]}
    Logs: {new_compile.Logs}""")

Read Compile

Follow these steps to read a compilation task of a project.

  1. Call ReadCompile with the project ID and the compile ID.
  2. var compile = api.ReadCompile(projectId, newCompile.CompileId);
    compile_ = api.ReadCompile(project_id, new_compile.CompileId)
  3. Display the compilation result.
  4. Console.WriteLine($@"Compile ID: {compile.CompileId}
    State: {compile.State}
    Logs: [{string.Join(", ", compile.Logs)}]
    ");
    print(f"""Compile ID: {compile_.CompileId}
    State: {states[compile_.State]}
    Logs: {compile_.Logs}
    """);

Delete Projects

Follow these steps to delete a project by the QuantConnect Api.

  1. Call DeleteProject with the project ID. This will return a RestResponse.
  2. var response = api.DeleteProject(projectId);
    response = api.DeleteProject(project_id)
  3. Call Success attribute to check if the update request is successful.
  4. Console.WriteLine($"{response.Success}");
    print(f"{response.Success}")

List Projects

Follow these steps to list out all projects by using the QuantConnect Api.

  1. Call ListProjects.
  2. var projects = api.ListProjects();
    projects = api.ListProjects()
  3. Call Projects attribute. This will return a list of projects.
  4. var projectList = projects.Projects;
    project_list = projects.Projects
  5. Display the project details.
  6. foreach(var prj in projectList.Take(2))
    {
        Console.WriteLine($@"Project ID: {prj.ProjectId}
    Name: {prj.Name}
    Created Time: {prj.Created}
    Language: {prj.Language}
    ");
    }
    for prj in project_list[:2]:
        print(f"""Project ID: {prj.ProjectId}
    Name: {prj.Name}
    Created Time: {prj.Created.strftime("%Y/%m/%d %H:%M:%S")}
    Language: {lang[prj.Language]}\n""")

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: