Live Trading

Getting Started

Introduction

A live algorithm is an algorithm that trades in real-time with real market data. Local Platform provides multiple deployment targets to enable you to run live algorithms on-premise and in QuantConnect Cloud. If you run live algorithms on-premise, you are prone to downtime from power outages, computer crashes, and natural disasters. If you don't want to be at risk to these, run your algorithms on QuantConnect Cloud

Deploy Live Algorithms

Follow these steps to deploy a live trading algorithm with the Interactive Brokers (IB) brokerage:

  1. Open the project that you want to deploy.
  2. Click the Local deploy live icon / Deploy live icon Deploy Live icon.
  3. On the Deploy Live page, click the Brokerage field and then click Interactive Brokers from the drop-down menu.
  4. Enter your IB user name, ID, and password.
  5. If you use IB data provider and trade with a paper trading account, you need to share the market data subscription with your paper trading account. For instructions on sharing market data subscription, see Account Types.

    Your account details are not saved on QuantConnect.

  6. In the Weekly Restart UTC field, enter the Coordinated Universal Time (UTC) time of when you want to receive notifications on Sundays to re-authenticate your account connection.
  7. For example, 4 PM UTC is equivalent to 11 AM Eastern Standard Time, 12 PM Eastern Daylight Time, 8 AM Pacific Standard Time, and 9 AM Pacific Daylight Time. To convert from UTC to a different time zone, see the UTC Time Zone Converter on the UTC Time website.

    If your IB account has 2FA enabled, you receive a notification on your IB Key device every Sunday to re-authenticate the connection between IB and your live algorithm. If you don't re-authenticate before the timeout period, your algorithm quits executing.

  8. Click the Node field and then click the live trading node that you want to use from the drop-down menu.
  9. (Optional) If you are deploying to QuantConnect Cloud, set up notifications.
  10. Configure the Automatically restart algorithm setting.
  11. 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.

  12. Click Deploy.
  13. If your IB account has 2FA enabled, tap the notification on your IB Key device and then enter your pin.

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 Stop 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
  • Update the settings you entered into the deployment command
  • Place manual orders through your brokerage account

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:

  1. Open your algorithm's live results page.
  2. Click Stop.
  3. Click Stop again.

Liquidate Live Algorithms

The live results page has a Liquidate 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 Liquidate 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:

  1. Open your algorithm's live results page.
  2. Click Liquidate.
  3. Click Liquidate again.

Data Providers

Local Platform currently supports several brokerage data providers. To use other data providers, contact us.

Result Files

When you deploy a live algorithm, the live results page automatically displays. To view the results in their raw form, open the <organizationWorkspace> / <projectName> / live / <timeStamp> directory. The following table describes the initial contents of the live result directories:

File/DirectoryDescription
code /A directory containing a copy of the files that were in the project when you deployed the algorithm.
L-<deploymentId>.json
Ex: L-3712451018.json
A file containing the following data:
L-<deploymentId>-<date>_minute.json
Ex: L-3712451018-2023-06-22_minute.json
A file similiar to the L-<deploymentId>.json file, but the values of the chart data are only sampled every 10 minutes.
L-<deploymentId>-<date>_10minute.json
Ex: L-3712451018-2023-06-22_10minute.json
A file similiar to the L-<deploymentId>.json file, but the values of the chart data are only sampled every 10 minutes.
L-<deploymentId>-<date>_second_Strategy%20Equity.json
Ex: L-3712451018-2023-06-22-19_second_Strategy%20Equity.json
A file containing the algorithm holdings, chart, and orders. The values of the chart data are sampled every few seconds.
L-<deploymentId>-log.txt
Ex: L-3712451018
A file containing all of the live trading logs.
log.txtA file containing the syslog.
configA file containing some configuration settings, including the deployment Id, brokerage name, and Docker container name.

Algorithm Lab Live Algorithms

For information about live trading in the cloud through the Algorithm Lab, see Getting Started.

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: