[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 self.mode == BacktestingMode.BAR: if not self.end:
self.history_data = load_bar_data( self.end = datetime.now()
self.symbol,
self.exchange,
self.interval,
self.start,
self.end
)
else:
self.history_data = load_tick_data(
self.symbol,
self.exchange,
self.start,
self.end
)
# 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:
data = load_bar_data(
self.symbol,
self.exchange,
self.interval,
start,
end
)
else:
data = load_tick_data(
self.symbol,
self.exchange,
start,
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):