Live trading

Cloud live trading

Introduction

The Lean CLI supports starting live trading for a cloud project on any of the brokerages supported in the cloud. We recommend live trading your projects in our cloud because we provide a battle-tested, colocated infrastructure racked in Equinix, maintained by our engineers to ensure the best possible stability and uptime.

Follow these steps to start live trading a project in the cloud:

  1. Log in to the CLI if you haven't done so already.
  2. Open a terminal in the directory you ran lean init in.
  3. Run lean cloud live "My Project" --push --open to push ./My Project to the cloud, start a live deployment wizard, and open the results in the browser once the deployment starts.
    $ lean cloud live "My Project" --push --open
    [1/1] Pushing 'My Project'
    Successfully updated cloud file 'My Project/main.py'
    Started compiling project 'My Project'
    Successfully compiled project 'My Project'
    Select a brokerage:
    1) Paper Trading
    2) Interactive Brokers
    3) Tradier
    4) OANDA
    5) Bitfinex
    6) Coinbase Pro
    7) Binance
    Enter an option:
  4. Enter the number of the brokerage to use.
    $ lean cloud live "My Project" --push --open
    Select a brokerage:
    1) Paper Trading
    2) Interactive Brokers
    3) Tradier
    4) OANDA
    5) Bitfinex
    6) Coinbase Pro
    7) Binance
    Enter an option: 1
  5. Configure your brokerage settings. Depending on which brokerage you select in step 4 you get different prompts to configure your credentials. See the table of contents on the right for quick links to exact instructions for each brokerage.
  6. Select the live node that you want to use. If you only have one non-busy live node it is selected automatically and this step is skipped.
    $ lean cloud live "My Project" --push --open
    Select a node:
    1) L-MICRO node 89c90172 - 1 CPU @ 2.4GHz, 0.5GB Ram
    2) L-MICRO node 85a52135 - 1 CPU @ 2.4GHz, 0.5GB Ram
    Enter an option: 1
  7. Configure your notification settings. You can configure any combination of email notifications, webhook notifications, and SMS notifications for order events and emitted insights.
    $ lean cloud live "My Project" --push --open
    Do you want to send notifications on order events? [y/N]: y
    Do you want to send notifications on insights? [y/N]: y
    Email notifications: None
    Webhook notifications: None
    SMS notifications: None
    Select a notification method:
    1) Email
    2) Webhook
    3) SMS
    Enter an option: 1
    Email address: john.doe@example.com
    Subject: Algorithm notification
    Email notifications: john.doe@example.com
    Webhook notifications: None
    SMS notifications: None
    Do you want to add another notification method? [y/N]: n
  8. Enable or disable automatic algorithm restarting. This feature attempts to restart your algorithm if it fails due to a runtime error, like a brokerage API disconnection.
    $ lean cloud live "My Project" --push --open
    Do you want to enable automatic algorithm restarting? [Y/n]: y
  9. Verify the configured settings and confirm them to start the live deployment in the cloud.
    $ lean cloud live "My Project" --push --open
    Brokerage: Paper Trading
    Project id: 1234567
    Environment: Paper
    Server name: L-MICRO node 89c90172
    Server type: L-MICRO
    Data provider: QuantConnect
    LEAN version: 11157
    Order event notifications: Yes
    Insight notifications: Yes
    Email notifications: john.doe@example.com
    Webhook notifications: None
    SMS notifications: None
    Automatic algorithm restarting: Yes
    Are you sure you want to start live trading for project 'My Project'? [y/N]: y
  10. Inspect the result in the browser, which opens automatically after the deployment starts.

Follow these steps to see the live status of a project:

  1. Log in to the CLI if you haven't done so already.
  2. Open a terminal in the directory you ran lean init in.
  3. Run lean cloud status "My Project" to show the status of the cloud project named "My Project".
    $ lean cloud status "My Project"
    Project id: 1234567
    Project name: My Project
    Project url: https://www.quantconnect.com/project/1234567
    Live status: Running
    Live id: L-1234567a8901d234e5e678ddd9b0123c
    Live url: https://www.quantconnect.com/project/1234567/live
    Brokerage: Paper Trading
    Launched: 2021-06-09 15:10:12 UTC

