Brokerages

QuantConnect Paper Trading

Introduction

QuantConnect enables you to run your algorithms in live mode with real-time market data. We have successfully hosted more than 200,000 live algorithms and have had more than $22B in volume traded on our servers since 2015.

QuantConnect Paper Trading lets you run live, real-time data into your algorithm but execute trades using fictional capital. Instead of your orders being routed to an exchange when you're paper trading, your order fills are simulated. Use paper trading to test your algorithm without risking real money and to ensure your backtest wasn't overfit before deploying with real money. You can use the paper trading brokerage without needing to sign up for a real brokerage account. If you don't set a brokerage model in your algorithm with the SetBrokerageModel method, the paper trading brokerage uses the DefaultBrokerageModel to simulate trades.

To view the implementation of the QuantConnect Paper Trading brokerage, see PaperBrokerage.cs in the LEAN GitHub repository. To view the implementation of the backtesting brokerage, see BacktestingBrokerage.cs in the LEAN GitHub repository.

Account Types

The QuantConnect Paper Trading brokerage supports cash and margin accounts. To set the account type in an algorithm, see the paper trading brokerage model documentation.

If you pass a different BrokerageName to the SetBrokerageModel method, the new brokerage model defines the account types that are available.

Asset Classes

The QuantConnect Paper Trading brokerage supports the following asset classes:

If you set the brokerage model to a model other than the DefaultBrokerageModel, the new brokerage model defines the asset classes you can trade.

Data Feeds

We can only provide paper trading on the assets for which we have a live data provider.

Orders

The following sections describe how the DefaultBrokerageModel handles orders. If you set the brokerage model to a different model, the new brokerage model defines how orders are handled.

Order Types

The following table describes the available order types for each asset class that the DefaultBrokerageModel supports:

Order TypeUS EquityCryptoCrypto FuturesForexCFDFuturesFutures Options
MarketOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen checkgreen check
LimitOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen checkgreen check
LimitIfTouchedOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen checkgreen check
StopMarketOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen checkgreen check
StopLimitOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen checkgreen check
MarketOnOpenOrdergreen checkgreen checkgreen checkgreen check
MarketOnCloseOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
ComboMarketOrdergreen check
ComboLimitOrdergreen check
ComboLegLimitOrdergreen check
ExerciseOptiongreen check

Time In Force

The DefaultBrokerageModel supports the following TimeInForce instructions:

  • Day
  • GoodTilCanceled
  • GoodTilDate

Updates

The DefaultBrokerageModel supports order updates.

Handling Splits

If you're using raw data normalization and you have active orders with a limit, stop, or trigger price in the market for a US Equity when a stock split occurs, the following properties of your orders automatically adjust to reflect the stock split:

  • Quantity
  • Limit price
  • Stop price
  • Trigger price

Fees

The following table shows the fees that the DefaultBrokerageModel charges for each of the supported asset classes:

Asset ClassFee
Equities$0.005/share with a $1 minimum fee
Crypto$0
Forex$0
CFDs$0
Futures$1.85/contract
Future Options$1.85/contract

There is no fee to exercise Option contracts.

If you set the brokerage model to a model other than the DefaultBrokerageModel, the new brokerage model defines the order fees.

To see the fee models that the DefaultBrokerageModel uses, see Fees.

Margin

We model buying power and margin calls to ensure your algorithm stays within the margin requirements. If you set the brokerage model to a different model, the new brokerage model defines how margin is modeled. If you have more than $25,000 in your brokerage account, you can use the PatternDayTradingMarginModel to make use of the 4x intraday leverage and 2x overnight leverage available on most brokerages from the PDT rule.

Slippage

Orders through the DefaultBrokerageModel do not experience slippage in backtests or paper trading. For more information about the slippage model the DefaultBrokerageModel uses, see Slippage.

Fills

The DefaultBrokerageModel fills market orders immediately and completely. When available, bid and ask spread will be used for the fill prices.

To view how we model realistic order fills, see Fills.

Settlements

If you trade with a margin account, trades settle immediately

To view how we model settlement for paper trades, see Settlement.

Brokerage Models

The QuantConnect Paper Trading brokerage uses the DefaultBrokerageModel by default, but you can use any of the brokerage models.

Deposits and Withdraws

The QuantConnect Paper Trading brokerage supports deposits and withdraws.

Porfolio.CashBook.Add(AccountCurrency, 100);
Porfolio.CashBook.Add("ETH", -1);
self.Porfolio.CashBook.Add(self.AccountCurrency, 100)
self.Porfolio.CashBook.Add("ETH", -1)

Demo Algorithm

The following algorithm demonstrates the functionality of the DefaultBrokerageModel:

Deploy Live 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:

  1. Open the project that you want to deploy.
  2. Click the Deploy live icon Deploy Live icon.
  3. On the Deploy Live page, click the Brokerage field and then click Paper Trading from the drop-down menu.
  4. Click the Node field and then click the live trading node that you want to use from the drop-down menu.
  5. (Optional) In the Data Provider section, click Show and change the data provider or add additional providers.
  6. (Optional) Follow these steps to start the algorithm with existing cash holdings (see video):
    1. In the Algorithm Cash State section, click Show.
    2. Click Add Currency.
    3. Enter the currency ticker (for example, USD or BTC) and a quantity.
  7. (Optional) Follow these steps to start the algorithm with existing position holdings (see video):
    1. In the Algorithm Holdings State section, click Show.
    2. Click Add Holding.
    3. Enter the symbol ID, symbol, quantity, and average price.
  8. (Optional) Set up notifications.
  9. Configure the Automatically restart algorithm setting.
  10. 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.

  11. Click Deploy.

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.

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: