[Add] progress bar when loading history data

This commit is contained in:
vn.py 2019-05-29 17:05:39 +08:00
parent 6018c43a32
commit 69d2dd37be

View File

@ -1,5 +1,5 @@
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime from datetime import date, datetime, timedelta
from typing import Callable from typing import Callable
from itertools import product from itertools import product
from functools import lru_cache from functools import lru_cache
@ -211,22 +211,44 @@ class BacktestingEngine:
"""""" """"""
self.output("开始加载历史数据") self.output("开始加载历史数据")
if not self.end:
self.end = datetime.now()
# Load 30 days of data each time and allow for progress update
progress_delta = timedelta(days=30)
total_delta = self.end - self.start
start = self.start
end = self.start + progress_delta
progress = 0
while start < self.end:
if self.mode == BacktestingMode.BAR: if self.mode == BacktestingMode.BAR:
self.history_data = load_bar_data( data = load_bar_data(
self.symbol, self.symbol,
self.exchange, self.exchange,
self.interval, self.interval,
self.start, start,
self.end end
) )
else: else:
self.history_data = load_tick_data( data = load_tick_data(
self.symbol, self.symbol,
self.exchange, self.exchange,
self.start, start,
self.end end
) )
self.history_data.extend(data)
progress += progress_delta / total_delta
progress = min(progress, 1)
progress_bar = "#" * int(progress * 10)
self.output(f"加载进度:{progress_bar} [{progress:.0%}]")
start = end
end += progress_delta
self.output(f"历史数据加载完成,数据量:{len(self.history_data)}") self.output(f"历史数据加载完成,数据量:{len(self.history_data)}")
def run_backtesting(self): def run_backtesting(self):