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 | |
|---|---|
| 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 Brokerage configuration for the live algorithm. |
| dataProviders | object Dictionary of data provider configurations to be used in the live algorithm. Provide at least one. The order in which you define the providers defines their order of precedence. |
| Example |
{
"versionId": "-1",
"projectId": 23456789,
"compileId": "5d1f2cba3a0ec7407c566614300502b5-173e0419674daf4144ce7c9931155ca8",
"nodeId": "LN-c54129e1b4f667613d3f34542b787771",
"brokerage": {
"QuantConnectBrokerageSettings": object,
"InteractiveBrokersBrokerageSettings": object,
"TradierBrokerageSettings": object,
"BitfinexSettings": object,
"CoinbaseBrokerageSettings": {
{
"id": "CoinbaseBrokerage",
"coinbase-api-name": "string",
"coinbase-api-private-key": "string"
},
},
"BinanceBrokerageSettings": {
{
"id": "BinanceBrokerage",
"binance-exchange-name": "Binance",
"binance-api-key": "string",
"binance-api-secret": "string",
"binance-use-testnet": "live"
},
},
"BinanceUSBrokerageSettings": {
{
"id": "BinanceBrokerage",
"binance-exchange-name": "BinanceUS",
"binanceus-api-key": "string",
"binanceus-api-secret": "string"
},
},
"BinanceUSDMFuturesBrokerageSettings": {
{
"id": "BinanceBrokerage",
"binance-exchange-name": "Binance-USDM-Futures",
"binance-api-key": "string",
"binance-api-secret": "string"
},
},
"BinanceCOINFuturesBrokerageSettings": {
{
"id": "BinanceBrokerage",
"binance-exchange-name": "Binance-COIN-Futures",
"binance-api-key": "string",
"binance-api-secret": "string"
},
},
"TradingTechnologiesBrokerageSettings": object,
"KrakenSettings": object,
"BybitBrokerageSettings": {
{
"id": "BybitBrokerage",
"bybit-api-key": "string",
"bybit-api-secret": "string",
"bybit-vip-level": "VIP0"
},
},
"OandaSettings": object,
"WolverineSettings": object,
"CharlesSchwabSettings": object,
"RBIBrokerageSettings": object,
"TerminalLinkSettings": object,
"TradeStationSettings": object,
"TastytradeSettings": object,
"AlpacaBrokerageSettings": object,
},
"dataProviders":
}
|
QuantConnectBrokerageSettings Model - Settings for using Paper Trading as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['QuantConnectBrokerage'] |
| holdings | BrokerageHolding Array List of holdings for the brokerage. |
| cash | CashAmount Array List of cash amount. |
| Example |
{
"id": "QuantConnectBrokerage",
"holdings": [
{
"symbolId": "BTCUSD 2XR",
"symbol": "BTCUSD",
"quantity": 0,
"averagePrice": 0
}
],
"cash": [
{
"amount": 0,
"currency": "string"
}
]
}
|
InteractiveBrokersBrokerageSettings Model - Settings for using Interactive Brokers as the brokerage or a data provider for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['InteractiveBrokersBrokerage'] |
| ib-user-name | string Your Interactive Brokers username. |
| ib-account | string Your Interactive Brokers account id. |
| ib-password | string Your Interactive Brokers password. |
| ib-weekly-restart-utc-time | string Weekly restart UTC time (hh:mm:ss). Each week on Sunday your algorithm restarts at this time and requires 2FA verification. This is required by Interactive Brokers. |
| ib-financial-advisors-group-filter | string Use this field to filter data by a specific financial advisor group within your Interactive Brokers account. Leave blank to include all groups. |
| Example |
{
"id": "InteractiveBrokersBrokerage",
"ib-user-name": "string",
"ib-account": "string",
"ib-password": "string",
"ib-weekly-restart-utc-time": "string",
"ib-financial-advisors-group-filter": "string"
}
|
TradierBrokerageSettings Model - Settings for using Tradier as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['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": "TradierBrokerage",
"tradier-account-id": "string",
"tradier-access-token": "string",
"tradier-environment": "live"
}
|
BitfinexSettings Model - Settings for using Bitfinex as the brokerage or a data provider for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['BitfinexBrokerage'] |
| bitfinex-api-key | string Your Bitfinex API key. |
| bitfinex-api-secret | string Your Bitfinex API secret. |
| Example |
{
"id": "BitfinexBrokerage",
"bitfinex-api-key": "string",
"bitfinex-api-secret": "string"
}
|
CoinbaseBrokerageAndDataProviderSettings Model | |
|---|---|
| id | string Enum Id of the module. Options : ['CoinbaseBrokerage'] |
| coinbase-api-name | string Your Coinbase Advanced Trade API name. |
| coinbase-api-private-key | string Your Coinbase Advanced Trade API private key. |
| Example |
{
"id": "CoinbaseBrokerage",
"coinbase-api-name": "string",
"coinbase-api-private-key": "string"
}
|
BinanceBrokerageAndDataProviderSettings Model | |
|---|---|
| id | string Enum Id of the module. Options : ['BinanceBrokerage'] |
| binance-exchange-name | string Enum Binance exchange name. Options : ['Binance'] |
| binance-api-key | string Your Binance API key. |
| binance-api-secret | string Your Binance API secret. |
| binance-use-testnet | string Enum Whether the testnet should be used. Options : ['live', 'paper'] |
| Example |
{
"id": "BinanceBrokerage",
"binance-exchange-name": "Binance",
"binance-api-key": "string",
"binance-api-secret": "string",
"binance-use-testnet": "live"
}
|
BinanceUSBrokerageAndDataProviderSettings Model | |
|---|---|
| id | string Enum Id of the module. Options : ['BinanceBrokerage'] |
| binance-exchange-name | string Enum Binance exchange name. Options : ['BinanceUS'] |
| binanceus-api-key | string Your Binance API key. |
| binanceus-api-secret | string Your Binance API secret. |
| Example |
{
"id": "BinanceBrokerage",
"binance-exchange-name": "BinanceUS",
"binanceus-api-key": "string",
"binanceus-api-secret": "string"
}
|
BinanceUSDMFuturesBrokerageAndDataProviderSettings Model | |
|---|---|
| id | string Enum Id of the module. Options : ['BinanceBrokerage'] |
| binance-exchange-name | string Enum Binance exchange name. Options : ['Binance-USDM-Futures'] |
| binance-api-key | string Your Binance API key. |
| binance-api-secret | string Your Binance API secret. |
| Example |
{
"id": "BinanceBrokerage",
"binance-exchange-name": "Binance-USDM-Futures",
"binance-api-key": "string",
"binance-api-secret": "string"
}
|
BinanceCOINFuturesBrokerageAndDataProviderSettings Model | |
|---|---|
| id | string Enum Id of the module. Options : ['BinanceBrokerage'] |
| binance-exchange-name | string Enum Binance exchange name. Options : ['Binance-COIN-Futures'] |
| binance-api-key | string Your Binance API key. |
| binance-api-secret | string Your Binance API secret. |
| Example |
{
"id": "BinanceBrokerage",
"binance-exchange-name": "Binance-COIN-Futures",
"binance-api-key": "string",
"binance-api-secret": "string"
}
|
TradingTechnologiesBrokerageSettings Model - Settings for using Trading Technologies as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['TradingTechnologiesBrokerage'] |
| tt-user-name | string Your Trading Technologies username. |
| tt-session-password | string Your Trading Technologies session password. |
| tt-account-name | string Your Trading Technologies account name. |
| tt-rest-app-key | string Your Trading Technologies REST app key. |
| tt-rest-app-secret | string Your Trading Technologies REST app secret. |
| tt-rest-environment | string Enum The REST environment to run in. Options : ['live', 'uat'] |
| tt-order-routing-sender-comp-id | string The order routing sender comp id to use. |
| cash | CashAmount Array List of cash amount. |
| Example |
{
"id": "TradingTechnologiesBrokerage",
"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"
}
]
}
|
KrakenSettings Model - Settings for using Kraken as the brokerage or a data provider for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['KrakenBrokerage'] |
| kraken-api-key | string Your Kraken API key. |
| kraken-api-secret | string Your Kraken API secret. |
| kraken-verification-tier | string Enum Your Kraken Verification Tier. Options : ['Starter', 'Intermediate', 'Pro'] |
| Example |
{
"id": "KrakenBrokerage",
"kraken-api-key": "string",
"kraken-api-secret": "string",
"kraken-verification-tier": "Starter"
}
|
BybitBrokerageAndDataProviderSettings Model | |
|---|---|
| id | string Enum Id of the module. Options : ['BybitBrokerage'] |
| bybit-api-key | string Your Bybit API key. |
| bybit-api-secret | string Your Bybit API secret. |
| bybit-vip-level | string Enum Your Bybit VIP Level. Options : ['VIP0', 'VIP1', 'VIP2', 'VIP3', 'VIP4', 'VIP5', 'SupremeVIP', 'Pro1', 'Pro2', 'Pro3', 'Pro4', 'Pro5'] |
| Example |
{
"id": "BybitBrokerage",
"bybit-api-key": "string",
"bybit-api-secret": "string",
"bybit-vip-level": "VIP0"
}
|
OandaSettings Model - Settings for using Oanda as the brokerage or a data provider for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['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": "OandaBrokerage",
"oanda-account-id": "string",
"oanda-access-token": "string",
"oanda-environment": "Practice"
}
|
WolverineSettings Model - Settings for using Wolverine Execution Services as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['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": "WolverineBrokerage",
"wolverine-on-behalf-of-comp-id": "string",
"wolverine-account": "string",
"cash": [
{
"amount": 0,
"currency": "string"
}
],
"holdings": [
{
"symbolId": "BTCUSD 2XR",
"symbol": "BTCUSD",
"quantity": 0,
"averagePrice": 0
}
]
}
|
CharlesSchwabSettings Model - Settings for using Charles Schwab as a data provider or the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['CharlesSchwabBrokerage'] |
| charles-schwab-account-number | string Your Charles Schwab account number. |
| Example |
{
"id": "CharlesSchwabBrokerage",
"charles-schwab-account-number": "string"
}
|
RBIBrokerageSettings Model - Settings for using RBI as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['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": "RBIBrokerage",
"rbi-on-behalf-of-comp-id": "string",
"rbi-account": "string",
"cash": [
{
"amount": 0,
"currency": "string"
}
],
"holdings": [
{
"symbolId": "BTCUSD 2XR",
"symbol": "BTCUSD",
"quantity": 0,
"averagePrice": 0
}
]
}
|
TerminalLinkSettings Model - Settings for using TerminalLink as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['TerminalLinkBrokerage'] |
| terminal-link-connection-type | string Enum Terminal Link Connection Type. Options : ['SAPI'] |
| terminal-link-server-auth-id | string Your unique user identifier (UUID). The UUID is a unique integer identifier that's assigned to each Bloomberg Anywhere user. If you don't know your UUID, contact Bloomberg. |
| terminal-link-environment | string Enum The environment to run in. Options : ['Production', 'Beta'] |
| terminal-link-server-host | string The public IP address of the SAPI AWS server. |
| terminal-link-server-port | integer The port where SAPI is listening. The default port is 8194. |
| terminal-link-emsx-broker | string The EMSX broker to use. |
| terminal-link-emsx-account | string The account to which LEAN should route orders. |
| terminal-link-openfigi-api-key | string The OpenFIGI API key to use for mapping options. |
| terminal-link-emsx-team | string The EMSX team to use. |
| cash | CashAmount Array List of cash amount. |
| holdings | BrokerageHolding Array List of holdings for the brokerage. |
| Example |
{
"id": "TerminalLinkBrokerage",
"terminal-link-connection-type": "SAPI",
"terminal-link-server-auth-id": "string",
"terminal-link-environment": "Production",
"terminal-link-server-host": "string",
"terminal-link-server-port": 0,
"terminal-link-emsx-broker": "string",
"terminal-link-emsx-account": "string",
"terminal-link-openfigi-api-key": "string",
"terminal-link-emsx-team": "string",
"cash": [
{
"amount": 0,
"currency": "string"
}
],
"holdings": [
{
"symbolId": "BTCUSD 2XR",
"symbol": "BTCUSD",
"quantity": 0,
"averagePrice": 0
}
]
}
|
TradeStationSettings Model - Settings for using TradeStation as the brokerage or a data provider for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['TradeStationBrokerage'] |
| trade-station-client-id | string Your TradeStation client Id. |
| trade-station-account-id | string The TradeStation account Id. |
| trade-station-refresh-token | string The TradeStation refresh token. |
| trade-station-environment | string Enum The environment to run the algorithm in. Options : ['live', 'paper'] |
| Example |
{
"id": "TradeStationBrokerage",
"trade-station-client-id": "string",
"trade-station-account-id": "string",
"trade-station-refresh-token": "string",
"trade-station-environment": "live"
}
|
TastytradeSettings Model - Settings for using Tastytrade as the brokerage or a data provider for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['TastytradeBrokerage'] |
| tastytrade-account-number | integer Your Tastytrade account number. |
| tastytrade-refresh-token | string The TradeStation refresh token. |
| Example |
{
"id": "TastytradeBrokerage",
"tastytrade-account-number": 0,
"tastytrade-refresh-token": "string"
}
|
AlpacaBrokerageSettings Model - Settings for using Alpaca as the brokerage for a live algorithm. | |
|---|---|
| id | string Enum Id of the module. Options : ['AlpacaBrokerage'] |
| alpaca-access-token | string Your Alpaca access token for authentication. |
| alpaca-environment | string Enum The environment to run the algorithm in. Options : ['live', 'paper'] |
| Example |
{
"id": "AlpacaBrokerage",
"alpaca-access-token": "string",
"alpaca-environment": "live"
}
|
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 you hold. |
| averagePrice | number Average price of your Holding in the currency the symbol is traded in. |
| Example |
{
"symbolId": "BTCUSD 2XR",
"symbol": "BTCUSD",
"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. | |
|---|---|
| responseCode | string Response code of the request. |
| source | string Source of the API call. |
| deployId | string Id of the live deployment. |
| versionId | integer Id of the LEAN version deployed. |
| projectId | integer Id of the project deployed. |
| 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 |
{
"responseCode": "string",
"source": "string",
"deployId": "L-141106d80de1da9a9f85ea07c06bf7b6",
"versionId": 17202,
"projectId": 24058693,
"live": {
"message": "string",
"deployId": "L-sdf86b7045bb83203e79d2aa6150b321",
"status": "DeployError",
"cloneId": 0,
"launched": "2021-11-26T15:18:27.693Z",
"stopped": "2021-11-26T15:18:27.693Z",
"description": "string",
"projectName": "string",
"brokerage": "string",
"securityTypes": "string",
"datacenter": "NY7",
"isPublicStreaming": true,
"success": true,
"public": true,
"files": [
{
"id": 0,
"projectId": 23456789,
"name": "string",
"content": "string",
"modified": "2021-11-26T15:18:27.693Z",
"open": true,
"isLibrary": true
}
],
"runtimeStatistics": {
"Equity": "$100.00",
"Fees": "-$100.00",
"Holdings": "$100.00",
"Net Profit": "$100.00",
"Probabilistic Sharpe Ratio": "50.00%",
"Return": "50.00%",
"Unrealized": "$100.00",
"Volume": "$100.00"
},
"charts": {
"name": "string"
}
},
"success": true,
"errors": [
"string"
]
}
|
LiveAlgorithm Model - Live algorithm instance result from the QuantConnect Rest API. | |
|---|---|
| message | string Error message. |
| deployId | string Unique live algorithm deployment identifier (similar to a backtest id). |
| status | string Enum State of the live deployment. Options : ['DeployError', 'InQueue', 'Running', 'Stopped', 'Liquidated', 'Deleted', 'Completed', 'RuntimeError', 'Invalid', 'LoggingIn', 'Initializing', 'History'] |
| cloneId | integer The snapshot project Id for cloning the live development's source code. |
| 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. |
| description | string Project description. |
| projectName | string Project name. |
| brokerage | string Brokerage. |
| securityTypes | string Security types detected in the algorithm. |
| datacenter | string Name of the datacenter where the algorithm is physically located. |
| isPublicStreaming | boolean Flag to indicate if public streaming is enabled. |
| success | boolean Response success. |
| public | boolean Flag to indicate if the algorithm is public. |
| files | ProjectFile Array Files present in the project that contains the algorithm. |
| runtimeStatistics | RuntimeStatistics object Runtime banner/updating statistics in the title banner of the live algorithm GUI. It can be empty if the algorithm is not running. |
| charts | ChartSummary object Contains the names of all charts. |
| Example |
{
"message": "string",
"deployId": "L-sdf86b7045bb83203e79d2aa6150b321",
"status": "DeployError",
"cloneId": 0,
"launched": "2021-11-26T15:18:27.693Z",
"stopped": "2021-11-26T15:18:27.693Z",
"description": "string",
"projectName": "string",
"brokerage": "string",
"securityTypes": "string",
"datacenter": "NY7",
"isPublicStreaming": true,
"success": true,
"public": true,
"files": [
{
"id": 0,
"projectId": 23456789,
"name": "string",
"content": "string",
"modified": "2021-11-26T15:18:27.693Z",
"open": true,
"isLibrary": true
}
],
"runtimeStatistics": {
"Equity": "$100.00",
"Fees": "-$100.00",
"Holdings": "$100.00",
"Net Profit": "$100.00",
"Probabilistic Sharpe Ratio": "50.00%",
"Return": "50.00%",
"Unrealized": "$100.00",
"Volume": "$100.00"
},
"charts": {
"name": "string"
}
}
|
ProjectFile Model - File for a project. | |
|---|---|
| id | integer ID of the project file. This can also be null. |
| projectId | integer ID of the project. |
| name | string Name of a project file. |
| content | string Contents of the project file. |
| modified | string($date-time) DateTime project file was modified. |
| open | boolean Indicates if the project file is open or not. |
| isLibrary | boolean Indicates if the project file is a library or not. It's always false in live/read and backtest/read. |
| Example |
{
"id": 0,
"projectId": 23456789,
"name": "string",
"content": "string",
"modified": "2021-11-26T15:18:27.693Z",
"open": true,
"isLibrary": true
}
|
RuntimeStatistics Model | |
|---|---|
| Equity | string Total portfolio value. |
| Fees | string Transaction fee. |
| Holdings | string Equity value of security holdings. |
| Net Profit | string Net profit. |
| Probabilistic Sharpe Ratio | string Probabilistic Sharpe Ratio. |
| Return | string Return. |
| Unrealized | string Unrealized profit/loss. |
| Volume | string Total transaction volume. |
| Example |
{
"Equity": "$100.00",
"Fees": "-$100.00",
"Holdings": "$100.00",
"Net Profit": "$100.00",
"Probabilistic Sharpe Ratio": "50.00%",
"Return": "50.00%",
"Unrealized": "$100.00",
"Volume": "$100.00"
}
|
ChartSummary Model - Contains the names of all charts | |
|---|---|
| name | string Name of the Chart. |
| Example |
{
"name": "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)