rename column to liquidation_price
This commit is contained in:
parent
2748b113ee
commit
d2a163e2cf
@ -725,7 +725,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
leverage=leverage,
|
leverage=leverage,
|
||||||
is_short=is_short,
|
is_short=is_short,
|
||||||
interest_rate=interest_rate,
|
interest_rate=interest_rate,
|
||||||
isolated_liq=isolated_liq,
|
liquidation_price=isolated_liq,
|
||||||
trading_mode=self.trading_mode,
|
trading_mode=self.trading_mode,
|
||||||
funding_fees=funding_fees
|
funding_fees=funding_fees
|
||||||
)
|
)
|
||||||
|
@ -82,7 +82,8 @@ def migrate_trades_and_orders_table(
|
|||||||
|
|
||||||
# Leverage Properties
|
# Leverage Properties
|
||||||
leverage = get_column_def(cols, 'leverage', '1.0')
|
leverage = get_column_def(cols, 'leverage', '1.0')
|
||||||
isolated_liq = get_column_def(cols, 'isolated_liq', 'null')
|
liquidation_price = get_column_def(cols, 'liquidation_price',
|
||||||
|
get_column_def(cols, 'isolated_liq', 'null'))
|
||||||
# sqlite does not support literals for booleans
|
# sqlite does not support literals for booleans
|
||||||
is_short = get_column_def(cols, 'is_short', '0')
|
is_short = get_column_def(cols, 'is_short', '0')
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ def migrate_trades_and_orders_table(
|
|||||||
stoploss_order_id, stoploss_last_update,
|
stoploss_order_id, stoploss_last_update,
|
||||||
max_rate, min_rate, sell_reason, sell_order_status, strategy, enter_tag,
|
max_rate, min_rate, sell_reason, sell_order_status, strategy, enter_tag,
|
||||||
timeframe, open_trade_value, close_profit_abs,
|
timeframe, open_trade_value, close_profit_abs,
|
||||||
trading_mode, leverage, isolated_liq, is_short,
|
trading_mode, leverage, liquidation_price, is_short,
|
||||||
interest_rate, funding_fees
|
interest_rate, funding_fees
|
||||||
)
|
)
|
||||||
select id, lower(exchange), pair,
|
select id, lower(exchange), pair,
|
||||||
@ -155,7 +156,7 @@ def migrate_trades_and_orders_table(
|
|||||||
{sell_order_status} sell_order_status,
|
{sell_order_status} sell_order_status,
|
||||||
{strategy} strategy, {enter_tag} enter_tag, {timeframe} timeframe,
|
{strategy} strategy, {enter_tag} enter_tag, {timeframe} timeframe,
|
||||||
{open_trade_value} open_trade_value, {close_profit_abs} close_profit_abs,
|
{open_trade_value} open_trade_value, {close_profit_abs} close_profit_abs,
|
||||||
{trading_mode} trading_mode, {leverage} leverage, {isolated_liq} isolated_liq,
|
{trading_mode} trading_mode, {leverage} leverage, {liquidation_price} liquidation_price,
|
||||||
{is_short} is_short, {interest_rate} interest_rate,
|
{is_short} is_short, {interest_rate} interest_rate,
|
||||||
{funding_fees} funding_fees
|
{funding_fees} funding_fees
|
||||||
from {trade_back_name}
|
from {trade_back_name}
|
||||||
@ -233,10 +234,9 @@ def check_migrate(engine, decl_base, previous_tables) -> None:
|
|||||||
|
|
||||||
# Check if migration necessary
|
# Check if migration necessary
|
||||||
# Migrates both trades and orders table!
|
# Migrates both trades and orders table!
|
||||||
# if not has_column(cols, 'buy_tag'):
|
# if ('orders' not in previous_tables
|
||||||
if ('orders' not in previous_tables
|
# or not has_column(cols_orders, 'leverage')):
|
||||||
or not has_column(cols_orders, 'ft_fee_base')
|
if not has_column(cols, 'liquidation_price'):
|
||||||
or not has_column(cols_orders, 'leverage')):
|
|
||||||
logger.info(f"Running database migration for trades - "
|
logger.info(f"Running database migration for trades - "
|
||||||
f"backup: {table_back_name}, {order_table_bak_name}")
|
f"backup: {table_back_name}, {order_table_bak_name}")
|
||||||
migrate_trades_and_orders_table(
|
migrate_trades_and_orders_table(
|
||||||
|
@ -329,7 +329,7 @@ class LocalTrade():
|
|||||||
trading_mode: TradingMode = TradingMode.SPOT
|
trading_mode: TradingMode = TradingMode.SPOT
|
||||||
|
|
||||||
# Leverage trading properties
|
# Leverage trading properties
|
||||||
isolated_liq: Optional[float] = None
|
liquidation_price: Optional[float] = None
|
||||||
is_short: bool = False
|
is_short: bool = False
|
||||||
leverage: float = 1.0
|
leverage: float = 1.0
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ class LocalTrade():
|
|||||||
|
|
||||||
'leverage': self.leverage,
|
'leverage': self.leverage,
|
||||||
'interest_rate': self.interest_rate,
|
'interest_rate': self.interest_rate,
|
||||||
'isolated_liq': self.isolated_liq,
|
'liquidation_price': self.liquidation_price,
|
||||||
'is_short': self.is_short,
|
'is_short': self.is_short,
|
||||||
'trading_mode': self.trading_mode,
|
'trading_mode': self.trading_mode,
|
||||||
'funding_fees': self.funding_fees,
|
'funding_fees': self.funding_fees,
|
||||||
@ -507,25 +507,25 @@ class LocalTrade():
|
|||||||
self.max_rate = max(current_price, self.max_rate or self.open_rate)
|
self.max_rate = max(current_price, self.max_rate or self.open_rate)
|
||||||
self.min_rate = min(current_price_low, self.min_rate or self.open_rate)
|
self.min_rate = min(current_price_low, self.min_rate or self.open_rate)
|
||||||
|
|
||||||
def set_isolated_liq(self, isolated_liq: Optional[float]):
|
def set_isolated_liq(self, liquidation_price: Optional[float]):
|
||||||
"""
|
"""
|
||||||
Method you should use to set self.liquidation price.
|
Method you should use to set self.liquidation price.
|
||||||
Assures stop_loss is not passed the liquidation price
|
Assures stop_loss is not passed the liquidation price
|
||||||
"""
|
"""
|
||||||
if not isolated_liq:
|
if not liquidation_price:
|
||||||
return
|
return
|
||||||
self.isolated_liq = isolated_liq
|
self.liquidation_price = liquidation_price
|
||||||
|
|
||||||
def _set_stop_loss(self, stop_loss: float, percent: float):
|
def _set_stop_loss(self, stop_loss: float, percent: float):
|
||||||
"""
|
"""
|
||||||
Method you should use to set self.stop_loss.
|
Method you should use to set self.stop_loss.
|
||||||
Assures stop_loss is not passed the liquidation price
|
Assures stop_loss is not passed the liquidation price
|
||||||
"""
|
"""
|
||||||
if self.isolated_liq is not None:
|
if self.liquidation_price is not None:
|
||||||
if self.is_short:
|
if self.is_short:
|
||||||
sl = min(stop_loss, self.isolated_liq)
|
sl = min(stop_loss, self.liquidation_price)
|
||||||
else:
|
else:
|
||||||
sl = max(stop_loss, self.isolated_liq)
|
sl = max(stop_loss, self.liquidation_price)
|
||||||
else:
|
else:
|
||||||
sl = stop_loss
|
sl = stop_loss
|
||||||
|
|
||||||
@ -553,13 +553,13 @@ class LocalTrade():
|
|||||||
if self.is_short:
|
if self.is_short:
|
||||||
new_loss = float(current_price * (1 + abs(stoploss / leverage)))
|
new_loss = float(current_price * (1 + abs(stoploss / leverage)))
|
||||||
# If trading with leverage, don't set the stoploss below the liquidation price
|
# If trading with leverage, don't set the stoploss below the liquidation price
|
||||||
if self.isolated_liq:
|
if self.liquidation_price:
|
||||||
new_loss = min(self.isolated_liq, new_loss)
|
new_loss = min(self.liquidation_price, new_loss)
|
||||||
else:
|
else:
|
||||||
new_loss = float(current_price * (1 - abs(stoploss / leverage)))
|
new_loss = float(current_price * (1 - abs(stoploss / leverage)))
|
||||||
# If trading with leverage, don't set the stoploss below the liquidation price
|
# If trading with leverage, don't set the stoploss below the liquidation price
|
||||||
if self.isolated_liq:
|
if self.liquidation_price:
|
||||||
new_loss = max(self.isolated_liq, new_loss)
|
new_loss = max(self.liquidation_price, new_loss)
|
||||||
|
|
||||||
# no stop loss assigned yet
|
# no stop loss assigned yet
|
||||||
if self.initial_stop_loss_pct is None:
|
if self.initial_stop_loss_pct is None:
|
||||||
@ -1093,7 +1093,7 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||||||
# Leverage trading properties
|
# Leverage trading properties
|
||||||
leverage = Column(Float, nullable=True, default=1.0)
|
leverage = Column(Float, nullable=True, default=1.0)
|
||||||
is_short = Column(Boolean, nullable=False, default=False)
|
is_short = Column(Boolean, nullable=False, default=False)
|
||||||
isolated_liq = Column(Float, nullable=True)
|
liquidation_price = Column(Float, nullable=True)
|
||||||
|
|
||||||
# Margin Trading Properties
|
# Margin Trading Properties
|
||||||
interest_rate = Column(Float, nullable=False, default=0.0)
|
interest_rate = Column(Float, nullable=False, default=0.0)
|
||||||
|
@ -613,7 +613,7 @@ def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
|||||||
# = 0.0008176703703703704
|
# = 0.0008176703703703704
|
||||||
|
|
||||||
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
||||||
assert pytest.approx(trade.isolated_liq) == 0.00081767037
|
assert pytest.approx(trade.liquidation_price) == 0.00081767037
|
||||||
|
|
||||||
# Binance, Short
|
# Binance, Short
|
||||||
# liquidation_price
|
# liquidation_price
|
||||||
@ -625,7 +625,7 @@ def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
|||||||
# = 0.0011787191419141915
|
# = 0.0011787191419141915
|
||||||
|
|
||||||
trade = backtesting._enter_trade(pair, row=row, direction='short')
|
trade = backtesting._enter_trade(pair, row=row, direction='short')
|
||||||
assert pytest.approx(trade.isolated_liq) == 0.0011787191
|
assert pytest.approx(trade.liquidation_price) == 0.0011787191
|
||||||
|
|
||||||
# Stake-amount too high!
|
# Stake-amount too high!
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=600.0)
|
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=600.0)
|
||||||
|
@ -112,7 +112,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||||||
'exchange': 'binance',
|
'exchange': 'binance',
|
||||||
'leverage': 1.0,
|
'leverage': 1.0,
|
||||||
'interest_rate': 0.0,
|
'interest_rate': 0.0,
|
||||||
'isolated_liq': None,
|
'liquidation_price': None,
|
||||||
'is_short': False,
|
'is_short': False,
|
||||||
'funding_fees': 0.0,
|
'funding_fees': 0.0,
|
||||||
'trading_mode': TradingMode.SPOT,
|
'trading_mode': TradingMode.SPOT,
|
||||||
@ -194,7 +194,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||||||
'exchange': 'binance',
|
'exchange': 'binance',
|
||||||
'leverage': 1.0,
|
'leverage': 1.0,
|
||||||
'interest_rate': 0.0,
|
'interest_rate': 0.0,
|
||||||
'isolated_liq': None,
|
'liquidation_price': None,
|
||||||
'is_short': False,
|
'is_short': False,
|
||||||
'funding_fees': 0.0,
|
'funding_fees': 0.0,
|
||||||
'trading_mode': TradingMode.SPOT,
|
'trading_mode': TradingMode.SPOT,
|
||||||
|
@ -944,7 +944,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
|||||||
trade.is_short = is_short
|
trade.is_short = is_short
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.open_rate_requested == 10
|
assert trade.open_rate_requested == 10
|
||||||
assert trade.isolated_liq == liq_price
|
assert trade.liquidation_price == liq_price
|
||||||
|
|
||||||
# In case of too high stake amount
|
# In case of too high stake amount
|
||||||
|
|
||||||
|
@ -116,38 +116,38 @@ def test_set_stop_loss_isolated_liq(fee):
|
|||||||
trading_mode=margin
|
trading_mode=margin
|
||||||
)
|
)
|
||||||
trade.set_isolated_liq(0.09)
|
trade.set_isolated_liq(0.09)
|
||||||
assert trade.isolated_liq == 0.09
|
assert trade.liquidation_price == 0.09
|
||||||
assert trade.stop_loss is None
|
assert trade.stop_loss is None
|
||||||
assert trade.initial_stop_loss is None
|
assert trade.initial_stop_loss is None
|
||||||
|
|
||||||
trade._set_stop_loss(0.1, (1.0/9.0))
|
trade._set_stop_loss(0.1, (1.0/9.0))
|
||||||
assert trade.isolated_liq == 0.09
|
assert trade.liquidation_price == 0.09
|
||||||
assert trade.stop_loss == 0.1
|
assert trade.stop_loss == 0.1
|
||||||
assert trade.initial_stop_loss == 0.1
|
assert trade.initial_stop_loss == 0.1
|
||||||
|
|
||||||
trade.set_isolated_liq(0.08)
|
trade.set_isolated_liq(0.08)
|
||||||
assert trade.isolated_liq == 0.08
|
assert trade.liquidation_price == 0.08
|
||||||
assert trade.stop_loss == 0.1
|
assert trade.stop_loss == 0.1
|
||||||
assert trade.initial_stop_loss == 0.1
|
assert trade.initial_stop_loss == 0.1
|
||||||
|
|
||||||
trade.set_isolated_liq(0.11)
|
trade.set_isolated_liq(0.11)
|
||||||
trade._set_stop_loss(0.1, 0)
|
trade._set_stop_loss(0.1, 0)
|
||||||
assert trade.isolated_liq == 0.11
|
assert trade.liquidation_price == 0.11
|
||||||
assert trade.stop_loss == 0.11
|
assert trade.stop_loss == 0.11
|
||||||
assert trade.initial_stop_loss == 0.1
|
assert trade.initial_stop_loss == 0.1
|
||||||
|
|
||||||
# lower stop doesn't move stoploss
|
# lower stop doesn't move stoploss
|
||||||
trade._set_stop_loss(0.1, 0)
|
trade._set_stop_loss(0.1, 0)
|
||||||
assert trade.isolated_liq == 0.11
|
assert trade.liquidation_price == 0.11
|
||||||
assert trade.stop_loss == 0.11
|
assert trade.stop_loss == 0.11
|
||||||
assert trade.initial_stop_loss == 0.1
|
assert trade.initial_stop_loss == 0.1
|
||||||
|
|
||||||
trade.stop_loss = None
|
trade.stop_loss = None
|
||||||
trade.isolated_liq = None
|
trade.liquidation_price = None
|
||||||
trade.initial_stop_loss = None
|
trade.initial_stop_loss = None
|
||||||
|
|
||||||
trade._set_stop_loss(0.07, 0)
|
trade._set_stop_loss(0.07, 0)
|
||||||
assert trade.isolated_liq is None
|
assert trade.liquidation_price is None
|
||||||
assert trade.stop_loss == 0.07
|
assert trade.stop_loss == 0.07
|
||||||
assert trade.initial_stop_loss == 0.07
|
assert trade.initial_stop_loss == 0.07
|
||||||
|
|
||||||
@ -157,29 +157,29 @@ def test_set_stop_loss_isolated_liq(fee):
|
|||||||
trade.initial_stop_loss = None
|
trade.initial_stop_loss = None
|
||||||
|
|
||||||
trade.set_isolated_liq(0.09)
|
trade.set_isolated_liq(0.09)
|
||||||
assert trade.isolated_liq == 0.09
|
assert trade.liquidation_price == 0.09
|
||||||
assert trade.stop_loss is None
|
assert trade.stop_loss is None
|
||||||
assert trade.initial_stop_loss is None
|
assert trade.initial_stop_loss is None
|
||||||
|
|
||||||
trade._set_stop_loss(0.08, (1.0/9.0))
|
trade._set_stop_loss(0.08, (1.0/9.0))
|
||||||
assert trade.isolated_liq == 0.09
|
assert trade.liquidation_price == 0.09
|
||||||
assert trade.stop_loss == 0.08
|
assert trade.stop_loss == 0.08
|
||||||
assert trade.initial_stop_loss == 0.08
|
assert trade.initial_stop_loss == 0.08
|
||||||
|
|
||||||
trade.set_isolated_liq(0.1)
|
trade.set_isolated_liq(0.1)
|
||||||
assert trade.isolated_liq == 0.1
|
assert trade.liquidation_price == 0.1
|
||||||
assert trade.stop_loss == 0.08
|
assert trade.stop_loss == 0.08
|
||||||
assert trade.initial_stop_loss == 0.08
|
assert trade.initial_stop_loss == 0.08
|
||||||
|
|
||||||
trade.set_isolated_liq(0.07)
|
trade.set_isolated_liq(0.07)
|
||||||
trade._set_stop_loss(0.1, (1.0/8.0))
|
trade._set_stop_loss(0.1, (1.0/8.0))
|
||||||
assert trade.isolated_liq == 0.07
|
assert trade.liquidation_price == 0.07
|
||||||
assert trade.stop_loss == 0.07
|
assert trade.stop_loss == 0.07
|
||||||
assert trade.initial_stop_loss == 0.08
|
assert trade.initial_stop_loss == 0.08
|
||||||
|
|
||||||
# Stop doesn't move stop higher
|
# Stop doesn't move stop higher
|
||||||
trade._set_stop_loss(0.1, (1.0/9.0))
|
trade._set_stop_loss(0.1, (1.0/9.0))
|
||||||
assert trade.isolated_liq == 0.07
|
assert trade.liquidation_price == 0.07
|
||||||
assert trade.stop_loss == 0.07
|
assert trade.stop_loss == 0.07
|
||||||
assert trade.initial_stop_loss == 0.08
|
assert trade.initial_stop_loss == 0.08
|
||||||
|
|
||||||
@ -1474,7 +1474,7 @@ def test_adjust_stop_loss_short(fee):
|
|||||||
trade.set_isolated_liq(0.63)
|
trade.set_isolated_liq(0.63)
|
||||||
trade.adjust_stop_loss(0.59, -0.1)
|
trade.adjust_stop_loss(0.59, -0.1)
|
||||||
assert trade.stop_loss == 0.63
|
assert trade.stop_loss == 0.63
|
||||||
assert trade.isolated_liq == 0.63
|
assert trade.liquidation_price == 0.63
|
||||||
|
|
||||||
|
|
||||||
def test_adjust_min_max_rates(fee):
|
def test_adjust_min_max_rates(fee):
|
||||||
@ -1539,7 +1539,7 @@ def test_get_open_lev(fee, use_db):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_to_json(default_conf, fee):
|
def test_to_json(fee):
|
||||||
|
|
||||||
# Simulate dry_run entries
|
# Simulate dry_run entries
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
@ -1608,7 +1608,7 @@ def test_to_json(default_conf, fee):
|
|||||||
'exchange': 'binance',
|
'exchange': 'binance',
|
||||||
'leverage': None,
|
'leverage': None,
|
||||||
'interest_rate': None,
|
'interest_rate': None,
|
||||||
'isolated_liq': None,
|
'liquidation_price': None,
|
||||||
'is_short': None,
|
'is_short': None,
|
||||||
'trading_mode': None,
|
'trading_mode': None,
|
||||||
'funding_fees': None,
|
'funding_fees': None,
|
||||||
@ -1683,7 +1683,7 @@ def test_to_json(default_conf, fee):
|
|||||||
'exchange': 'binance',
|
'exchange': 'binance',
|
||||||
'leverage': None,
|
'leverage': None,
|
||||||
'interest_rate': None,
|
'interest_rate': None,
|
||||||
'isolated_liq': None,
|
'liquidation_price': None,
|
||||||
'is_short': None,
|
'is_short': None,
|
||||||
'trading_mode': None,
|
'trading_mode': None,
|
||||||
'funding_fees': None,
|
'funding_fees': None,
|
||||||
|
Loading…
Reference in New Issue
Block a user