Wrote failing tests for exchange.set_leverage and exchange.set_margin_mode
This commit is contained in:
parent
c7a2e6c2c6
commit
1b20b4f3c7
@ -1573,7 +1573,7 @@ class Exchange:
|
|||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
raise TemporaryError(
|
raise TemporaryError(
|
||||||
f'Could not set leverage due to {e.__class__.__name__}. Message: {e}') from e
|
f'Could not set margin mode due to {e.__class__.__name__}. Message: {e}') from e
|
||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import ccxt
|
|||||||
import pytest
|
import pytest
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
from freqtrade.enums import Collateral
|
||||||
from freqtrade.exceptions import (DDosProtection, DependencyException, InvalidOrderException,
|
from freqtrade.exceptions import (DDosProtection, DependencyException, InvalidOrderException,
|
||||||
OperationalException, PricingError, TemporaryError)
|
OperationalException, PricingError, TemporaryError)
|
||||||
from freqtrade.exchange import Binance, Bittrex, Exchange, Kraken
|
from freqtrade.exchange import Binance, Bittrex, Exchange, Kraken
|
||||||
@ -2972,6 +2973,71 @@ def test_get_max_leverage(
|
|||||||
|
|
||||||
|
|
||||||
def test_fill_leverage_brackets():
|
def test_fill_leverage_brackets():
|
||||||
|
api_mock = MagicMock()
|
||||||
|
api_mock.set_leverage = MagicMock(return_value=[
|
||||||
|
{
|
||||||
|
'amount': 0.14542341,
|
||||||
|
'code': 'USDT',
|
||||||
|
'datetime': '2021-09-01T08:00:01.000Z',
|
||||||
|
'id': '485478',
|
||||||
|
'info': {'asset': 'USDT',
|
||||||
|
'income': '0.14542341',
|
||||||
|
'incomeType': 'FUNDING_FEE',
|
||||||
|
'info': 'FUNDING_FEE',
|
||||||
|
'symbol': 'XRPUSDT',
|
||||||
|
'time': '1630512001000',
|
||||||
|
'tradeId': '',
|
||||||
|
'tranId': '4854789484855218760'},
|
||||||
|
'symbol': 'XRP/USDT',
|
||||||
|
'timestamp': 1630512001000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'amount': -0.14642341,
|
||||||
|
'code': 'USDT',
|
||||||
|
'datetime': '2021-09-01T16:00:01.000Z',
|
||||||
|
'id': '485479',
|
||||||
|
'info': {'asset': 'USDT',
|
||||||
|
'income': '-0.14642341',
|
||||||
|
'incomeType': 'FUNDING_FEE',
|
||||||
|
'info': 'FUNDING_FEE',
|
||||||
|
'symbol': 'XRPUSDT',
|
||||||
|
'time': '1630512001000',
|
||||||
|
'tradeId': '',
|
||||||
|
'tranId': '4854789484855218760'},
|
||||||
|
'symbol': 'XRP/USDT',
|
||||||
|
'timestamp': 1630512001000
|
||||||
|
}
|
||||||
|
])
|
||||||
|
type(api_mock).has = PropertyMock(return_value={'fetchFundingHistory': True})
|
||||||
|
|
||||||
|
# mocker.patch('freqtrade.exchange.Exchange.get_funding_fees', lambda pair, since: y)
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
date_time = datetime.strptime("2021-09-01T00:00:01.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
unix_time = int(date_time.strftime('%s'))
|
||||||
|
expected_fees = -0.001 # 0.14542341 + -0.14642341
|
||||||
|
fees_from_datetime = exchange.get_funding_fees(
|
||||||
|
pair='XRP/USDT',
|
||||||
|
since=date_time
|
||||||
|
)
|
||||||
|
fees_from_unix_time = exchange.get_funding_fees(
|
||||||
|
pair='XRP/USDT',
|
||||||
|
since=unix_time
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(isclose(expected_fees, fees_from_datetime))
|
||||||
|
assert(isclose(expected_fees, fees_from_unix_time))
|
||||||
|
|
||||||
|
ccxt_exceptionhandlers(
|
||||||
|
mocker,
|
||||||
|
default_conf,
|
||||||
|
api_mock,
|
||||||
|
exchange_name,
|
||||||
|
"get_funding_fees",
|
||||||
|
"fetch_funding_history",
|
||||||
|
pair="XRP/USDT",
|
||||||
|
since=unix_time
|
||||||
|
)
|
||||||
|
|
||||||
# TODO-lev
|
# TODO-lev
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -2981,6 +3047,47 @@ def test_get_interest_rate():
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def test_set_leverage():
|
@pytest.mark.parametrize("collateral", [
|
||||||
# TODO-lev
|
(Collateral.CROSS),
|
||||||
return
|
(Collateral.ISOLATED)
|
||||||
|
])
|
||||||
|
@pytest.mark.parametrize("exchange_name", [("ftx"), ("binance")])
|
||||||
|
def test_set_leverage(mocker, default_conf, exchange_name, collateral):
|
||||||
|
|
||||||
|
api_mock = MagicMock()
|
||||||
|
api_mock.set_leverage = MagicMock()
|
||||||
|
type(api_mock).has = PropertyMock(return_value={'setLeverage': True})
|
||||||
|
|
||||||
|
ccxt_exceptionhandlers(
|
||||||
|
mocker,
|
||||||
|
default_conf,
|
||||||
|
api_mock,
|
||||||
|
exchange_name,
|
||||||
|
"set_leverage",
|
||||||
|
"set_leverage",
|
||||||
|
symbol="XRP/USDT",
|
||||||
|
collateral=collateral
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("collateral", [
|
||||||
|
(Collateral.CROSS),
|
||||||
|
(Collateral.ISOLATED)
|
||||||
|
])
|
||||||
|
@pytest.mark.parametrize("exchange_name", [("ftx"), ("binance")])
|
||||||
|
def test_set_margin_mode(mocker, default_conf, exchange_name, collateral):
|
||||||
|
|
||||||
|
api_mock = MagicMock()
|
||||||
|
api_mock.set_leverage = MagicMock()
|
||||||
|
type(api_mock).has = PropertyMock(return_value={'setMarginMode': True})
|
||||||
|
|
||||||
|
ccxt_exceptionhandlers(
|
||||||
|
mocker,
|
||||||
|
default_conf,
|
||||||
|
api_mock,
|
||||||
|
exchange_name,
|
||||||
|
"set_margin_mode",
|
||||||
|
"set_margin_mode",
|
||||||
|
symbol="XRP/USDT",
|
||||||
|
collateral=collateral
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user