diff --git a/freqtrade/data/converter.py b/freqtrade/data/converter.py index 63a6c98df..1ef224978 100644 --- a/freqtrade/data/converter.py +++ b/freqtrade/data/converter.py @@ -116,21 +116,23 @@ def order_book_to_dataframe(bids: list, asks: list) -> DataFrame: return frame -def trades_to_ohlcv(trades, timeframe): +def trades_to_ohlcv(trades: list, timeframe: str) -> list: """ Converts trades list to ohlcv list + :param trades: List of trades, as returned by ccxt.fetch_trades. + :param timeframe: Ticker timeframe to resample data to + :return: ohlcv timeframe as list (as returned by ccxt.fetch_ohlcv) """ from freqtrade.exchange import timeframe_to_minutes ticker_minutes = timeframe_to_minutes(timeframe) df = pd.DataFrame(trades) df['datetime'] = pd.to_datetime(df['datetime']) - df = df.set_index('datetime') - df_new = df['price'].resample(f'{ticker_minutes}min').ohlc() + df_new = df['price'].resample(f'{ticker_minutes}min').ohlc() df_new['volume'] = df['amount'].resample(f'{ticker_minutes}min').sum() df_new['date'] = df_new.index.astype("int64") // 10 ** 6 - # Drop 0 volume columns + # Drop 0 volume rows df_new = df_new.dropna() columns = ["date", "open", "high", "low", "close", "volume"] return list(zip(*[df_new[x].values.tolist() for x in columns])) diff --git a/freqtrade/data/history.py b/freqtrade/data/history.py index e594af430..fd3aee2a9 100644 --- a/freqtrade/data/history.py +++ b/freqtrade/data/history.py @@ -93,7 +93,6 @@ def load_trades_file(datadir: Path, pair: str, if not tradesdata: return [] - # TODO: trim trades based on timerange... ? return tradesdata diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index fed903a4a..86078ae05 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -988,22 +988,6 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(e) from e - def build_ohlcv(self, trades: List[Dict], timeframe: str, since: int = None, - limit: int = None) -> List: - """ - Build ohlcv data from trade list. - trade-list has to be in the ccxt format, which is a list of dicts containing at least: - * timestamp - * price - * amount - :param trades: List of Dicts - :param timeframe: timeframe to convert to (e.g. "5m") - :param since: start at a specific data, as oposed to the trades-list start date - :param limit: Limit amount of candles - :return: ohlcv data (as returned by ccxt.fetch_ohlcv) - """ - return self._api.build_ohlcv(trades, timeframe, since, limit) - def is_exchange_bad(exchange_name: str) -> bool: return exchange_name in BAD_EXCHANGES diff --git a/freqtrade/utils.py b/freqtrade/utils.py index 48734883c..e77b76208 100644 --- a/freqtrade/utils.py +++ b/freqtrade/utils.py @@ -97,7 +97,7 @@ def start_download_data(args: Dict[str, Any]) -> None: # Convert downloaded trade data to different timeframes convert_trades_to_ohlcv( - exchange, pairs=config["pairs"], timeframes=config["timeframes"], + pairs=config["pairs"], timeframes=config["timeframes"], datadir=Path(config['datadir']), timerange=timerange, erase=config.get("erase")) else: pairs_not_available = refresh_backtest_ohlcv_data(