Live Management
Create Live Algorithm
Request
Project, compile and brokerage login information for deploying a live algorithm. The /live/create
API accepts requests in the following format:
CreateLiveAlgorithmRequest Model - Request to create a live algorithm. | |
---|---|
versionId | string The version of the Lean used to run the algorithm. -1 is master, however, sometimes this can create problems with live deployments. If you experience problems using, try specifying the version of Lean you would like to use. |
projectId | integer Project Id. |
compileId | string Compile Id. |
nodeId | string Id of the node that will run the algorithm. |
brokerage | object Enum Brokerage configurations to be used in the live algorithm. Options : ['QuantConnectSettings', 'InteractiveBrokersSettings', 'BinanceSettings', 'BinanceFuturesUSDMSettings', 'BinanceFuturesCOINSettings', 'BinanceUSSettings', 'TradierSettings', 'BitfinexSettings', 'CoinbaseSettings', 'KrakenSettings', 'BybitSettings', 'OandaSettings', 'ZerodhaSettings', 'SamcoSettings', 'WolverineSettings', 'CharlesSchwabSettings', 'TradingTechnologiesSettings', 'RBIBrokerageSettings', 'TerminalLinkSettings'] |
dataProviders | object Dictionary of data provider configurations to be used in the live algorithm. |
Example |
{ "versionId": "-1", "projectId": 23456789, "compileId": "c0edc6-49048b", "nodeId": "string", "brokerage": { "id": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ], "cash": [ { "amount": 0, "currency": "string" } ] }, "dataProviders": { "QuantConnectBrokerage": { "id": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ], "cash": [ { "amount": 0, "currency": "string" } ] } } } |
QuantConnectSettings Model - QuantConnect settings for using it as a brokerage or data provider. | |
---|---|
id | string ID of QuantConnect, this is QuantConnectBrokerage. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
cash | CashAmount Array List of cash amount. |
Example |
{ "id": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ], "cash": [ { "amount": 0, "currency": "string" } ] } |
InteractiveBrokersSettings Model - Settings for using Interactive Brokers as brokerage or data provider. | |
---|---|
id | string ID of InteractiveBrokers, this is InteractiveBrokersBrokerage. |
ib-user-name | string Your Interactive Brokers username. |
ib-password | string Your Interactive Brokers password. |
ib-trading-mode | string Enum Represents the types of environments supported by Interactive Brokers for trading. Options : ['live', 'paper'] |
ib-account | string Your Interactive Brokers account id. |
ib-weekly-restart-utc-time | string($date) Weekly restart UTC time (hh:mm:ss). |
Example |
{ "id": "string", "ib-user-name": "string", "ib-password": "string", "ib-trading-mode": "live", "ib-account": "string", "ib-weekly-restart-utc-time": "2021-11-26T15:18:27.693Z" } |
BinanceSettings Model - Settings for using Binance as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, BinanceBrokerage. |
binance-exchange-name | string Binance exchange, this is, Binance. |
binance-api-secret | string Your Binance API secret. |
binance-api-key | string Your Binance API key. |
binance-api-url | string Binance configuration for spot/margin. The value for this property is https://api.binance.com. |
binance-websocket-url | string Binance configuration for spot/margin. The value for this property is wss://stream.binance.com:9443/ws. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "binance-exchange-name": "string", "binance-api-secret": "string", "binance-api-key": "string", "binance-api-url": "string", "binance-websocket-url": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
BinanceFuturesUSDMSettings Model - Settings for using Binance Futures USDM as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, BinanceBrokerage. |
binance-exchange-name | string Binance exchange, this is, Binance-USDM-Futures. |
binance-api-secret | string Your Binance API secret. |
binance-api-key | string Your Binance API key. |
binance-fapi-url | string Binance Futures configuration for spot/margin. The value for this property is https://fapi.binance.com. |
binance-fwebsocket-url | string Binance Futures configuration for spot/margin. The value for this property is wss://fstream.binance.com/ws. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "binance-exchange-name": "string", "binance-api-secret": "string", "binance-api-key": "string", "binance-fapi-url": "string", "binance-fwebsocket-url": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
BinanceFuturesCOINSettings Model - Settings for using Binance Futures COIN as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, BinanceBrokerage. |
binance-exchange-name | string Binance exchange, this is, Binance-COIN-Futures. |
binance-api-secret | string Your Binance API secret. |
binance-api-key | string Your Binance API key. |
binance-dapi-url | string Binance Futures configuration for spot/margin. The value for this property is https://dapi.binance.com. |
binance-dwebsocket-url | string Binance Futures configuration for spot/margin. The value for this property is wss://dstream.binance.com/ws. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "binance-exchange-name": "string", "binance-api-secret": "string", "binance-api-key": "string", "binance-dapi-url": "string", "binance-dwebsocket-url": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
BinanceUSSettings Model - Settings for using Binance US as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, BinanceBrokerage. |
binance-exchange-name | string Binance exchange, this is, BinanceUS. |
binanceus-api-secret | string Your Binance US API secret. |
binanceus-api-key | string Your Binance US API key. |
binanceus-api-url | string Binance US configuration for spot/margin. The value for this property is https://api.binance.us. |
binanceus-websocket-url | string Binance US configuration for spot/margin. The value for this property is wss://stream.binance.us:9443/ws. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "binance-exchange-name": "string", "binanceus-api-secret": "string", "binanceus-api-key": "string", "binanceus-api-url": "string", "binanceus-websocket-url": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
TradierSettings Model - Settings for using Tradier as a data provider. | |
---|---|
id | string ID of the brokerage, this is, TradierBrokerage. |
tradier-account-id | string Your Tradier account id. |
tradier-access-token | string Your Tradier access token. |
tradier-environment | string Enum Whether the developer sandbox should be used. Options : ['live', 'paper'] |
Example |
{ "id": "string", "tradier-account-id": "string", "tradier-access-token": "string", "tradier-environment": "live" } |
BitfinexSettings Model - Settings for using Bitfinex as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, BitfinexBrokerage. |
bitfinex-api-key | string Your Bitfinex API key. |
bitfinex-api-secret | string Your Bitfinex API secret. |
Example |
{ "id": "string", "bitfinex-api-key": "string", "bitfinex-api-secret": "string" } |
CoinbaseSettings Model - Settings for using Coinbase as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, CoinbaseBrokerage. |
coinbase-api-key | string Your Coinbase Advanced Trade API key. |
coinbase-api-secret | string Your Coinbase Advanced Trade API secret. |
coinbase-url | string Coinbase URL, this is, wss://advanced-trade-ws.coinbase.com. |
coinbase-rest-api | string Coinbase REST API, this is, https://api.coinbase.com. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "coinbase-api-key": "string", "coinbase-api-secret": "string", "coinbase-url": "string", "coinbase-rest-api": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
KrakenSettings Model - Settings for using Kraken as a data provider. | |
---|---|
id | string ID of the brokerage, this is, KrakenBrokerage. |
kraken-api-key | string Your Kraken API key. |
kraken-api-secret | string Your Kraken API secret. |
kraken-verification-tier | string Your Kraken Verification Tier. |
Example |
{ "id": "string", "kraken-api-key": "string", "kraken-api-secret": "string", "kraken-verification-tier": "string" } |
BybitSettings Model - Settings for using Bybit as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, BybitBrokerage. |
bybit-api-key | string Your Bybit API key. |
bybit-api-secret | string Your Bybit API secret. |
bybit-vip-level | string Your Bybit VIP Level. |
bybit-use-testnet | string Enum Whether the testnet should be used. Options : ['live', 'paper'] |
bybit-api-url | string Bybit API URL, this is, https://api-testnet.bybit.com. |
bybit-websocket-url | string Bybit Websocket URL, this is, wss://stream.bybit.com. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "bybit-api-key": "string", "bybit-api-secret": "string", "bybit-vip-level": "string", "bybit-use-testnet": "live", "bybit-api-url": "string", "bybit-websocket-url": "string", "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
OandaSettings Model - Settings for using Oanda as a data provider or brokerage. | |
---|---|
id | string ID of the brokerage, this is, OandaBrokerage. |
oanda-account-id | string Your OANDA account id can be found on your OANDA Account Statement page (https://www.oanda.com/account/statement/). It follows the following format '###-###-######-###'. |
oanda-access-token | string Your OANDA API token. You can generate an API token from the Manage API Access page (https://www.oanda.com/account/tpa/personal_token). |
oanda-environment | string Enum The environment to run in, Practice for fxTrade Practice, Trade for fxTrade. Options : ['Practice', 'Trade'] |
Example |
{ "id": "string", "oanda-account-id": "string", "oanda-access-token": "string", "oanda-environment": "Practice" } |
ZerodhaSettings Model - Settings for using Zerodha as a data provider or brokerage. | |
---|---|
id | string Brokerage ID, this is, ZerodhaBrokerage. |
zerodha-api-key | string Your Kite Connect API key. |
zerodha-access-token | string Your Kite Connect access token. |
zerodha-product-type | string Enum The product type must be set to MIS if you are targeting intraday products, CNC if you are targeting delivery products or NRML if you are targeting carry forward products. Options : ['mis', 'cnc', 'nrml'] |
zerodha-trading-segment | string Enum The trading segment must be set to 'equity' if you are trading equities on NSE or BSE, or 'commodity' if you are trading commodities on MCX. Options : ['equity', 'commodity'] |
zerodha-history-subscription | boolean Whether you have a history API subscription for Zerodha. |
Example |
{ "id": "string", "zerodha-api-key": "string", "zerodha-access-token": "string", "zerodha-product-type": "mis", "zerodha-trading-segment": "equity", "zerodha-history-subscription": true } |
SamcoSettings Model - Settings for using Samco as a data provider or brokerage. | |
---|---|
id | string Brokerage ID, this is, SamcoBrokerage. |
samco-client-id | string Your Samco account Client ID. |
samco-client-password | string Your Samco account password. |
samco-year-of-birth | integer Your year of birth (YYYY) registered with Samco. |
samco-product-type | string Enum MIS if you are targeting intraday products, CNC if you are targeting delivery products, NRML if you are targeting carry forward products. Options : ['mis', 'cnc', 'nrml'] |
samco-trading-segment | string Enum \'equity\' if you are trading equities on NSE or BSE, commodity if you are trading \'commodities\' on MCX. Options : ['equity', 'commodity'] |
Example |
{ "id": "string", "samco-client-id": "string", "samco-client-password": "string", "samco-year-of-birth": 0, "samco-product-type": "mis", "samco-trading-segment": "equity" } |
WolverineSettings Model - Settings for using Wolverine Execution Services as a brokerage. | |
---|---|
id | string Brokerage ID, this is, WolverineBrokerage. |
wolverine-on-behalf-of-comp-id | string Value used to identify the trading firm. |
wolverine-account | string Wolverine Execution Services account name. |
cash | CashAmount Array List of cash amount. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "wolverine-on-behalf-of-comp-id": "string", "wolverine-account": "string", "cash": [ { "amount": 0, "currency": "string" } ], "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
CharlesSchwabSettings Model - Settings for using Charles Schwab as a data provider or brokerage. | |
---|---|
id | string Brokerage ID, this is, Charles Schwab. |
charles-schwab-app-key | string Your Charles Schwab app key. |
charles-schwab-secret | string Your Charles Schwab secret. |
charles-schwab-account-number | string Your Charles Schwab account number. |
Example |
{ "id": "string", "charles-schwab-app-key": "string", "charles-schwab-secret": "string", "charles-schwab-account-number": "string" } |
TradingTechnologiesSettings Model - Settings for using Trading Technologies as a brokerage. | |
---|---|
id | string Brokerage ID, this is, TradingTechnologiesBrokerage. |
tt-user-name | string Trading Technologies user name. |
tt-session-password | string Trading Technologies session password. |
tt-account-name | string Trading Technologies account name. |
tt-rest-app-key | string Trading Technologies App key. |
tt-rest-app-secret | string Trading Technologies App secret. |
tt-rest-environment | string Enum Environment in which the brokerage Trading Technologies will be used. Options : ['live', 'uat'] |
tt-order-routing-sender-comp-id | string Trading Technologies remote comp id. |
cash | CashAmount Array List of cash amount. |
Example |
{ "id": "string", "tt-user-name": "string", "tt-session-password": "string", "tt-account-name": "string", "tt-rest-app-key": "string", "tt-rest-app-secret": "string", "tt-rest-environment": "live", "tt-order-routing-sender-comp-id": "string", "cash": [ { "amount": 0, "currency": "string" } ] } |
RBIBrokerageSettings Model - Settings for using RBI as a brokerage. | |
---|---|
id | string Brokerage ID, this is, RBIBrokerage. |
rbi-on-behalf-of-comp-id | string Value used to identify the trading firm. |
rbi-account | string RBI account name. |
cash | CashAmount Array List of cash amount. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "rbi-on-behalf-of-comp-id": "string", "rbi-account": "string", "cash": [ { "amount": 0, "currency": "string" } ], "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
TerminalLinkSettings Model - Settings for using TerminalLink as a brokerage. | |
---|---|
id | string Brokerage ID, this is TerminalLinkBrokerage. |
terminal-link-connection-type | string Enum Terminal Link Connection Type [DAPI, SAPI]. Options : ['DAPI', 'SAPI'] |
cash | CashAmount Array List of cash amount. |
holdings | BrokerageHolding Array List of holdings for the brokerage. |
Example |
{ "id": "string", "terminal-link-connection-type": "DAPI", "cash": [ { "amount": 0, "currency": "string" } ], "holdings": [ { "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } ] } |
BrokerageHolding Model - Holding object class for creating a live algorithm. | |
---|---|
symbolId | string Symbol ID of the holding. |
symbol | string Symbol ticker of the holding. |
quantity | number Quantity of the Symbol we hold. |
averagePrice | number Average Price of our Holding in the currency the symbol is traded in. |
Example |
{ "symbolId": "string", "symbol": "string", "quantity": 0, "averagePrice": 0 } |
CashAmount Model - Represents a cash amount which can be converted to account currency using a currency converter. | |
---|---|
amount | number The amount of cash. |
currency | string The currency in which the cash amount is denominated. |
Example |
{ "amount": 0, "currency": "string" } |
Responses
The /live/create
API provides a response in the following format:
200 Success
CreateLiveAlgorithmResponse Model - Response received when deploying a live algorithm. | |
---|---|
live | LiveAlgorithm object Live algorithm instance result from the QuantConnect Rest API. |
success | boolean Indicate if the API request was successful. |
errors | string Array List of errors with the API call. |
Example |
{ "live": { "projectId": 23456789, "deployId": "L-sdf86b7045bb83203e79d2aa6150b321", "status": "DeployError", "launched": "2021-11-26T15:18:27.693Z", "stopped": "2021-11-26T15:18:27.693Z", "brokerage": "Interactive", "subscription": "string", "error": "string", "success": true, "errors": [ "string" ] }, "success": true, "errors": [ "string" ] } |
LiveAlgorithm Model - Live algorithm instance result from the QuantConnect Rest API. | |
---|---|
projectId | integer Project Id for the live instance. |
deployId | string Unique live algorithm deployment identifier (similar to a backtest id). |
status | string Enum States of a live deployment. Options : ['DeployError', 'InQueue', 'Running', 'Stopped', 'Liquidated', 'Deleted', 'Completed', 'RuntimeError', 'Invalid', 'LoggingIn', 'Initializing', 'History'] |
launched | string($date-time) Datetime the algorithm was launched in UTC. |
stopped | string($date-time) Datetime the algorithm was stopped in UTC, null if its still running. |
brokerage | string Enum Brokerage. Options : ['Interactive', 'FXCM', 'Oanda', 'Tradier', 'PaperBrokerage', 'Alpaca', 'Bitfinex', 'Binance', 'Coinbase'] |
subscription | string Chart we're subscribed to. |
error | string Live algorithm error message from a crash or algorithm runtime error. |
success | boolean Indicate if the API request was successful. |
errors | string Array List of errors with the API call. |
Example |
{ "projectId": 23456789, "deployId": "L-sdf86b7045bb83203e79d2aa6150b321", "status": "DeployError", "launched": "2021-11-26T15:18:27.693Z", "stopped": "2021-11-26T15:18:27.693Z", "brokerage": "Interactive", "subscription": "string", "error": "string", "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 listing live algorithms 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()) # -------------------- ### Create Live Algorithm # Define placeholder IDs for compilation and node (replace with actual values) project_id = 12345678 compile_id = "compile_id..." node_id = "node_id..." # Prepare the data payload for creating a live algorithm with necessary details payload = { "versionId": "-1", # Use the latest version of the algorithm "projectId": project_id, # ID of the project to deploy as a live algorithm "compileId": compile_id, # Compilation ID for the algorithm code "nodeId": node_id, # Node ID where the algorithm will run "brokerage": { # Brokerage configuration for live trading "id": "QuantConnectBrokerage", # Brokerage identifier "user": "", # Brokerage username (replace with actual value) "password": "", # Brokerage password (replace with actual value) "environment": "live-paper", # Trading environment (live or paper) "account": "" # Brokerage account ID (replace with actual value) }, "dataProviders": { # Data provider configuration "QuantConnectBrokerage": { "id": "QuantConnectBrokerage" # Data provider identifier } }, "parameters": {}, # Optional algorithm parameters (empty in this example) "notification": {} # Optional notification settings (empty in this example) } # Send a POST request to the /live/create endpoint to deploy the algorithm response = post(f'{BASE_URL}/live/create', headers=get_headers(), json=data) # Parse the JSON response into python managable dict from the API result = response.json() # Extract the deploy ID from the response for future operations deploy_id = result['deployId'] # Check if the request was successful and print the result if result['success']: print("Live Algorithm Created Successfully:") print(result) ### Read Live Algorithm Statistics # Prepare data payload with project and deploy IDs to fetch statistics payload = { "projectId": project_id, # ID of the project "deployId": deploy_id # ID of the deployed live algorithm } # Send a POST request to the /live/read endpoint to get algorithm statistics response = post(f'{BASE_URL}/live/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 statistics if result['success']: print("Live Algorithm Statistics:") print(result) ### Liquidate Live Algorithm # Prepare data payload with project ID to liquidate the algorithm payload = { "projectId": project_id # ID of the project to liquidate } # Send a POST request to the /live/update/liquidate endpoint to liquidate response = post(f'{BASE_URL}/live/update/liquidate', 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("Live Algorithm Liquidated Successfully:") print(result) ### Stop Live Algorithm # Prepare data payload with project ID to stop the algorithm payload = { "projectId": project_id # ID of the project to stop } # Send a POST request to the /live/update/stop endpoint to stop the algorithm response = post(f'{BASE_URL}/live/update/stop', 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("Live Algorithm Stopped Successfully:") print(result) ### List Live Algorithms # Prepare data payload with filters for listing live algorithms payload = { "status": "Running", # Filter to show only running algorithms "start": 1717801200, # Start time (Unix timestamp) for the list range "end": 1743462000 # End time (Unix timestamp) for the list range } # Send a POST request to the /live/list endpoint to list algorithms response = post(f'{BASE_URL}/live/list', 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 list if result['success']: print("List of Live Algorithms:") print(result)