Add fetch_trading_fees endpoint
This commit is contained in:
parent
5d3f2523e3
commit
33229c91cb
@ -1299,6 +1299,27 @@ class Exchange:
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
@retrier
|
||||||
|
def fetch_trading_fees(self) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
Fetch user account trading fees
|
||||||
|
Can be cached, should not update often.
|
||||||
|
"""
|
||||||
|
if (self._config['dry_run'] or self.trading_mode != TradingMode.FUTURES
|
||||||
|
or not self.exchange_has('fetchTradingFees')):
|
||||||
|
return {}
|
||||||
|
try:
|
||||||
|
trading_fees: Dict[str, Any] = self._api.fetch_trading_fees()
|
||||||
|
self._log_exchange_response('fetch_trading_fees', trading_fees)
|
||||||
|
return trading_fees
|
||||||
|
except ccxt.DDoSProtection as e:
|
||||||
|
raise DDosProtection(e) from e
|
||||||
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
|
raise TemporaryError(
|
||||||
|
f'Could not fetch trading fees due to {e.__class__.__name__}. Message: {e}') from e
|
||||||
|
except ccxt.BaseError as e:
|
||||||
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def fetch_bids_asks(self, symbols: List[str] = None, cached: bool = False) -> Dict:
|
def fetch_bids_asks(self, symbols: List[str] = None, cached: bool = False) -> Dict:
|
||||||
"""
|
"""
|
||||||
|
@ -1624,6 +1624,64 @@ def test_fetch_positions(default_conf, mocker, exchange_name):
|
|||||||
"fetch_positions", "fetch_positions")
|
"fetch_positions", "fetch_positions")
|
||||||
|
|
||||||
|
|
||||||
|
def test_fetch_trading_fees(default_conf, mocker):
|
||||||
|
api_mock = MagicMock()
|
||||||
|
tick = {
|
||||||
|
'1INCH/USDT:USDT': {
|
||||||
|
'info': {'user_id': '6266643',
|
||||||
|
'taker_fee': '0.0018',
|
||||||
|
'maker_fee': '0.0018',
|
||||||
|
'gt_discount': False,
|
||||||
|
'gt_taker_fee': '0',
|
||||||
|
'gt_maker_fee': '0',
|
||||||
|
'loan_fee': '0.18',
|
||||||
|
'point_type': '1',
|
||||||
|
'futures_taker_fee': '0.0005',
|
||||||
|
'futures_maker_fee': '0'},
|
||||||
|
'symbol': '1INCH/USDT:USDT',
|
||||||
|
'maker': 0.0,
|
||||||
|
'taker': 0.0005},
|
||||||
|
'ETH/USDT:USDT': {
|
||||||
|
'info': {'user_id': '6266643',
|
||||||
|
'taker_fee': '0.0018',
|
||||||
|
'maker_fee': '0.0018',
|
||||||
|
'gt_discount': False,
|
||||||
|
'gt_taker_fee': '0',
|
||||||
|
'gt_maker_fee': '0',
|
||||||
|
'loan_fee': '0.18',
|
||||||
|
'point_type': '1',
|
||||||
|
'futures_taker_fee': '0.0005',
|
||||||
|
'futures_maker_fee': '0'},
|
||||||
|
'symbol': 'ETH/USDT:USDT',
|
||||||
|
'maker': 0.0,
|
||||||
|
'taker': 0.0005}
|
||||||
|
}
|
||||||
|
exchange_name = 'gateio'
|
||||||
|
default_conf['dry_run'] = False
|
||||||
|
default_conf['trading_mode'] = TradingMode.FUTURES
|
||||||
|
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||||
|
api_mock.fetch_trading_fees = MagicMock(return_value=tick)
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
# retrieve original ticker
|
||||||
|
tradingfees = exchange.fetch_trading_fees()
|
||||||
|
|
||||||
|
assert '1INCH/USDT:USDT' in tradingfees
|
||||||
|
assert 'ETH/USDT:USDT' in tradingfees
|
||||||
|
assert api_mock.fetch_trading_fees.call_count == 1
|
||||||
|
|
||||||
|
api_mock.fetch_trading_fees.reset_mock()
|
||||||
|
|
||||||
|
ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name,
|
||||||
|
"fetch_trading_fees", "fetch_trading_fees")
|
||||||
|
|
||||||
|
api_mock.fetch_trading_fees = MagicMock(return_value={})
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
exchange.fetch_trading_fees()
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
||||||
|
assert exchange.fetch_trading_fees() == {}
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_bids_asks(default_conf, mocker):
|
def test_fetch_bids_asks(default_conf, mocker):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
tick = {'ETH/BTC': {
|
tick = {'ETH/BTC': {
|
||||||
|
Loading…
Reference in New Issue
Block a user