Paper trading

The paper trading brokerage does not have any brokerage-specific settings. After selecting "Paper Trading" in step 4 of the tutorial in the introduction, the CLI automatically skips to step 6.

Interactive Brokers

Follow these steps after selecting Interactive Brokers in step 4 of the tutorial in the introduction:

  1. Log in to Interactive Brokers in your browser and go to User Settings > Security > Secure Login System.
  2. Deselect all options or only select "IB Key Security via IBKR Mobile" on the Secure Login System page.
  3. Go back to the terminal and enter your Interactive Brokers username, account id, and password.
    $ lean cloud live "My Project" --push --open
    Username: trader777
    Account id: DU1234567
    Account password: ****************
  4. Enter whether you want to use the price data feed from Interactive Brokers instead of the one from QuantConnect. Enabling this feature requires you to have active Interactive Brokers market data subscriptions for all data required by your algorithm.
    $ lean cloud live "My Project" --push --open
    Do you want to use the Interactive Brokers price data feed instead of the QuantConnect price data feed? [y/N]: y
  5. Continue with step 6 of the tutorial in the introduction.

Tradier

Follow these steps after selecting Tradier in step 4 of the tutorial in the introduction:

  1. Enter your Tradier account id and access token. You can find these credentials on your Settings/API Access page.
    $ lean cloud live "My Project" --push --open
    Account id: VA000001
    Access token: ****************
  2. Enter which environment you want to use. You can either choose demo or real.
    $ lean cloud live "My Project" --push --open
    Environment (demo, real): demo
  3. Continue with step 6 of the tutorial in the introduction.

OANDA

Follow these steps after selecting OANDA in step 4 of the tutorial in the introduction:

  1. Enter your OANDA account number. You can find this number on your Account Statement page.
    $ lean cloud live "My Project" --push --open
    Account id: 001-011-5838423-001
  2. Enter your OANDA API token. You can generate a token on the Manage API Access page.
    $ lean cloud live "My Project" --push --open
    API token: ****************
  3. Enter which environment you want to use. You can either choose demo for fxTrade or real for fxTrade Practice.
    $ lean cloud live "My Project" --push --open
    Environment (demo, real): demo
  4. Continue with step 6 of the tutorial in the introduction.

Bitfinex

Follow these steps after selecting Bitfinex in step 4 of the tutorial in the introduction:

  1. Enter your API key id and secret. You can generate new API credentials on the API Management page.
    $ lean cloud live "My Project" --push --open
    API key: bbbMsqbxjytVM9cGvnLpKguz9rZf2T5qACxaVx7E8Mm
    Secret key: *******************************************
  2. Continue with step 6 of the tutorial in the introduction.

Coinbase Pro

Follow these steps after selecting Coinbase Pro in step 4 of the tutorial in the introduction:

  1. Enter your API key, API secret, and passphrase. You can generate new API credentials on the API settings page.
    $ lean cloud live "My Project" --push --open
    API key: 6d3ef5ca2d2fa52e4ee55624b0471261
    API secret: ****************************************************************************************
    Passphrase: ****************
    
  2. Continue with step 6 of the tutorial in the introduction.

Binance

Follow these steps after selecting Binance in step 4 of the tutorial in the introduction:

  1. Enter your Binance API key and secret. You can generate new API credentials on your API Settings Management page if you want to trade use the production environment, or on Binance Testnet if you want to use the demo environment.
    $ lean cloud live "My Project" --push --open
    API key: wL1waeOC7VD447skCFeiat9pP3r1uKXfYomGg43uyCOgzl8xsI9SZsX97AXP4zWv
    API secret: ****************************************************************
  2. Enter which environment you want to use. You can either choose demo for the testnet or real for the production environment.
    $ lean cloud live "My Project" --push --open
    Environment (demo, real): demo
  3. Continue with step 6 of the tutorial in the introduction.

You can also see our Videos. You can also get in touch with us via Chat.

Did you find this page helpful?

Contribute to the documentation: