stable/docs/leverage.md

105 lines
6.1 KiB
Markdown
Raw Normal View History

2021-10-30 18:28:46 +00:00
# Leverage
2021-11-05 07:47:58 +00:00
!!! Warning "Beta feature"
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.
2021-11-05 07:47:58 +00:00
!!! Note "Multiple bots on one account"
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.
2021-11-05 07:47:58 +00:00
!!! Danger "Trading with leverage is very risky"
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 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.
2021-11-05 07:47:58 +00:00
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.
## Understand `trading_mode`
2022-02-11 03:02:05 +00:00
The possible values are: `spot` (default), `margin`(*Currently unavailable*) or `futures`.
2021-11-05 07:47:58 +00:00
### Spot
Regular trading mode (low risk)
- Long trades only (No short trades).
- No leverage.
- No Liquidation.
- Profits gained/lost are equal to the change in value of the assets (minus trading fees).
2021-10-30 18:28:46 +00:00
### Leverage trading modes
With leverage, a trader borrows capital from the exchange. The capital must be repayed 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.
Because the capital must always be repayed, exchanges will **liquidate** a trade (forcefully sell the traders assets) made using borrowed capital when the total value of assets in a 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 back the borrowed assets to the exchange. The exchange will also charge a **liquidation fee**, adding to the traders losses. For this reason, **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**
2022-03-12 06:16:31 +00:00
#### Margin
*Currently unavailable*
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
2022-03-12 06:16:31 +00:00
#### Futures
2021-11-05 07:47:58 +00:00
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 indefinately, in contrast to futures or option contracts.
In addition to the gains/losses from the change in price of the contract, traders also exchange funding fees, which are gains/losses worth an amount that is derived from the difference in price between the contract and the underlying asset. The difference in price between a contract and the underlying asset varies between exchanges.
2021-10-30 18:28:46 +00:00
In addition to the gains/losses from the change in price of the futures contract, traders also exchange funding fees, 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.
2021-11-05 07:47:58 +00:00
``` json
"trading_mode": "futures"
```
### Margin mode
2021-11-05 07:47:58 +00:00
The possible values are: `isolated`, or `cross`(*currently unavailable*)
2022-03-12 06:16:31 +00:00
#### Isolated margin mode
Each market(trading pair), keeps collateral in a separate account
2021-10-30 18:28:46 +00:00
``` json
"margin_mode": "isolated"
2021-10-30 18:28:46 +00:00
```
2022-03-12 06:16:31 +00:00
#### Cross margin mode
2021-11-05 07:47:58 +00:00
*currently unavailable*
One account is used to share collateral between markets (trading pairs). Margin is taken from total account balance to avoid liquidation when needed.
2021-11-05 07:47:58 +00:00
``` json
"margin_mode": "cross"
```
2022-02-11 03:02:05 +00:00
## Understand `liquidation_buffer`
2022-03-12 06:16:31 +00:00
*Defaults to `0.05`*
2022-02-11 03:02:05 +00:00
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
`freqtrade_liquidation_price = liquidation_price ± (abs(open_rate - liquidation_price) * liquidation_buffer)`
- `±` = `+` for long trades
- `±` = `-` for short trades
2022-02-11 03:02:05 +00:00
Possible values are any floats between 0.0 and 0.99
**ex:** 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 `liquidation_buffer` set to `0.05` the minimum stoploss for this trade would be 8 + ((10 - 8) * 0.05) = 8 + 0.1 = 8.1
!!! Danger "A `liquidation_buffer` of 0.0, or a low `liquidation_buffer` is likely to result in liquidations, and liquidation fees"
2022-03-12 06:16:31 +00:00
Currently Freqtrade is able to calculate liquidation prices, but does not calculate liquidation fees. Setting your `liquidation_buffer` to 0.0, or using a low `liquidation_buffer` 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 `liquidation_buffer`, it is recommended to use `stoploss_on_exchange` if your exchange supports this.
2022-02-11 03:02:05 +00:00
### Developer
2021-11-05 07:47:58 +00:00
#### Margin mode
For shorts, the currency which pays the interest fee for the `borrowed` 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).
2021-11-05 07:47:58 +00:00
For longs, the currency which pays the interest fee for the `borrowed` will already be owned by the user and does not need to be purchased. The interest is subtracted from the `close_value` of the trade.
All Fees are included in `current_profit` calculations during the trade.
2022-03-12 06:16:31 +00:00
#### Futures mode
Funding fees are either added or subtracted from the total amount of a trade
2022-02-11 03:02:05 +00:00