Compiling Code
Read Compilation Result
Request
Read a compile result for a specific Project Id and Compile Id. The /compile/read
API accepts requests in the following format:
ReadCompileRequest Model - Request to read a compile packet job. | |
---|---|
projectId | integer Project Id we sent for compile. |
compileId | string Compile Id returned during the creation request. |
Example |
{ "projectId": 23456789, "compileId": "c0edc6-49048b" } |
Responses
The /compile/read
API provides a response in the following format:
200 Success
CompileResponse Model - Response from the compiler on a build event. | |
---|---|
compileId | string Compile Id for a sucessful build. |
state | string Enum True on successful compile. Options : ['InQueue', 'BuildSuccess', 'BuildError'] |
projectId | integer Project Id we sent for compile. |
signature | string Signature key of compilation. |
signatureOrder | string Array Signature order of files to be compiled. |
logs | string Array Logs of the compilation request. |
success | boolean Indicate if the API request was successful. |
errors | string Array List of errors with the API call. |
Example |
{ "compileId": "c0edc6-49048b", "state": "InQueue", "projectId": 23456789, "signature": "string", "signatureOrder": [ "string" ], "logs": [ "string" ], "success": true, "errors": [ "string" ] } |
401 Authentication Error
UnauthorizedError Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash. | |
---|---|
www_authenticate | string Header |
Examples
The following example demonstates creating, and reading a compilation job through the cloud API.
from base64 import b64encode from hashlib import sha256 from time import time from requests import get, post BASE_URL = 'https://www.quantconnect.com/api/v2/' # You need to replace these with your actual credentials. # You can request your credentials at https://www.quantconnect.com/settings/ # You can find our organization ID at https://www.quantconnect.com/organization/ USER_ID = 0 API_TOKEN = '____' ORGANIZATION_ID = '____' def get_headers(): # Get timestamp timestamp = f'{int(time())}' time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8') # Get hased API token hashed_token = sha256(time_stamped_token).hexdigest() authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8') authentication = b64encode(authentication).decode('ascii') # Create headers dictionary. return { 'Authorization': f'Basic {authentication}', 'Timestamp': timestamp } # Authenticate to verify credentials response = post(f'{BASE_URL}/authenticate', headers = get_headers()) print(response.json()) # -------------------- # The project ID of the project to compile project_id = 12345678 ### Create Compilation Job # Prepare data payload to create a compilation job payload = { "projectId": project_id # ID of the project to compile } # Send a POST request to the /compile/create endpoint to start compilation response = post(f'{BASE_URL}/compile/create', headers=get_headers(), json=payload) # Parse the JSON response into python managable dict result = response.json() # Extract the compile ID from the response compile_id = result['compileId'] # Check if the request was successful and print the result if result['success']: print("Compilation Job Created Successfully:") print(result) ### Read Compilation Result # Prepare data payload to read compilation result payload = { "projectId": project_id, # ID of the project "compileId": compile_id # ID of the compilation job } # Send a POST request to the /compile/read endpoint to get compilation result response = post(f'{BASE_URL}/compile/read', headers=get_headers(), json=payload) # Parse the JSON response into python managable dict result = response.json() # Check if the request was successful and print the result if result['success']: print("Compilation Result:") print(result)