Compiling Code

Read Compilation Result

Introduction

Read a compile packet job 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
required

Id of the project you requested to compile.
compileId string
required

Compile Id returned during the creation request.
Example
{
  "projectId": 0,
  "compileId": "string"
}

Responses

The /compile/read API provides a response in the following format:

200 Success

ReadCompileResponse Model - Response received from reading a compile job.
compileId string
Compile Id for a successful build.
state string Enum
The current state of the compile job. Options : ['InQueue', 'BuildSuccess', 'BuildError']
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": "string",
  "state": "InQueue",
  "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)

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: