Added set leverage to create_order
This commit is contained in:
parent
09418938fe
commit
0c1e5afc91
@ -771,12 +771,13 @@ class Exchange:
|
|||||||
# Order handling
|
# Order handling
|
||||||
|
|
||||||
def create_order(self, pair: str, ordertype: str, side: str, amount: float,
|
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']:
|
if self._config['dry_run']:
|
||||||
dry_order = self.create_dry_run_order(pair, ordertype, side, amount, rate)
|
dry_order = self.create_dry_run_order(pair, ordertype, side, amount, rate)
|
||||||
return dry_order
|
return dry_order
|
||||||
|
|
||||||
|
self._set_leverage(pair, leverage)
|
||||||
params = self._params.copy()
|
params = self._params.copy()
|
||||||
if time_in_force != 'gtc' and ordertype != 'market':
|
if time_in_force != 'gtc' and ordertype != 'market':
|
||||||
param = self._ft_has.get('time_in_force_parameter', '')
|
param = self._ft_has.get('time_in_force_parameter', '')
|
||||||
@ -1600,7 +1601,7 @@ class Exchange:
|
|||||||
return 1.0
|
return 1.0
|
||||||
|
|
||||||
@retrier
|
@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
|
Set's the leverage before making a trade, in order to not
|
||||||
have the same leverage on every trade
|
have the same leverage on every trade
|
||||||
|
@ -172,7 +172,7 @@ class Kraken(Exchange):
|
|||||||
"""
|
"""
|
||||||
return float(max(self._leverage_brackets[pair]))
|
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
|
Kraken set's the leverage as an option in the order object, so we need to
|
||||||
add it to params
|
add it to params
|
||||||
|
@ -2970,7 +2970,7 @@ def test_calculate_backoff(retrycount, max_retries, expected):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('exchange', ['binance', 'kraken', 'ftx'])
|
@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),
|
(9.0, 3.0, 3.0),
|
||||||
(20.0, 5.0, 4.0),
|
(20.0, 5.0, 4.0),
|
||||||
(100.0, 100.0, 1.0)
|
(100.0, 100.0, 1.0)
|
||||||
@ -2992,7 +2992,7 @@ def test_apply_leverage_to_stake_amount(
|
|||||||
(Collateral.ISOLATED)
|
(Collateral.ISOLATED)
|
||||||
])
|
])
|
||||||
@pytest.mark.parametrize("exchange_name", [("ftx"), ("binance")])
|
@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 = MagicMock()
|
||||||
api_mock.set_leverage = MagicMock()
|
api_mock.set_leverage = MagicMock()
|
||||||
@ -3003,7 +3003,7 @@ def test_set_leverage(mocker, default_conf, exchange_name, collateral):
|
|||||||
default_conf,
|
default_conf,
|
||||||
api_mock,
|
api_mock,
|
||||||
exchange_name,
|
exchange_name,
|
||||||
"set_leverage",
|
"_set_leverage",
|
||||||
"set_leverage",
|
"set_leverage",
|
||||||
pair="XRP/USDT",
|
pair="XRP/USDT",
|
||||||
leverage=5.0
|
leverage=5.0
|
||||||
|
Loading…
Reference in New Issue
Block a user