<metaname="description"content="Freqtrade is a free and open source crypto trading bot written in Python, designed to support all major exchanges and be controlled via Telegram or builtin Web UI">
<inputclass="md-option"data-md-color-media=""data-md-color-scheme="default"data-md-color-primary="blue-grey"data-md-color-accent="tear"aria-label="Switch to dark mode"type="radio"name="__palette"id="__palette_0">
<labelclass="md-header__button md-icon"title="Switch to dark mode"for="__palette_1"hidden>
<inputclass="md-option"data-md-color-media=""data-md-color-scheme="slate"data-md-color-primary="blue-grey"data-md-color-accent="tear"aria-label="Switch to light mode"type="radio"name="__palette"id="__palette_1">
<labelclass="md-header__button md-icon"title="Switch to light mode"for="__palette_0"hidden>
<h1id="trading-with-leverage">Trading with Leverage<aclass="headerlink"href="#trading-with-leverage"title="Permanent link">¶</a></h1>
<divclass="admonition warning">
<pclass="admonition-title">Beta feature</p>
<p>This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">Multiple bots on one account</p>
<p>You can't run 2 bots on the same account with leverage. For leveraged / margin trading, freqtrade assumes it's the only user of the account, and all liquidation levels are calculated based on this assumption.</p>
</div>
<divclass="admonition danger">
<pclass="admonition-title">Trading with leverage is very risky</p>
<p>Do not trade with a leverage > 1 using a strategy that hasn't shown positive results in a live run using the spot market. Check the stoploss of your strategy. With a leverage of 2, a stoploss of 0.5 (50%) would be too low, and these trades would be liquidated before reaching that stoploss.
We do not assume any responsibility for eventual losses that occur from using this software or this mode.</p>
<p>Please only use advanced trading modes when you know how freqtrade (and your strategy) works.
Also, never risk more than what you can afford to lose.</p>
</div>
<p>If you already have an existing strategy, please read the <ahref="../strategy_migration/#strategy-migration-between-v2-and-v3">strategy migration guide</a> to migrate your strategy from a freqtrade v2 strategy, to strategy of version 3 which can short and trade futures.</p>
<p>Shorting is not possible when trading with <ahref="#leverage-trading-modes"><code>trading_mode</code></a> set to <code>spot</code>. To short trade, <code>trading_mode</code> must be set to <code>margin</code>(currently unavailable) or <ahref="#futures"><code>futures</code></a>, with <ahref="#margin-mode"><code>margin_mode</code></a> set to <code>cross</code>(currently unavailable) or <ahref="#isolated-margin-mode"><code>isolated</code></a></p>
<p>For a strategy to short, the strategy class must set the class variable <code>can_short = True</code></p>
<p>Please read <ahref="../strategy-customization/#entry-signal-rules">strategy customization</a> for instructions on how to set signals to enter and exit short trades.</p>
<p>With leverage, a trader borrows capital from the exchange. The capital must be re-payed fully to the exchange (potentially with interest), and the trader keeps any profits, or pays any losses, from any trades made using the borrowed capital.</p>
<p>Because the capital must always be re-payed, exchanges will <strong>liquidate</strong> (forcefully sell the traders assets) a trade made using borrowed capital when the total value of assets in the leverage account drops to a certain point (a point where the total value of losses is less than the value of the collateral that the trader actually owns in the leverage account), in order to ensure that the trader has enough capital to pay the borrowed assets back to the exchange. The exchange will also charge a <strong>liquidation fee</strong>, adding to the traders losses.</p>
<p>For this reason, <strong>DO NOT TRADE WITH LEVERAGE IF YOU DON'T KNOW EXACTLY WHAT YOUR DOING. LEVERAGE TRADING IS HIGH RISK, AND CAN RESULT IN THE VALUE OF YOUR ASSETS DROPPING TO 0 VERY QUICKLY, WITH NO CHANCE OF INCREASING IN VALUE AGAIN.</strong></p>
<p>Trading occurs on the spot market, but the exchange lends currency to you in an amount equal to the chosen leverage. You pay the amount lent to you back to the exchange with interest, and your profits/losses are multiplied by the leverage specified.</p>
<p>Perpetual swaps (also known as Perpetual Futures) are contracts traded at a price that is closely tied to the underlying asset they are based off of (ex.). You are not trading the actual asset but instead are trading a derivative contract. Perpetual swap contracts can last indefinitely, in contrast to futures or option contracts.</p>
<p>In addition to the gains/losses from the change in price of the futures contract, traders also exchange <em>funding fees</em>, which are gains/losses worth an amount that is derived from the difference in price between the futures contract and the underlying asset. The difference in price between a futures contract and the underlying asset varies between exchanges.</p>
<p>To trade in futures markets, you'll have to set <code>trading_mode</code> to "futures".
You will also have to pick a "margin mode" (explanation below) - with freqtrade currently only supporting isolated margin.</p>
<p>One account is used to share collateral between markets (trading pairs). Margin is taken from total account balance to avoid liquidation when needed.</p>
<p>Please read the <ahref="../exchanges/">exchange specific notes</a> for exchanges that support this mode and how they differ.</p>
<h2id="set-leverage-to-use">Set leverage to use<aclass="headerlink"href="#set-leverage-to-use"title="Permanent link">¶</a></h2>
<p>Different strategies and risk profiles will require different levels of leverage.
While you could configure one static leverage value - freqtrade offers you the flexibility to adjust this via <ahref="../strategy-callbacks/#leverage-callback">strategy leverage callback</a> - which allows you to use different leverages by pair, or based on some other factor benefitting your strategy result.</p>
<p>If not implemented, leverage defaults to 1x (no leverage).</p>
<divclass="admonition warning">
<pclass="admonition-title">Warning</p>
<p>Higher leverage also equals higher risk - be sure you fully understand the implications of using leverage!</p>
<p>A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price.
This artificial liquidation price is calculated as:</p>
<li><code>±</code> = <code>+</code> for long trades</li>
<li><code>±</code> = <code>-</code> for short trades</li>
</ul>
<p>Possible values are any floats between 0.0 and 0.99</p>
<p><strong>ex:</strong> If a trade is entered at a price of 10 coin/USDT, and the liquidation price of this trade is 8 coin/USDT, then with <code>liquidation_buffer</code> set to <code>0.05</code> the minimum stoploss for this trade would be <spanclass="arithmatex">\(8 + ((10 - 8) * 0.05) = 8 + 0.1 = 8.1\)</span></p>
<divclass="admonition danger">
<pclass="admonition-title">A <code>liquidation_buffer</code> of 0.0, or a low <code>liquidation_buffer</code> is likely to result in liquidations, and liquidation fees</p>
<p>Currently Freqtrade is able to calculate liquidation prices, but does not calculate liquidation fees. Setting your <code>liquidation_buffer</code> to 0.0, or using a low <code>liquidation_buffer</code> could result in your positions being liquidated. Freqtrade does not track liquidation fees, so liquidations will result in inaccurate profit/loss results for your bot. If you use a low <code>liquidation_buffer</code>, it is recommended to use <code>stoploss_on_exchange</code> if your exchange supports this.</p>
<p>For futures data, exchanges commonly provide the futures candles, the marks, and the funding rates. However, it is common that whilst candles and marks might be available, the funding rates are not. This can affect backtesting timeranges, i.e. you may only be able to test recent timeranges and not earlier, experiencing the <code>No data found. Terminating.</code> error. To get around this, add the <code>futures_funding_rate</code> config option as listed in <ahref="../configuration/">configuration.md</a>, and it is recommended that you set this to <code>0</code>, unless you know a given specific funding rate for your pair, exchange and timerange. Setting this to anything other than <code>0</code> can have drastic effects on your profit calculations within strategy, e.g. within the <code>custom_exit</code>, <code>custom_stoploss</code>, etc functions.</p>
<divclass="admonition warning">
<pclass="admonition-title">This will mean your backtests are inaccurate.</p>
<p>This will not overwrite funding rates that are available from the exchange, but bear in mind that setting a false funding rate will mean backtesting results will be inaccurate for historical timeranges where funding rates are not available.</p>
<p>For shorts, the currency which pays the interest fee for the <code>borrowed</code> currency is purchased at the same time of the closing trade (This means that the amount purchased in short closing trades is greater than the amount sold in short opening trades).</p>
<p>For longs, the currency which pays the interest fee for the <code>borrowed</code> will already be owned by the user and does not need to be purchased. The interest is subtracted from the <code>close_value</code> of the trade.</p>
<p>All Fees are included in <code>current_profit</code> calculations during the trade.</p>
<scriptid="__config"type="application/json">{"base":"..","features":["content.code.annotate","search.share","content.code.copy","navigation.top","navigation.footer"],"search":"../assets/javascripts/workers/search.b8dbb3d2.min.js","translations":{"clipboard.copied":"Copied to clipboard","clipboard.copy":"Copy to clipboard","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.placeholder":"Type to start searching","search.result.term.missing":"Missing","select.version":"Select version"},"version":{"alias":true,"provider":"mike"}}</script>