Create Live Algorithms



This page explains how to use the QuantConnect API to deploy live algorithms that connect to the Tradier brokerage.

Compile Projects

To compile a project, call the CreateCompile method with the project ID.

#load "../Initialize.csx"
#load "../QuantConnect.csx"

using QuantConnect;
using QuantConnect.Api;

var compile = api.CreateCompile(projectID);
compile = api.CreateCompile(project_id)

The CreateCompile method returns a Compile object, which have the following attributes:

Select a Node

You need to select a node to deploy a live algorithm. To view the live trading nodes in your organization, call the ReadNodes method with your organization ID.

var nodes = api.ReadNodes(organizationId);
nodes = api.ReadNodes(organization_id)

The ReadNodes method returns a NodeList object, which have the following attributes:

To select the first available live trading node in your organization, run:

var nodeId = nodes.LiveNodes.Where(x => x.Busy == false).FirstOrDefault().Id;
node_id = [x for x in nodes.LiveNodes if not x.Busy][0].Id

Define Algorithm Settings

To use the Tradier brokerage, create a TradierLiveAlgorithmSettings object and then set its Environment property.

var liveSettings = new TradierLiveAlgorithmSettings(accessToken: "",
                                                    dateIssued: "",
                                                    refreshToken: "",
                                                    account: "");
liveSettings.Environment = BrokerageEnvironment.Live;
live_settings = TradierLiveAlgorithmSettings(accessToken="",
live_settings.Environment = BrokerageEnvironment.Live

To get your account ID and token, see the Create an Account section in the Account Types documentation. Your account details are not saved on QuantConnect.

The BrokerageEnvironment enumeration has the following members:

Deploy Algorithms

You need to compile the project, select a node, and define the algorithm settings before you can deploy live algorithms.

To deploy live algorithms, call the CreateLiveAlgorithm method.

var liveAlgorithm = api.CreateLiveAlgorithm(projectId, compile.CompileId, nodeId, liveSettings);
new_live_algorithm = api.CreateLiveAlgorithm(project_id, compile.CompileId, node_id, live_settings)

By default, LEAN uses the latest master branch. If the latest master branch causes issues with your live deployment, pass a LEAN version to the CreateLiveAlgorithm method.

var liveAlgorithm = api.CreateLiveAlgorithm(projectId, compile.CompileId, nodeId, liveSettings, versionId);
new_live_algorithm = api.CreateLiveAlgorithm(project_id, compile.CompileId, node_id, live_settings, version_id)

The CreateLiveAlgorithm method returns a LiveAlgorithm object, which have the following attributes:

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: