book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

Nodes

Update Project Nodes

Introduction

Update the active state of some nodes to true. If you don't provide any nodes, all the nodes become inactive and AutoSelectNode is true.

Request

The /projects/nodes/update API accepts requests in the following format:

UpdateProjectNodesRequest Model - Request to update the nodes of a project.
projectId integer
required
example: 23456789

Project Id to which the nodes refer.
nodes string Array
List of node Id to update.
Example
{
  "projectId": 23456789,
  "nodes": [
    "string"
  ]
}

Responses

The /projects/nodes/update API provides a response in the following format:

200 Success

ProjectNodesResponse Model - Response received when reading all nodes of a project.
nodes #/components/schemas/ProjectNodes
List of project nodes.
autoSelectNode boolean
Indicate if a node is automatically selected.
success boolean
Indicate if the API request was successful.
errors string Array
List of errors with the API call.
Example
{
  "nodes": ,
  "autoSelectNode": true,
  "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, reading, updating, and deleting a project 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 manage
project_id = 12345678

### Create Project
# Send a POST request to the /projects/create endpoint to create a new project
response = post(f'{BASE_URL}/projects/create', headers=get_headers(), json={
    "name": f"Project_{int(time())}",  # Unique project name using current timestamp
    "language": "Py"  # Programming language for the project (Python)
})
# Parse the JSON response into python managable dict
result = response.json()
# Extract the project ID from the response
project_id = result['projects'][0]['projectId']
# Check if the request was successful and print the result
if result['success']:
    print("Project Created Successfully:")
    print(result)

### Read Project
# Prepare data payload to read project details
payload = {
    "id": project_id  # ID of the project to read
}
# Send a POST request to the /projects/read endpoint to get project details
response = post(f'{BASE_URL}/projects/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 project details
if result['success']:
    print("Project Details:")
    print(result)

### Update Project
# Send a POST request to the /projects/update endpoint to update project details
response = post(f'{BASE_URL}/projects/update', headers=get_headers(), json={
    "projectId": project_id,  # ID of the project to update
    "name": f"Project_{project_id}",  # New name for the project
    "description": "The new project name is awesome!"  # New description
})
# 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("Project Updated Successfully:")
    print(result)

### Delete Project
# Prepare data payload to delete the project
payload = {
    "projectId": project_id  # ID of the project to delete
}
# Send a POST request to the /projects/delete endpoint to delete the project
response = post(f'{BASE_URL}/projects/delete', 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("Project Deleted Successfully:")
    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: