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