Fix stake-amount handling for dry-run
This commit is contained in:
parent
0bac7f824e
commit
76e5d5b232
@ -779,7 +779,7 @@ class Exchange:
|
||||
'price': rate,
|
||||
'average': rate,
|
||||
'amount': _amount,
|
||||
'cost': _amount * rate,
|
||||
'cost': _amount * rate / leverage,
|
||||
'type': ordertype,
|
||||
'side': side,
|
||||
'filled': 0,
|
||||
|
@ -102,8 +102,7 @@ class Wallets:
|
||||
for position in open_trades:
|
||||
# size = self._exchange._contracts_to_amount(position.pair, position['contracts'])
|
||||
size = position.amount
|
||||
# TODO-lev: stake_amount in real trades does not include the leverage ...
|
||||
collateral = position.stake_amount / position.leverage
|
||||
collateral = position.stake_amount
|
||||
leverage = position.leverage
|
||||
tot_in_trades -= collateral
|
||||
_positions[position.pair] = PositionWallet(
|
||||
|
@ -1040,12 +1040,14 @@ def test_exchange_has(default_conf, mocker):
|
||||
assert not exchange.exchange_has("deadbeef")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("side", [
|
||||
("buy"),
|
||||
("sell")
|
||||
@pytest.mark.parametrize("side,leverage", [
|
||||
("buy", 1),
|
||||
("buy", 5),
|
||||
("sell", 1.0),
|
||||
("sell", 5.0),
|
||||
])
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
def test_create_dry_run_order(default_conf, mocker, side, exchange_name):
|
||||
def test_create_dry_run_order(default_conf, mocker, side, exchange_name, leverage):
|
||||
default_conf['dry_run'] = True
|
||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||
|
||||
@ -1055,7 +1057,7 @@ def test_create_dry_run_order(default_conf, mocker, side, exchange_name):
|
||||
side=side,
|
||||
amount=1,
|
||||
rate=200,
|
||||
leverage=1.0
|
||||
leverage=leverage
|
||||
)
|
||||
assert 'id' in order
|
||||
assert f'dry_run_{side}_' in order["id"]
|
||||
@ -1063,6 +1065,8 @@ def test_create_dry_run_order(default_conf, mocker, side, exchange_name):
|
||||
assert order["type"] == "limit"
|
||||
assert order["symbol"] == "ETH/BTC"
|
||||
assert order["amount"] == 1
|
||||
assert order["leverage"] == leverage
|
||||
assert order["cost"] == 1 * 200 / leverage
|
||||
|
||||
|
||||
@pytest.mark.parametrize("side,startprice,endprice", [
|
||||
|
Loading…
Reference in New Issue
Block a user