Merge pull request #6425 from samgermain/stake-amount

leverage in trade.stake_amount calculation
This commit is contained in:
Matthias 2022-02-19 20:11:23 +01:00 committed by GitHub
commit c3c815e794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -1291,8 +1291,7 @@ class FreqtradeBot(LoggingMixin):
# * Check edge cases, we don't want to make leverage > 1.0 if we don't have to
# * (for leverage modes which aren't isolated futures)
# TODO-lev: The below calculation needs to include leverage ...
trade.stake_amount = trade.amount * trade.open_rate
trade.stake_amount = trade.amount * trade.open_rate / trade.leverage
self.update_trade_state(trade, trade.open_order_id, corder)
trade.open_order_id = None

View File

@ -2573,11 +2573,13 @@ def test_check_handle_cancelled_sell(
@pytest.mark.parametrize("is_short", [False, True])
@pytest.mark.parametrize("leverage", [1, 3, 5, 10])
def test_check_handle_timedout_partial(
default_conf_usdt, ticker_usdt, limit_buy_order_old_partial, is_short,
default_conf_usdt, ticker_usdt, limit_buy_order_old_partial, is_short, leverage,
open_trade, mocker
) -> None:
rpc_mock = patch_RPCManager(mocker)
open_trade.leverage = leverage
limit_buy_order_old_partial['id'] = open_trade.open_order_id
limit_buy_canceled = deepcopy(limit_buy_order_old_partial)
limit_buy_canceled['status'] = 'canceled'
@ -2591,7 +2593,7 @@ def test_check_handle_timedout_partial(
cancel_order_with_result=cancel_order_mock
)
freqtrade = FreqtradeBot(default_conf_usdt)
prior_stake = open_trade.stake_amount
Trade.query.session.add(open_trade)
# check it does cancel buy orders over the time limit
@ -2602,7 +2604,8 @@ def test_check_handle_timedout_partial(
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
assert len(trades) == 1
assert trades[0].amount == 23.0
assert trades[0].stake_amount == open_trade.open_rate * trades[0].amount
assert trades[0].stake_amount == open_trade.open_rate * trades[0].amount / leverage
assert trades[0].stake_amount != prior_stake
@pytest.mark.parametrize("is_short", [False, True])