Compiling Code

Create Compilation Job

Introduction

Asynchronously create a compile job request for a project.

Request

Project Id specifying project to build. The /compile/create API accepts requests in the following format:

CreateCompileRequest Model - Request to compile a project.
projectId integer
required

Id of the project to compile.
Example
{
  "projectId": 0
}

Responses

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

200 Success

CreateCompileResponse Model - Response received from creating 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']
parameters FileParameters Array
List of files and their associated parameters detected during compilation.
projectId integer
Id of the project you requested to compile.
signature string
Signature key of compilation.
signatureOrder string Array
Signature order of files to be compiled.
success boolean
Indicate if the API request was successful.
errors string Array
List of errors with the API call.
Example
{
  "compileId": "string",
  "state": "InQueue",
  "parameters": [
    {
      "file": "string",
      "parameters": [
        {
          "line": 0,
          "type": "string"
        }
      ]
    }
  ],
  "projectId": 0,
  "signature": "string",
  "signatureOrder": [
    "string"
  ],
  "success": true,
  "errors": [
    "string"
  ]
}
FileParameters Model
file string
Path of the file in the project.
parameters ParameterDetail Array
List of parameters detected in the file.
Example
{
  "file": "string",
  "parameters": [
    {
      "line": 0,
      "type": "string"
    }
  ]
}
ParameterDetail Model
line integer
Line number where the parameter was detected.
type string
Description of the detected parameter.
Example
{
  "line": 0,
  "type": "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: