cleanup and better docstring
This commit is contained in:
parent
023eb19615
commit
13e80e449c
@ -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]))
|
||||
|
@ -93,7 +93,6 @@ def load_trades_file(datadir: Path, pair: str,
|
||||
if not tradesdata:
|
||||
return []
|
||||
|
||||
# TODO: trim trades based on timerange... ?
|
||||
return tradesdata
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user