Update gateio to patch fees

This commit is contained in:
Matthias
2022-03-26 14:57:42 +01:00
parent 33229c91cb
commit 9a8c24ddf3
4 changed files with 31 additions and 4 deletions

View File

@@ -75,6 +75,7 @@ class Exchange:
"mark_ohlcv_price": "mark",
"mark_ohlcv_timeframe": "8h",
"ccxt_futures_name": "swap",
"needs_trading_fees": False, # use fetch_trading_fees to cache fees
}
_ft_has: Dict = {}
_ft_has_futures: Dict = {}
@@ -451,6 +452,9 @@ class Exchange:
self._markets = self._api.load_markets()
self._load_async_markets()
self._last_markets_refresh = arrow.utcnow().int_timestamp
if self._ft_has['needs_trading_fees']:
self.trading_fees = self.fetch_trading_fees()
except ccxt.BaseError:
logger.exception('Unable to initialize markets.')

View File

@@ -27,6 +27,10 @@ class Gateio(Exchange):
"stoploss_on_exchange": True,
}
_ft_has_futures: Dict = {
"needs_trading_fees": True
}
_supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [
# TradingMode.SPOT always supported and not required in this list
# (TradingMode.MARGIN, MarginMode.CROSS),
@@ -42,6 +46,26 @@ class Gateio(Exchange):
raise OperationalException(
f'Exchange {self.name} does not support market orders.')
def fetch_order(self, order_id: str, pair: str, params={}) -> Dict:
order = super().fetch_order(order_id, pair, params)
if self.trading_mode == TradingMode.FUTURES and order.get('fee') is None:
# Futures usually don't contain fees in the response.
# As such, futures orders on gateio will not contain a fee, which causes
# a repeated "update fee" cycle and wrong calculations.
# Therefore we patch the response with fees if it's not available.
# An alternative also contianing fees would be
# privateFuturesGetSettleAccountBook({"settle": "usdt"})
pair_fees = self.trading_fees.get(pair, {})
if pair_fees and pair_fees['taker'] is not None:
order['fee'] = {
'currency': self.get_pair_quote_currency(pair),
'cost': abs(order['cost']) * pair_fees['taker'],
'rate': pair_fees['taker'],
}
return order
def fetch_stoploss_order(self, order_id: str, pair: str, params={}) -> Dict:
return self.fetch_order(
order_id=order_id,