mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
moved liquidation_buffer to exchange class, add check for valid liquidation_buffer values
This commit is contained in:
parent
305d3738d9
commit
3c3675ea1a
|
@ -101,6 +101,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
|
|||
| `fee` | Fee used during backtesting / dry-runs. Should normally not be configured, which has freqtrade fall back to the exchange default fee. Set as ratio (e.g. 0.001 = 0.1%). Fee is applied twice for each trade, once when buying, once when selling. <br> **Datatype:** Float (as ratio)
|
||||
| `trading_mode` | Specifies if you want to trade regularly, trade with leverage, or trade contracts whose prices are derived from matching cryptocurrency prices. [leverage documentation](leverage.md). <br>*Defaults to `"spot"`.* <br> **Datatype:** String
|
||||
| `margin_mode` | When trading with leverage, this determines if the collateral owned by the trader will be shared or isolated to each trading pair [leverage documentation](leverage.md). <br> **Datatype:** String
|
||||
| `liquidation_buffer` | 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 [leverage documentation](leverage.md). <br>*Defaults to `0.05`.* <br> **Datatype:** Float
|
||||
| `unfilledtimeout.buy` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled buy order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
||||
| `unfilledtimeout.sell` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled sell order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
||||
| `unfilledtimeout.unit` | Unit to use in unfilledtimeout setting. Note: If you set unfilledtimeout.unit to "seconds", "internals.process_throttle_secs" must be inferior or equal to timeout [Strategy Override](#parameters-in-the-strategy). <br> *Defaults to `minutes`.* <br> **Datatype:** String
|
||||
|
|
|
@ -135,13 +135,18 @@ class Exchange:
|
|||
self._trades_pagination = self._ft_has['trades_pagination']
|
||||
self._trades_pagination_arg = self._ft_has['trades_pagination_arg']
|
||||
|
||||
# Leverage properties
|
||||
self.trading_mode = TradingMode(config.get('trading_mode', 'spot'))
|
||||
|
||||
self.margin_mode: Optional[MarginMode] = (
|
||||
MarginMode(config.get('margin_mode'))
|
||||
if config.get('margin_mode')
|
||||
else None
|
||||
)
|
||||
self.liquidation_buffer = config.get('liquidation_buffer', 0.05)
|
||||
if self.liquidation_buffer < 0.0:
|
||||
raise OperationalException('Cannot have a negative liquidation_buffer')
|
||||
if self.liquidation_buffer > 0.99:
|
||||
raise OperationalException('Liquidation_buffer must be below 0.99')
|
||||
|
||||
# Initialize ccxt objects
|
||||
ccxt_config = self._ccxt_config
|
||||
|
@ -2062,7 +2067,7 @@ class Exchange:
|
|||
|
||||
if self._config['dry_run'] or not self.exchange_has("fetchPositions"):
|
||||
|
||||
return self.dry_run_liquidation_price(
|
||||
isolated_liq = self.dry_run_liquidation_price(
|
||||
pair=pair,
|
||||
open_rate=open_rate,
|
||||
is_short=is_short,
|
||||
|
@ -2076,7 +2081,7 @@ class Exchange:
|
|||
positions = self._api.fetch_positions([pair])
|
||||
if len(positions) > 0:
|
||||
pos = positions[0]
|
||||
return pos['liquidationPrice']
|
||||
isolated_liq = pos['liquidationPrice']
|
||||
else:
|
||||
return None
|
||||
except ccxt.DDoSProtection as e:
|
||||
|
@ -2087,6 +2092,17 @@ class Exchange:
|
|||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
||||
if isolated_liq:
|
||||
buffer_amount = abs(open_rate - isolated_liq) * self.liquidation_buffer
|
||||
isolated_liq = (
|
||||
isolated_liq - buffer_amount
|
||||
if is_short else
|
||||
isolated_liq + buffer_amount
|
||||
)
|
||||
return isolated_liq
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_maintenance_ratio_and_amt(
|
||||
self,
|
||||
pair: str,
|
||||
|
|
|
@ -758,14 +758,6 @@ class FreqtradeBot(LoggingMixin):
|
|||
funding_fees = self.exchange.get_funding_fees(
|
||||
pair=pair, amount=amount, is_short=is_short, open_date=open_date)
|
||||
# This is a new trade
|
||||
if isolated_liq:
|
||||
liquidation_buffer = abs(enter_limit_filled_price -
|
||||
isolated_liq) * self.liquidation_buffer
|
||||
isolated_liq = (
|
||||
isolated_liq - liquidation_buffer
|
||||
if is_short else
|
||||
isolated_liq + liquidation_buffer
|
||||
)
|
||||
if trade is None:
|
||||
trade = Trade(
|
||||
pair=pair,
|
||||
|
|
Loading…
Reference in New Issue
Block a user