Merge branch 'lev-exchange' into lev-freqtradebot
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
@@ -2969,18 +2969,11 @@ def test_calculate_backoff(retrycount, max_retries, expected):
|
||||
assert calculate_backoff(retrycount, max_retries) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exchange,stake_amount,leverage,min_stake_with_lev', [
|
||||
('binance', 9.0, 3.0, 3.0),
|
||||
('binance', 20.0, 5.0, 4.0),
|
||||
('binance', 100.0, 100.0, 1.0),
|
||||
# Kraken
|
||||
('kraken', 9.0, 3.0, 9.0),
|
||||
('kraken', 20.0, 5.0, 20.0),
|
||||
('kraken', 100.0, 100.0, 100.0),
|
||||
# FTX
|
||||
('ftx', 9.0, 3.0, 9.0),
|
||||
('ftx', 20.0, 5.0, 20.0),
|
||||
('ftx', 100.0, 100.0, 100.0)
|
||||
@pytest.mark.parametrize('exchange', ['binance', 'kraken', 'ftx'])
|
||||
@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)
|
||||
])
|
||||
def test_apply_leverage_to_stake_amount(
|
||||
exchange,
|
||||
@@ -2994,12 +2987,12 @@ def test_apply_leverage_to_stake_amount(
|
||||
assert exchange._apply_leverage_to_stake_amount(stake_amount, leverage) == min_stake_with_lev
|
||||
|
||||
|
||||
@pytest.mark.parametrize("collateral", [
|
||||
(Collateral.CROSS),
|
||||
(Collateral.ISOLATED)
|
||||
@pytest.mark.parametrize("exchange_name,trading_mode", [
|
||||
("binance", TradingMode.FUTURES),
|
||||
("ftx", TradingMode.MARGIN),
|
||||
("ftx", TradingMode.FUTURES)
|
||||
])
|
||||
@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, trading_mode):
|
||||
|
||||
api_mock = MagicMock()
|
||||
api_mock.set_leverage = MagicMock()
|
||||
@@ -3010,10 +3003,11 @@ 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
|
||||
leverage=5.0,
|
||||
trading_mode=trading_mode
|
||||
)
|
||||
|
||||
|
||||
@@ -3021,8 +3015,7 @@ def test_set_leverage(mocker, default_conf, exchange_name, collateral):
|
||||
(Collateral.CROSS),
|
||||
(Collateral.ISOLATED)
|
||||
])
|
||||
@pytest.mark.parametrize("exchange_name", [("ftx"), ("binance")])
|
||||
def test_set_margin_mode(mocker, default_conf, exchange_name, collateral):
|
||||
def test_set_margin_mode(mocker, default_conf, collateral):
|
||||
|
||||
api_mock = MagicMock()
|
||||
api_mock.set_margin_mode = MagicMock()
|
||||
@@ -3032,7 +3025,7 @@ def test_set_margin_mode(mocker, default_conf, exchange_name, collateral):
|
||||
mocker,
|
||||
default_conf,
|
||||
api_mock,
|
||||
exchange_name,
|
||||
"binance",
|
||||
"set_margin_mode",
|
||||
"set_margin_mode",
|
||||
pair="XRP/USDT",
|
||||
|
@@ -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
|
||||
@@ -227,3 +228,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
|
||||
)
|
||||
|
@@ -294,7 +294,28 @@ def test_fill_leverage_brackets_kraken(default_conf, mocker):
|
||||
exchange.fill_leverage_brackets()
|
||||
|
||||
assert exchange._leverage_brackets == {
|
||||
'BLK/BTC': ['2', '3'],
|
||||
'TKN/BTC': ['2', '3', '4', '5'],
|
||||
'ETH/BTC': ['2']
|
||||
'BLK/BTC': [1, 2, 3],
|
||||
'TKN/BTC': [1, 2, 3, 4, 5],
|
||||
'ETH/BTC': [1, 2],
|
||||
'LTC/BTC': [1],
|
||||
'XRP/BTC': [1],
|
||||
'NEO/BTC': [1],
|
||||
'BTT/BTC': [1],
|
||||
'ETH/USDT': [1],
|
||||
'LTC/USDT': [1],
|
||||
'LTC/USD': [1],
|
||||
'XLTCUSDT': [1],
|
||||
'LTC/ETH': [1]
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
exchange._set_leverage(1.0)
|
||||
assert 'leverage' not in exchange._params
|
||||
exchange._set_leverage(3.0)
|
||||
assert exchange._params['leverage'] == 3
|
||||
|
Reference in New Issue
Block a user