Add conversion from trades to ohlcv at different intervals
This commit is contained in:
parent
9584629f50
commit
476adf872a
@ -86,7 +86,7 @@ def load_trades_file(datadir: Optional[Path], pair: str,
|
|||||||
timerange: Optional[TimeRange] = None) -> List[Dict]:
|
timerange: Optional[TimeRange] = None) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Load a pair from file, either .json.gz or .json
|
Load a pair from file, either .json.gz or .json
|
||||||
:return: tickerlist or empty list if unsuccesful
|
:return: tradelist or empty list if unsuccesful
|
||||||
"""
|
"""
|
||||||
filename = pair_trades_filename(datadir, pair)
|
filename = pair_trades_filename(datadir, pair)
|
||||||
tradesdata = misc.file_load_json(filename)
|
tradesdata = misc.file_load_json(filename)
|
||||||
@ -373,11 +373,10 @@ def download_trades_history(datadir: Optional[Path],
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def refresh_backtest_trades_data(exchange: Exchange, pairs: List[str], timeframes: List[str],
|
def refresh_backtest_trades_data(exchange: Exchange, pairs: List[str], datadir: Path,
|
||||||
datadir: Path, timerange: TimeRange,
|
timerange: TimeRange, erase=False) -> List[str]:
|
||||||
erase=False) -> List[str]:
|
|
||||||
"""
|
"""
|
||||||
Refresh stored trades data .
|
Refresh stored trades data.
|
||||||
Used by freqtrade download-data
|
Used by freqtrade download-data
|
||||||
:return: Pairs not available
|
:return: Pairs not available
|
||||||
"""
|
"""
|
||||||
@ -387,7 +386,6 @@ def refresh_backtest_trades_data(exchange: Exchange, pairs: List[str], timeframe
|
|||||||
pairs_not_available.append(pair)
|
pairs_not_available.append(pair)
|
||||||
logger.info(f"Skipping pair {pair}...")
|
logger.info(f"Skipping pair {pair}...")
|
||||||
continue
|
continue
|
||||||
# for ticker_interval in timeframes:
|
|
||||||
|
|
||||||
dl_file = pair_trades_filename(datadir, pair)
|
dl_file = pair_trades_filename(datadir, pair)
|
||||||
if erase and dl_file.exists():
|
if erase and dl_file.exists():
|
||||||
@ -402,6 +400,23 @@ def refresh_backtest_trades_data(exchange: Exchange, pairs: List[str], timeframe
|
|||||||
return pairs_not_available
|
return pairs_not_available
|
||||||
|
|
||||||
|
|
||||||
|
def convert_trades_to_ohlcv(exchange: Exchange, pairs: List[str], timeframes: List[str],
|
||||||
|
datadir: Path, timerange: TimeRange, erase=False) -> None:
|
||||||
|
"""
|
||||||
|
Convert stored trades data to ohlcv data
|
||||||
|
"""
|
||||||
|
for pair in pairs:
|
||||||
|
trades = load_trades_file(datadir, pair)
|
||||||
|
for timeframe in timeframes:
|
||||||
|
ohlcv_file = pair_data_filename(datadir, pair, timeframe)
|
||||||
|
if erase and ohlcv_file.exists():
|
||||||
|
logger.info(f'Deleting existing data for pair {pair}, interval {timeframe}.')
|
||||||
|
ohlcv_file.unlink()
|
||||||
|
ohlcv = exchange.build_ohlcv(trades, timeframe)
|
||||||
|
# Store ohlcv
|
||||||
|
store_tickerdata_file(datadir, pair, timeframe, data=ohlcv)
|
||||||
|
|
||||||
|
|
||||||
def get_timeframe(data: Dict[str, DataFrame]) -> Tuple[arrow.Arrow, arrow.Arrow]:
|
def get_timeframe(data: Dict[str, DataFrame]) -> Tuple[arrow.Arrow, arrow.Arrow]:
|
||||||
"""
|
"""
|
||||||
Get the maximum timeframe for the given backtest data
|
Get the maximum timeframe for the given backtest data
|
||||||
|
@ -8,7 +8,8 @@ import arrow
|
|||||||
from freqtrade import OperationalException
|
from freqtrade import OperationalException
|
||||||
from freqtrade.configuration import Configuration, TimeRange
|
from freqtrade.configuration import Configuration, TimeRange
|
||||||
from freqtrade.configuration.directory_operations import create_userdata_dir
|
from freqtrade.configuration.directory_operations import create_userdata_dir
|
||||||
from freqtrade.data.history import (refresh_backtest_ohlcv_data,
|
from freqtrade.data.history import (convert_trades_to_ohlcv,
|
||||||
|
refresh_backtest_ohlcv_data,
|
||||||
refresh_backtest_trades_data)
|
refresh_backtest_trades_data)
|
||||||
from freqtrade.exchange import available_exchanges, ccxt_exchanges
|
from freqtrade.exchange import available_exchanges, ccxt_exchanges
|
||||||
from freqtrade.resolvers import ExchangeResolver
|
from freqtrade.resolvers import ExchangeResolver
|
||||||
@ -96,6 +97,11 @@ def start_download_data(args: Dict[str, Any]) -> None:
|
|||||||
dl_path=Path(config['datadir']), timerange=timerange, erase=config.get("erase"))
|
dl_path=Path(config['datadir']), timerange=timerange, erase=config.get("erase"))
|
||||||
else:
|
else:
|
||||||
pairs_not_available = refresh_backtest_trades_data(
|
pairs_not_available = refresh_backtest_trades_data(
|
||||||
|
exchange, pairs=config["pairs"], datadir=Path(config['datadir']),
|
||||||
|
timerange=timerange, erase=config.get("erase"))
|
||||||
|
|
||||||
|
# Convert downloaded trade data to different timeframes
|
||||||
|
convert_trades_to_ohlcv(
|
||||||
exchange, pairs=config["pairs"], timeframes=config["timeframes"],
|
exchange, pairs=config["pairs"], timeframes=config["timeframes"],
|
||||||
datadir=Path(config['datadir']), timerange=timerange, erase=config.get("erase"))
|
datadir=Path(config['datadir']), timerange=timerange, erase=config.get("erase"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user