Create Live Algorithms
QuantConnect Paper Trading
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 QuantConnect Paper Trading brokerage, create a DefaultLiveAlgorithmSettings
object.
var liveSettings = new DefaultLiveAlgorithmSettings(user: "", password: "", environment: BrokerageEnvironment.Paper, account: "");
live_settings = DefaultLiveAlgorithmSettings(user="", password="", environment=BrokerageEnvironment.Paper, account="")
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: