Tools
Search
Request
Search for content in QuantConnect. The /ai/tools/search
API accepts requests in the following format:
SearchRequest Model - Request to search content in QuantConnect. | |
---|---|
language | string Enum Programming language of the content to search. Options : ['C#', 'Py'] |
criteria | SearchCriteria Array Criteria for the search. |
Example |
{ "language": "Py", "criteria": "[{"input": "option", "type": "Docs", "count": 1}]" ] } |
SearchCriteria Model - Search criteria. | |
---|---|
input | string Input for the search. |
type | string Type of the search criteria. |
count | integer Number of results to return. |
Example |
{ "input": "option", "type": "Docs", "count": 1 } |
Responses
The /ai/tools/search
API provides a response in the following format:
200 Success
SearchResponse Model - Response to a search request. | |
---|---|
state | string State of the search. |
version | string Version of the response. |
retrivals | SearchRetrieval Array List of search results. |
messageId | integer ID of the message. |
Example |
{ "state": "End", "version": 2.0, "retrivals": [ { "url": "option[Index Options - QuantConnect.com](https://www.quantconnect.com/docs/v2/writing-algorithms/universes/index-options)", "score": 0.320344448, "content": "string", "type": 2 } ], "messageId": 0 } |
SearchRetrieval Model - Search criteria. | |
---|---|
url | string Input for the search. |
score | number Relevance score of the search result. |
content | string Content of the search result. |
type | number Type of the search result. |
Example |
{ "url": "option[Index Options - QuantConnect.com](https://www.quantconnect.com/docs/v2/writing-algorithms/universes/index-options)", "score": 0.320344448, "content": "string", "type": 2 } |
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 searching content in QuantConnect 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()) # -------------------- ### Search Content # Send a POST request to the /ai/tools/search endpoint to search content response = post(f'{BASE_URL}/ai/tools/search', headers=get_headers(), json={ "language": "Python", # Programming language to filter search results "criteria": [ # Search criteria { "input": "option", # Search term (e.g., "option") "type": "Docs", # Type of content to search (e.g., documentation) "count": 1 # Number of results to return } ] }) # Parse the JSON response into python managable dict result = response.json() # Check if the request was successful and print the search results if result['success']: print("Search Results:") print(result)