chore: simplify exchange class setup

remove attributes that are only used once.
This commit is contained in:
Matthias
2025-07-03 08:08:54 +02:00
parent f6ed609134
commit b98816635d
2 changed files with 8 additions and 13 deletions

View File

@@ -399,7 +399,7 @@ class Binance(Exchange):
trades = await self._api_async.fetch_trades( trades = await self._api_async.fetch_trades(
pair, pair,
params={ params={
self._trades_pagination_arg: "0", self._ft_has["trades_pagination_arg"]: "0",
}, },
limit=5, limit=5,
) )

View File

@@ -249,11 +249,6 @@ class Exchange:
# Assign this directly for easy access # Assign this directly for easy access
self._ohlcv_partial_candle = self._ft_has["ohlcv_partial_candle"] self._ohlcv_partial_candle = self._ft_has["ohlcv_partial_candle"]
self._max_trades_limit = self._ft_has["trades_limit"]
self._trades_pagination = self._ft_has["trades_pagination"]
self._trades_pagination_arg = self._ft_has["trades_pagination_arg"]
# Initialize ccxt objects # Initialize ccxt objects
ccxt_config = self._ccxt_config ccxt_config = self._ccxt_config
ccxt_config = deep_merge_dicts(exchange_conf.get("ccxt_config", {}), ccxt_config) ccxt_config = deep_merge_dicts(exchange_conf.get("ccxt_config", {}), ccxt_config)
@@ -2995,7 +2990,7 @@ class Exchange:
returns: List of dicts containing trades, the next iteration value (new "since" or trade_id) returns: List of dicts containing trades, the next iteration value (new "since" or trade_id)
""" """
try: try:
trades_limit = self._max_trades_limit trades_limit = self._ft_has["trades_limit"]
# fetch trades asynchronously # fetch trades asynchronously
if params: if params:
logger.debug("Fetching trades for pair %s, params: %s ", pair, params) logger.debug("Fetching trades for pair %s, params: %s ", pair, params)
@@ -3039,7 +3034,7 @@ class Exchange:
""" """
if not trades: if not trades:
return None return None
if self._trades_pagination == "id": if self._ft_has["trades_pagination"] == "id":
return trades[-1].get("id") return trades[-1].get("id")
else: else:
return trades[-1].get("timestamp") return trades[-1].get("timestamp")
@@ -3057,7 +3052,7 @@ class Exchange:
) -> tuple[str, list[list]]: ) -> tuple[str, list[list]]:
""" """
Asynchronously gets trade history using fetch_trades Asynchronously gets trade history using fetch_trades
use this when exchange uses id-based iteration (check `self._trades_pagination`) use this when exchange uses id-based iteration (check `self._ft_has["trades_pagination"]`)
:param pair: Pair to fetch trade data for :param pair: Pair to fetch trade data for
:param since: Since as integer timestamp in milliseconds :param since: Since as integer timestamp in milliseconds
:param until: Until as integer timestamp in milliseconds :param until: Until as integer timestamp in milliseconds
@@ -3083,7 +3078,7 @@ class Exchange:
while True: while True:
try: try:
t, from_id_next = await self._async_fetch_trades( t, from_id_next = await self._async_fetch_trades(
pair, params={self._trades_pagination_arg: from_id} pair, params={self._ft_has["trades_pagination_arg"]: from_id}
) )
if t: if t:
trades.extend(t[x]) trades.extend(t[x])
@@ -3111,7 +3106,7 @@ class Exchange:
) -> tuple[str, list[list]]: ) -> tuple[str, list[list]]:
""" """
Asynchronously gets trade history using fetch_trades, Asynchronously gets trade history using fetch_trades,
when the exchange uses time-based iteration (check `self._trades_pagination`) when the exchange uses time-based iteration (check `self._ft_has["trades_pagination"]`)
:param pair: Pair to fetch trade data for :param pair: Pair to fetch trade data for
:param since: Since as integer timestamp in milliseconds :param since: Since as integer timestamp in milliseconds
:param until: Until as integer timestamp in milliseconds :param until: Until as integer timestamp in milliseconds
@@ -3165,9 +3160,9 @@ class Exchange:
until = ccxt.Exchange.milliseconds() until = ccxt.Exchange.milliseconds()
logger.debug(f"Exchange milliseconds: {until}") logger.debug(f"Exchange milliseconds: {until}")
if self._trades_pagination == "time": if self._ft_has["trades_pagination"] == "time":
return await self._async_get_trade_history_time(pair=pair, since=since, until=until) return await self._async_get_trade_history_time(pair=pair, since=since, until=until)
elif self._trades_pagination == "id": elif self._ft_has["trades_pagination"] == "id":
return await self._async_get_trade_history_id( return await self._async_get_trade_history_id(
pair=pair, since=since, until=until, from_id=from_id pair=pair, since=since, until=until, from_id=from_id
) )