I got a notice saying “Unable to compute order quantity of DASHUSDT. Reason: The cash model does not allow shorting. Returning null.” when I live trade a pair trading strategy using QuantConnect and Binance margin sub-account.
Here is my code for the open
SetHoldings(Config.Symbol1, -0.3m); // Short symbol1 with 0.3 * portfolio value
SetHoldings(Config.Symbol2, 0.3m); // Long symbol2 with 0.3 * portfolio value
What should I do to short a crypto spot in Quantconnect?
Mia Alissi
To short a cryptocurrency in QuantConnect, you need to set the brokerage model to a margin account and override the default buying power model. Here is how you can do it:
Then, you can use
SetHoldings
to short the crypto:Please note that it's recommended to create orders manually for cryptocurrencies instead of using the
SetHoldings
method. TheSetHoldings
method isn't consistent when coins are added to the cashbook^1^.The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Rex Fan
in the code
What does 3.3 mean?
Mia Alissi
The
3.3
inSecurityMarginModel(3.3)
represents the leverage you want to use for your trading. Leverage is a concept in trading where you borrow funds to increase your position size, thus potentially increasing your return on investment.In this case, a leverage of
3.3
means that for every dollar of your own money, you can trade up to $3.3. This leverage should be set according to the maximum you want and below or equal to the maximum your broker authorizes^1^.Please note that while higher leverage can increase potential returns, it also increases potential losses. Therefore, it's important to use leverage judiciously.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Rex Fan
Thanks for the response,
I tried the below code to short crypto, e.g. ALGO, with a Binance SubMarginAccount.
And, got the below error through log.
Anything else I can try to short a crypto successfully?
Mia Alissi
The error message you received indicates that the Binance API does not support the operation you're trying to perform with a Portfolio Margin account. According to the Binance API documentation, certain types of accounts may not have access to all API functions.
Unfortunately, as of the current state of the QuantConnect platform, the Binance integration does not support trading with sub-accounts^1^. You must use your main account for trading.
If you want to short cryptocurrencies, you might want to consider using a different brokerage that supports this operation. For example, the Bitfinex brokerage model allows for crypto margin trading^2^^4^.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Rex Fan
I tried two possible solution, Neither of them works.
1 to use main account instead of sub account
2 to recreate API with full permission
Since short is necessary for pair trading strategy, can I know how to, the sample code, short perpetual futures, e.g. ALGOUSDT?
Mia Alissi
To short perpetual futures in QuantConnect, you can use the
SetHoldings
method similar to how you would short a spot cryptocurrency. However, you need to add the futures contract to your algorithm and set the appropriate brokerage model. Here is a sample code snippet in Python:Please note that the symbol "ALGOUSDT" in the
AddFutureContract
method should be replaced with the actual symbol of the perpetual futures contract you want to trade. Also, ensure that your account has the necessary permissions and funds to trade futures contracts^1^.The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Rex Fan
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!