From 0c1e5afc91384c88e4a3bf6d7aba9894780ef6e3 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sun, 12 Sep 2021 02:02:10 -0600 Subject: [PATCH] Added set leverage to create_order --- freqtrade/exchange/exchange.py | 5 +++-- freqtrade/exchange/kraken.py | 2 +- tests/exchange/test_exchange.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index dfee82d7b..a5778432a 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -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 diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index 97125f7ec..6981204a4 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -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 diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 5c0323915..939e45d63 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -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