API Reference
Authentication
Authenticating Requests
Requests to QuantConnect API v2 require a hashed combination of time, and the API token. The unixtime stamp combination serves as a nonce token as each request is sent with a different signature but never requires sending the API token itself.
Hashing
Follow the below example to create a hashed token for authentication.
# Generate a timestamped SHA-256 hashed API token for secure authentication import base64 import hashlib import time # Get timestamp timestamp = str(int(time.time())) time_stamped_token = "<your_api_token>" + ':' + timestamp # Get hased API token hashed_token = hashlib.sha256(time_stamped_token.encode('utf-8')).hexdigest() authentication = "{}:{}".format(<your_user_id>, hashed_token) api_token = base64.b64encode(authentication.encode('utf-8')).decode('ascii')
Make API Request
Follow the below example to install the hashing into the headings and make an API request.
# Create headers dictionary. headers = { 'Authorization': 'Basic %s' % api_token, 'Timestamp': timestamp } # Create POST Request with headers (optional: Json Content as data argument). response = requests.post("<request_url>", data = {}, json = {}, # Some request requires json param (must remove the data param in this case) headers = headers) content = response.text
Authenticated State Responses
The /authenticate
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. |
Example |
{ "success": true } |
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 |