QuantConnect API

Files

Introduction

This page explains how to create and manage files of a project in the research environment.

Prerequisites

Working knowledge of C#.

Working knowledge of Python.

You'll need to understand how to do Project Management through the QuantConnect Api.

Create Files

Follow these steps to create files in a project by the QuantConnect Api.

  1. Call AddProjectFile with the project ID, file name and file content. This will return a RestResponse.
  2. var projectId = <yourProjectId>;
    var content = "pass";
    var response = api.AddProjectFile(projectId, "newFile.cs", content);
    project_id = <your_project_id>
    content = "pass"
    response = api.AddProjectFile(project_id, "new_file.py", content)
  3. Call Success attribute to check if the creation request is successful.
  4. Console.WriteLine($"{response.Success}");
    print(f"{response.Success}")

Read Files

Note that the below instructions would fetch a snapshot of the files at this instance. You'll need to re-read them to update the information.

Read A Specific File

Follow these steps to read details of a file by the QuantConnect Api.

  1. Call ReadProjectFile with the project ID and the file name.
  2. var files = api.ReadProjectFile(projectId, "newFile.cs");
    files = api.ReadProjectFile(project_id, "new_file.py")
  3. Call Files attribute, then obtain the first file.
  4. var file = files.Files[0];
    file = files.Files[0]
  5. Display the file's details.
  6. Console.WriteLine($@"Name: {file.Name}
    Last Modified: {file.DateModified}
    Content: {file.Code}")
    print(f"""Name: {file.Name}
    Last Modified: {file.DateModified.strftime("%Y/%m/%d %H:%M:%S")}
    Content: {file.Code}""")

Read All Files

Follow these steps to read details of all files in a project by the QuantConnect Api.

  1. Call ReadProjectFiles with the project ID.
  2. var files = api.ReadProjectFiles(projectId);
    files = api.ReadProjectFiles(project_id)
  3. Call Files attribute to obtain a list of files.
  4. var filesList = files.Files;
    files_list = files.Files
  5. Display the files' details.
  6. foreach(var file in filesList)
    {
        Console.WriteLine($@"Name: {file.Name}
    Last Modified: {file.DateModified}
    Content: {file.Code}
    ");
    }
    for file in files_list:
        print(f"""Name: {file.Name}
    Last Modified: {file.DateModified.strftime("%Y/%m/%d %H:%M:%S")}
    Content: {file.Code}\n""")

Update Files

Update File Name

Follow these steps to update a file's name in a project by the QuantConnect Api.

  1. Call UpdateProjectFileName with the project ID, old file name and new file name. This will return a RestResponse.
  2. var response = api.UpdateProjectFileName(projectId, "newFile.cs", "file.cs");
    response = api.UpdateProjectFileName(project_id, "new_file.py", "file.py")
  3. Call Success attribute to check if the update request is successful.
  4. Console.WriteLine($"{response.Success}");
    print(f"{response.Success}")

    You may re-read the file to check this change.

Update File Content

Follow these steps to update a file's content in a project by the QuantConnect Api.

  1. Call UpdateProjectFileContent with the project ID, file name and new content. This will return a RestResponse.
  2. var content = "//";
    var response = api.UpdateProjectFileContent(projectId, "file.cs", content);
    content = "#"
    response = api.UpdateProjectFileContent(project_id, "file.py", content)
  3. Call Success attribute to check if the update request is successful.
  4. Console.WriteLine($"{response.Success}");
    print(f"{response.Success}")

    You may re-read the file to check this change.

Delete Files

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

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

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: