QuantConnect API
Files
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.
- Call
AddProjectFile
with the project ID, file name and file content. This will return aRestResponse
. - Call
Success
attribute to check if the creation request is successful.
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)
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.
- Call
ReadProjectFile
with the project ID and the file name. - Call
Files
attribute, then obtain the first file. - Display the file's details.
var files = api.ReadProjectFile(projectId, "newFile.cs");
files = api.ReadProjectFile(project_id, "new_file.py")
var file = files.Files[0];
file = files.Files[0]
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.
- Call
ReadProjectFiles
with the project ID. - Call
Files
attribute to obtain a list of files. - Display the files' details.
var files = api.ReadProjectFiles(projectId);
files = api.ReadProjectFiles(project_id)
var filesList = files.Files;
files_list = files.Files
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.
- Call
UpdateProjectFileName
with the project ID, old file name and new file name. This will return aRestResponse
. - Call
Success
attribute to check if the update request is successful.
var response = api.UpdateProjectFileName(projectId, "newFile.cs", "file.cs");
response = api.UpdateProjectFileName(project_id, "new_file.py", "file.py")
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.
- Call
UpdateProjectFileContent
with the project ID, file name and new content. This will return aRestResponse
. - Call
Success
attribute to check if the update request is successful.
var content = "//"; var response = api.UpdateProjectFileContent(projectId, "file.cs", content);
content = "#" response = api.UpdateProjectFileContent(project_id, "file.py", content)
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.
- Call
DeleteProjectFile
with the project ID and file name. This will return aRestResponse
. - Call
Success
attribute to check if the update request is successful.
var response = api.DeleteProjectFile(projectId, "file.cs");
response = api.DeleteProjectFile(project_id, "file.py")
Console.WriteLine($"{response.Success}");
print(f"{response.Success}")
