Nodes

Stop Nodes

Introduction

Stop the activity running on a node of your organization.

Description

To get the Id of a node, call the /projects/nodes/read endpoint. On a research node, this endpoint stops the research session. On an agent node, it stops every agent deployment. On a backtest node, it stops and deletes the running backtest. On a live node, it stops the live algorithm. The Stop button on the Resources page calls this endpoint.

Request

The /nodes/stop API accepts requests in the following format:

StopNodeRequest Model - Request to stop a node.
organizationId string
required
example: 5cad178b20a1d52567b534553413b691

Id of the organization that owns the node.
nodeId string
required

Id of the node to stop.
Example
{
  "organizationId": "5cad178b20a1d52567b534553413b691",
  "nodeId": "string"
}

Responses

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

200 Success

RestResponse Model - Base API response class for the QuantConnect API.
success boolean
Indicate if the API request was successful.
errors string Array
List of errors with the API call.
Example
{
  "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 demonstrates reading, updating, and stopping the nodes of 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

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

### Update Project Nodes
# Define a list of node Ids to update (replace with actual node Ids)
nodes = ["node_id_1", "node_id_2"]
# Prepare data payload to update project nodes
payload = {
    "projectId": project_id,  # ID of the project
    "nodes": nodes  # List of node Ids to associate with the project
}
# Send a POST request to the /projects/nodes/update endpoint to update nodes
response = post(f'{BASE_URL}/projects/nodes/update', 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 Nodes Updated Successfully:")
    print(result)

### Stop Project Nodes
# Read the project nodes to find the ones the project is using
response = post(f'{BASE_URL}/projects/nodes/read', headers=get_headers(), json={
    "projectId": project_id  # ID of the project
})
nodes = response.json()['nodes']
# Stop the research and agent nodes that are busy with this project
# (remove a list to stop only one type of node)
for node in nodes['research'] + nodes['agent']:
    if not node['busy'] or node['projectId'] != project_id:
        continue
    # Send a POST request to the /nodes/stop endpoint to stop the node
    response = post(f'{BASE_URL}/nodes/stop', headers=get_headers(), json={
        "organizationId": ORGANIZATION_ID,  # ID of the organization that owns the node
        "nodeId": node['id']  # ID of the node to stop
    })
    # 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(f"Node {node['name']} Stopped Successfully")
    else:
        print(f"Node {node['name']} Not Stopped:", result['errors'])

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: