mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
set leverage more thorough tests
This commit is contained in:
parent
ad44048e29
commit
e070bdd161
|
@ -156,8 +156,8 @@ class Binance(Exchange):
|
|||
def _set_leverage(
|
||||
self,
|
||||
leverage: float,
|
||||
pair: Optional[str],
|
||||
trading_mode: Optional[TradingMode]
|
||||
pair: Optional[str] = None,
|
||||
trading_mode: Optional[TradingMode] = None
|
||||
):
|
||||
"""
|
||||
Set's the leverage before making a trade, in order to not
|
||||
|
|
|
@ -1605,8 +1605,8 @@ class Exchange:
|
|||
def _set_leverage(
|
||||
self,
|
||||
leverage: float,
|
||||
pair: Optional[str],
|
||||
trading_mode: Optional[TradingMode]
|
||||
pair: Optional[str] = None,
|
||||
trading_mode: Optional[TradingMode] = None
|
||||
):
|
||||
"""
|
||||
Set's the leverage before making a trade, in order to not
|
||||
|
|
|
@ -175,8 +175,8 @@ class Kraken(Exchange):
|
|||
def _set_leverage(
|
||||
self,
|
||||
leverage: float,
|
||||
pair: Optional[str],
|
||||
trading_mode: Optional[TradingMode]
|
||||
pair: Optional[str] = None,
|
||||
trading_mode: Optional[TradingMode] = None
|
||||
):
|
||||
"""
|
||||
Kraken set's the leverage as an option in the order object, so we need to
|
||||
|
@ -185,4 +185,5 @@ class Kraken(Exchange):
|
|||
if leverage > 1.0:
|
||||
self._params['leverage'] = leverage
|
||||
else:
|
||||
del self._params['leverage']
|
||||
if 'leverage' in self._params:
|
||||
del self._params['leverage']
|
||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import MagicMock, PropertyMock
|
|||
import ccxt
|
||||
import pytest
|
||||
|
||||
from freqtrade.enums import TradingMode
|
||||
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
||||
from tests.conftest import get_patched_exchange
|
||||
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
||||
|
@ -232,3 +233,25 @@ def test_fill_leverage_brackets_binance(default_conf, mocker):
|
|||
"fill_leverage_brackets",
|
||||
"load_leverage_brackets"
|
||||
)
|
||||
|
||||
|
||||
def test__set_leverage_binance(mocker, default_conf):
|
||||
|
||||
api_mock = MagicMock()
|
||||
api_mock.set_leverage = MagicMock()
|
||||
type(api_mock).has = PropertyMock(return_value={'setLeverage': True})
|
||||
|
||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||
exchange._set_leverage(3.0, trading_mode=TradingMode.MARGIN)
|
||||
|
||||
ccxt_exceptionhandlers(
|
||||
mocker,
|
||||
default_conf,
|
||||
api_mock,
|
||||
"binance",
|
||||
"_set_leverage",
|
||||
"set_leverage",
|
||||
pair="XRP/USDT",
|
||||
leverage=5.0,
|
||||
trading_mode=TradingMode.FUTURES
|
||||
)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from random import randint
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, PropertyMock
|
||||
|
||||
import ccxt
|
||||
import pytest
|
||||
|
||||
from freqtrade.enums import TradingMode
|
||||
from freqtrade.exceptions import DependencyException, InvalidOrderException
|
||||
from freqtrade.exchange.common import API_FETCH_ORDER_RETRY_COUNT
|
||||
from tests.conftest import get_patched_exchange
|
||||
|
@ -229,3 +230,26 @@ def test_fill_leverage_brackets_ftx(default_conf, mocker):
|
|||
exchange = get_patched_exchange(mocker, default_conf, id="ftx")
|
||||
exchange.fill_leverage_brackets()
|
||||
assert exchange._leverage_brackets == {}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("trading_mode", [
|
||||
(TradingMode.MARGIN),
|
||||
(TradingMode.FUTURES)
|
||||
])
|
||||
def test__set_leverage(mocker, default_conf, trading_mode):
|
||||
|
||||
api_mock = MagicMock()
|
||||
api_mock.set_leverage = MagicMock()
|
||||
type(api_mock).has = PropertyMock(return_value={'setLeverage': True})
|
||||
|
||||
ccxt_exceptionhandlers(
|
||||
mocker,
|
||||
default_conf,
|
||||
api_mock,
|
||||
"ftx",
|
||||
"_set_leverage",
|
||||
"set_leverage",
|
||||
pair="XRP/USDT",
|
||||
leverage=5.0,
|
||||
trading_mode=trading_mode
|
||||
)
|
||||
|
|
|
@ -307,7 +307,13 @@ def test_fill_leverage_brackets_kraken(default_conf, mocker):
|
|||
}
|
||||
|
||||
|
||||
def test_kraken__set_leverage(default_conf, mocker):
|
||||
def test__set_leverage_kraken(default_conf, mocker):
|
||||
exchange = get_patched_exchange(mocker, default_conf, id="kraken")
|
||||
exchange._set_leverage(1)
|
||||
assert 'leverage' not in exchange._params
|
||||
exchange._set_leverage(3)
|
||||
assert exchange.params['leverage'] == 3
|
||||
assert exchange._params['leverage'] == 3
|
||||
exchange._set_leverage(1.0)
|
||||
assert 'leverage' not in exchange._params
|
||||
exchange._set_leverage(3.0)
|
||||
assert exchange._params['leverage'] == 3
|
||||
|
|
Loading…
Reference in New Issue
Block a user