Live Trading
Getting Started
Introduction
A live algorithm is an algorithm that trades in real-time with real market data. QuantConnect enables you to run your algorithms in live mode with real-time market data. Deploy your algorithms using QuantConnect because our infrastructure is battle-tested. We have successfully hosted more than 200,000 live algorithms and have had more than $22B in volume traded on our servers since 2015. The algorithms that our members create are run on co-located servers and the trading infrastructure is maintained at all times by our team of engineers. It's common for members to achieve 6-months of uptime with no interruptions.
Deploy Live Algorithms
The following video demonstrates how to deploy live paper trading algorithms:
You must have an available live trading node for each live trading algorithm you deploy.
Follow these steps to deploy a live paper trading algorithm:
- Open the project that you want to deploy.
- Click the Deploy Live icon.
- On the Deploy Live page, click the Brokerage field and then click from the drop-down menu.
- Click the Node field and then click the live trading node that you want to use from the drop-down menu.
- (Optional) In the Data Provider section, click and change the data provider or add additional providers.
- (Optional) Follow these steps to start the algorithm with existing cash holdings (see video):
- In the Algorithm Cash State section, click .
- Click .
- Enter the currency ticker (for example, USD or BTC) and a quantity.
- (Optional) Follow these steps to start the algorithm with existing position holdings (see video):
- In the Algorithm Holdings State section, click .
- Click .
- Enter the symbol ID, symbol, quantity, and average price.
- (Optional) Set up notifications.
- Configure the Automatically restart algorithm setting.
- Click .
By enabling automatic restarts, the algorithm will use best efforts to restart the algorithm if it fails due to a runtime error. This can help improve the algorithm's resilience to temporary outages such as a brokerage API disconnection.
The deployment process can take up to 5 minutes. When the algorithm deploys, the live results page displays. If you know your brokerage positions before you deployed, you can verify they have been loaded properly by checking your equity value in the runtime statistics, your cashbook holdings, and your position holdings.
To deploy a live algorithm with a different brokerage, see the Deploy Live Algorithms section of the brokerage integration documentation.
Stop Live Algorithms
The live trading results page has a
button to immediately stop your algorithm from executing. When you stop a live algorithm, your portfolio holdings are retained. Stop your algorithm if you want to perform any of the following actions:- Update your project's code files
- Upgrade the live trading node
- Update the settings you entered into the deployment wizard
- Place manual orders through your brokerage account instead of the web IDE
Furthermore, if you receive new securities in your portfolio because of a reverse merger, you also need to stop and redeploy the algorithm.
LEAN actively terminates live algorithms when it detects interference outside of the algorithm's control to avoid conflicting race conditions between the owner of the account and the algorithm, so avoid manipulating your brokerage account and placing manual orders on your brokerage account while your algorithm is running. If you need to adjust your brokerage account holdings, stop the algorithm, manually place your trades, and then redeploy the algorithm.
Follow these steps to stop your algorithm:
- Open your algorithm's live results page.
- Click .
- Click again.
Liquidate Live Algorithms
The live results page has a
button that acts as a "kill switch" to sell all of your portfolio holdings. If your algorithm has a bug in it that caused it to purchase a lot of securities that you didn't want, this button let's you easily liquidate your portfolio instead of placing many manual trades. When you click the button, if the market is open for an asset you hold, the algorithm liquidates it with market orders. If the market is not open, the algorithm places market on open orders. After the algorithm submits the liquidation orders, it stops executing.Follow these steps to liquidate your positions:
- Open your algorithm's live results page.
- Click .
- Click again.
On-Premise Live Algorithms
For information about on-premise live trading with Local Platform, see Getting Started.
Get Deployment Id
To get the live deployment Id, open the log file and enter "Launching analysis for" into the search bar. The log file shows all of the live deployment Ids for the project. An example deployment Id is L-6bf91128391608d0728ff90b81bfca41. If you have deployed the project multiple times, use the most recent deployment Id in the log file.
Automate Deployments
If you have multiple deployments, use a notebook in the Research Enviroment to programmatically deploy, stop or liquidate algorithms.