Contents
Brokerages
FTX
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 $15B in volume traded on our servers since 2015. Brokerages supply a connection to the exchanges so that you can automate orders using LEAN. You can use multiple data feeds in live trading algorithms.
FTX was founded by Sam Bankman-Fried in 2017 with the goal to "develop a platform robust enough for professional trading firms and intuitive enough for first-time users". FTX provides access to trading Crypto, tokenized Equities, and Bitcoin Options for clients outside of the restricted locations with no minimum deposit. FTX also provides a platform-native FTT token, an NFT marketplace, and margin borrowing services.
Account Types
FTX and FTX US support cash and margin accounts.
// FTX SetBrokerageModel(BrokerageName.FTX, AccountType.Cash); SetBrokerageModel(BrokerageName.FTX, AccountType.Margin); // FTX US SetBrokerageModel(BrokerageName.FTXUS, AccountType.Cash); SetBrokerageModel(BrokerageName.FTXUS, AccountType.Margin);
# FTX self.SetBrokerageModel(BrokerageName.FTX, AccountType.Cash) self.SetBrokerageModel(BrokerageName.FTX, AccountType.Margin) # FTX US self.SetBrokerageModel(BrokerageName.FTXUS, AccountType.Cash) self.SetBrokerageModel(BrokerageName.FTXUS, AccountType.Margin)
Create an Account
To create an FTX account, follow the Registration Guide on the FTX website.
To create an FTX US account, follow the New Customer Account Set Up page on the FTX US website.
You will need API credentials to deploy live algorithms with your brokerage account. After you open your account, create API credentials on your Profile page and store them somewhere safe.
Paper Trading
The FTX and FTX US brokerages don't support paper trading, but you can follow these steps to simulate it:
- In the
Initialize
method of your algorithm, add one of the precedingSetBrokerageModel
method calls. - Deploy your algorithm with the QuantConnect Paper Trading brokerage.
Sub-Accounts
Our FTX and FTX US integrations don't support trading with sub-accounts. You must use your main account.
Asset Classes
Our FTX and FTX US integrations support trading Crypto.
// FTX AddCrypto("BTCUSDT", Resolution.Minute, Market.FTX); // FTX US AddCrypto("BTCUSDT", Resolution.Minute, Market.FTXUS);
# FTX self.AddCrypto("BTCUSDT", Resolution.Minute, Market.FTX) # FTX US self.AddCrypto("BTCUSDT", Resolution.Minute, Market.FTXUS)
If you call the SetBrokerageModel
method with the correct BrokerageName
, then you don't need to pass a Market
argument to the AddCrypto
method because the brokerage model automatically selects the correct market.
Assets Available
Refer to the dataset listing of the FTX market you are trading to see the assets available. The following table shows the dataset listing of each FTX market:
Market | Dataset Listing |
---|---|
FTX | FTX Crypto Price Data |
FTXUS | FTXUS Crypto Price Data |
Orders
We model the FTX and FTX US APIs by supporting several order types, supporting order properties, and not supporting order updates. When you deploy live algorithms, you can place manual orders through the IDE.
Order Types
FTX and FTX US support the following order types:
MarketOrder
LimitOrder
StopMarketOrder
StopLimitOrder
MarketOnOpenOrder
MarketOnCloseOrder
LimitIfTouchedOrder
MarketOrder(_symbol, quantity); LimitOrder(_symbol, quantity, limitPrice); StopMarketOrder(_symbol, quantity, stopPrice); StopLimitOrder(_symbol, quantity, stopPrice, limitPrice); MarketOnOpenOrder(_symbol, quantity); MarketOnCloseOrder(_symbol, quantity); LimitIfTouchedOrder(_symbol, quantity, triggerPrice, limitPrice);
self.MarketOrder(self.symbol, quantity) self.LimitOrder(self.symbol, quantity, limit_price) self.StopMarketOrder(self.symbol, quantity, stop_price) self.StopLimitOrder(self.symbol, quantity, stop_price, limit_price) self.MarketOnOpenOrder(self.symbol, quantity) self.MarketOnCloseOrder(self.symbol, quantity) self.LimitIfTouchedOrder(self.symbol, quantity, trigger_price, limit_price)
If you submit a StopMarketOrder
or StopLimitOrder
, the stop price must be greater than or equal to the current ask price when buying and less than or equal to the current bid price when selling.
StopMarketOrder(_symbol, 1, currentAskPrice + 1); StopLimitOrder(_symbol, -1, currentBidPrice - 1, limitPrice);
self.StopMarketOrder(self.symbol, 1, current_ask_price + 1) self.StopLimitOrder(self.symbol, -1, current_bid_price - 1, limit_price)
Order Properties
We model custom order properties from the FTX and FTX US APIs. The following table describes the members of the FTXOrderProperties
object that you can set to customize order execution:
Property | Description |
---|---|
TimeInForce |
A TimeInForce instruction to apply to the order. The following instructions are supported:
|
ReduceOnly | A flag to signal that the order should only be filled if it reduces your position size. |
PostOnly | A flag to signal that the order must only add liquidity to the order book and not take liquidity from the order book. If part of the order results in taking liquidity rather than providing liquidity, the order is rejected without any part of it being filled. |
public override void Initialize() { // Set the default order properties DefaultOrderProperties = new FTXOrderProperties { TimeInForce = TimeInForce.GoodTilCanceled, ReduceOnly = false, PostOnly = false }; } public override void OnData(Slice slice) { // Use default order order properties LimitOrder(_symbol, quantity, limitPrice); // Override the default order properties LimitOrder(_symbol, quantity, limitPrice, orderProperties: new FTXOrderProperties { TimeInForce = TimeInForce.Day, ReduceOnly = true, PostOnly = false }); LimitOrder(_symbol, quantity, limitPrice, orderProperties: new FTXOrderProperties { TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)), ReduceOnly = false, PostOnly = true }); }
def Initialize(self) -> None: # Set the default order properties self.DefaultOrderProperties = FTXOrderProperties() self.DefaultOrderProperties.TimeInForce = TimeInForce.GoodTilCanceled self.DefaultOrderProperties.ReduceOnly = False self.DefaultOrderProperties.PostOnly = False def OnData(self, slice: Slice) -> None: # Use default order order properties self.LimitOrder(self.symbol, quantity, limit_price) # Override the default order properties order_properties = FTXOrderProperties() order_properties.TimeInForce = TimeInForce.Day order_properties.ReduceOnly = True order_properties.PostOnly = False self.LimitOrder(self.symbol, quantity, limit_price, orderProperties=order_properties) order_properties.TimeInForce = TimeInForce.GoodTilDate(datetime(year, month, day)) order_properties.ReduceOnly = False order_properties.PostOnly = True self.LimitOrder(self.symbol, quantity, limit_price, orderProperties=order_properties)
Updates
We model the FTX and FTX US APIs by not supporting order updates, but you can cancel an existing order and then create a new order with the desired arguments.
var ticket = LimitOrder(_symbol, quantity, limitPrice); ticket.Cancel(); ticket = LimitOrder(_symbol, newQuantity, newLimitPrice);
ticket = self.LimitOrder(self.symbol, quantity, limit_price) ticket.Cancel() ticket = self.LimitOrder(self.symbol, new_quantity, new_limit_price)
Fees
We model the order fees of FTX and FTX US at the lowest tier in their respective tiered fee structures. The following table shows the fees of each platform:
Platform | Maker Fee (%) | Taker Fee (%) |
---|---|---|
FTX | 0.02 | 0.07 |
FTX US | 0.1 | 0.4 |
If you add liquidity to the order book by placing a limit order that doesn't cross the spread, you pay maker fees. If you remove liquidity from the order book by placing an order that crosses the spread, you pay taker fees. You pay the fees in the base currency for maker orders and the quote currency for taker orders. FTX and FTXUS adjust your fees based on your 30-day trading volume and FTT balance, but we don't currently model these metrics to adjust fees. To check the latest fees at all the fee tiers, see the Fees page on the FTX.com or FTX.us website.
Margin
We model buying power and margin calls to ensure your algorithm stays within the margin requirements.
Buying Power
FTX and FTX US allow up to 3x leverage for margin accounts.
Margin Calls
Regulation T margin rules apply. When the amount of margin remaining in your portfolio drops below 5% of the total portfolio value, you receive a warning. When the amount of margin remaining in your portfolio drops to zero or goes negative, the portfolio sorts the generated margin call orders by their unrealized profit and executes each order synchronously until your portfolio is within the margin requirements.
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 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 Account Exchange field and then click the FTX exchange you are using from the drop-down menu.
- Click the Account Tier field and then click your FTX account tier from the drop-down menu.
- Enter your FTX API secret and key.
- Click the Node field and then click the live trading node that you want to use from the drop-down menu.
- (Optional) Set up notifications.
- Configure the Automatically restart algorithm setting.
- Click .
Gather your account tier from your Profile page on the FTX.com or FTX.us website. If your account tier changes after you deploy the algorithm, stop the algorithm and then redeploy it to correct the account tier.
Gather your API credentials from your Profile page on the FTX.com or FTX.us website. Your account details are not saved on QuantConnect.
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.