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
set_brokerage_model
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
set_brokerage_model
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 Type | US Equity | Crypto | Crypto Futures | Forex | CFD | Futures | Futures Options |
---|---|---|---|---|---|---|---|
Market | |||||||
Limit | |||||||
Limit if touched | |||||||
Stop market | |||||||
Stop limit | |||||||
Market on open | |||||||
Market on close | |||||||
Combo market | |||||||
Combo limit | |||||||
Combo leg limit | |||||||
Exercise Option |
Time In Force
The DefaultBrokerageModel
supports the following TimeInForce instructions:
Day
DAY
GoodTilCanceled
good_til_canceled
GoodTilDate
good_til_date
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 Class | Fee |
---|---|
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 Withdrawals
The QuantConnect Paper Trading brokerage supports deposits and withdrawals.
// Deposit 100 units of account currency and withdraw 1 ETH. Porfolio.CashBook.Add(AccountCurrency, 100); Porfolio.CashBook.Add("ETH", -1);
# Deposit 100 units of account currency and withdraw 1 ETH. self.porfolio.cash_book.add(self.account_currency, 100) self.porfolio.cash_book.add("ETH", -1)
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:
- 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.