refactor(move function): refresh_latest_trades into dataprovider

needed here to be used for call before analyze
also removes need for internal exchange function checking if
public_trades is enabled
This commit is contained in:
Joe Schr 2023-06-01 12:26:17 +02:00
parent 64a072e207
commit 4abac1364a
2 changed files with 16 additions and 17 deletions

View File

@ -446,10 +446,22 @@ class DataProvider:
final_pairs = (pairlist + helping_pairs) if helping_pairs else pairlist
# refresh latest ohlcv data
self._exchange.refresh_latest_ohlcv(final_pairs)
# refresh latest trades data (if enabled)
self._exchange.refresh_latest_trades(final_pairs,
# refresh latest trades data
self.refresh_latest_trades(final_pairs)
def refresh_latest_trades(self,
pairlist: ListPairsWithTimeframes) -> None:
"""
Refresh latest trades data (if enabled in config)
"""
use_public_trades = self._config.get(
'exchange', {}).get('use_public_trades', False)
if use_public_trades:
return self._exchange.refresh_latest_trades(pairlist,
get_datahandler(self._config['datadir'],
data_format=self._config['dataformat_trades']))
return {}
@property
def available_pairs(self) -> ListPairsWithTimeframes:

View File

@ -2297,25 +2297,12 @@ class Exchange:
now = timeframe_to_next_date(timeframe)
return int((now - timedelta(seconds=move_to // 1000)).timestamp() * 1000)
def refresh_latest_trades(self,
pair_list: ListPairsWithTimeframes ,
data_handler: Callable,# IDataHandler,
*,
cache: bool = True,
) -> Dict[PairWithTimeframe, DataFrame]:
use_public_trades = self._config.get(
'exchange', {}).get('use_public_trades', False)
if use_public_trades:
return self._refresh_latest_trades(pair_list, data_handler, cache=cache)
return {}
def _refresh_latest_trades(self,
pair_list: ListPairsWithTimeframes ,
data_handler: Callable,# IDataHandler,
*,
cache: bool = True,
) -> Dict[PairWithTimeframe, DataFrame]:
"""
Refresh in-memory TRADES asynchronously and set `_trades` with the result
Loops asynchronously over pair_list and downloads all pairs async (semi-parallel).