Added set leverage to create_order

This commit is contained in:
Sam Germain 2021-09-12 02:02:10 -06:00
parent 09418938fe
commit 0c1e5afc91
3 changed files with 7 additions and 6 deletions

View File

@ -771,12 +771,13 @@ class Exchange:
# Order handling
def create_order(self, pair: str, ordertype: str, side: str, amount: float,
rate: float, time_in_force: str = 'gtc') -> Dict:
rate: float, time_in_force: str = 'gtc', leverage=1.0) -> Dict:
if self._config['dry_run']:
dry_order = self.create_dry_run_order(pair, ordertype, side, amount, rate)
return dry_order
self._set_leverage(pair, leverage)
params = self._params.copy()
if time_in_force != 'gtc' and ordertype != 'market':
param = self._ft_has.get('time_in_force_parameter', '')
@ -1600,7 +1601,7 @@ class Exchange:
return 1.0
@retrier
def set_leverage(self, leverage: float, pair: Optional[str]):
def _set_leverage(self, leverage: float, pair: Optional[str]):
"""
Set's the leverage before making a trade, in order to not
have the same leverage on every trade

View File

@ -172,7 +172,7 @@ class Kraken(Exchange):
"""
return float(max(self._leverage_brackets[pair]))
def set_leverage(self, pair, leverage):
def _set_leverage(self, pair, leverage):
"""
Kraken set's the leverage as an option in the order object, so we need to
add it to params

View File

@ -2970,7 +2970,7 @@ def test_calculate_backoff(retrycount, max_retries, expected):
@pytest.mark.parametrize('exchange', ['binance', 'kraken', 'ftx'])
@pytest.mark.parametrize('exchange,stake_amount,leverage,min_stake_with_lev', [
@pytest.mark.parametrize('stake_amount,leverage,min_stake_with_lev', [
(9.0, 3.0, 3.0),
(20.0, 5.0, 4.0),
(100.0, 100.0, 1.0)
@ -2992,7 +2992,7 @@ def test_apply_leverage_to_stake_amount(
(Collateral.ISOLATED)
])
@pytest.mark.parametrize("exchange_name", [("ftx"), ("binance")])
def test_set_leverage(mocker, default_conf, exchange_name, collateral):
def test__set_leverage(mocker, default_conf, exchange_name, collateral):
api_mock = MagicMock()
api_mock.set_leverage = MagicMock()
@ -3003,7 +3003,7 @@ def test_set_leverage(mocker, default_conf, exchange_name, collateral):
default_conf,
api_mock,
exchange_name,
"set_leverage",
"_set_leverage",
"set_leverage",
pair="XRP/USDT",
leverage=5.0