def load_data(self): """""" self.output("开始加载历史数据") if self.mode == BacktestingMode.BAR: s = ( DbBarData.select() .where( (DbBarData.vt_symbol == self.vt_symbol) & (DbBarData.interval == self.interval) & (DbBarData.datetime >= self.start) & (DbBarData.datetime <= self.end) ) .order_by(DbBarData.datetime) ) self.history_data = [db_bar.to_bar() for db_bar in s] else: s = ( DbTickData.select() .where( (DbTickData.vt_symbol == self.vt_symbol) & (DbTickData.datetime >= self.start) & (DbTickData.datetime <= self.end) ) .order_by(DbTickData.datetime) ) self.history_data = [db_tick.to_tick() for db_tick in s] self.output(f"历史数据加载完成,数据量:{len(self.history_data)}")
def load_tick_data(vt_symbol: str, start: datetime, end: datetime): """""" s = (DbTickData.select().where((DbTickData.vt_symbol == vt_symbol) & (DbTickData.datetime >= start) & (DbTickData.datetime <= end)).order_by( DbTickData.datetime)) data = [db_tick.db_tick() for db_tick in s] return data
def load_tick(self, vt_symbol: str, days: int, callback: Callable): """""" end = datetime.now() start = end - timedelta(days) s = (DbTickData.select().where((DbBarData.vt_symbol == vt_symbol) & (DbBarData.datetime >= start) & (DbBarData.datetime <= end)).order_by( DbBarData.datetime)) for tick in s: callback(tick)
def load_tick(self, vt_symbol: str, days: int, callback: Callable): """""" end = datetime.now() start = end - timedelta(days) s = ( DbTickData.select() .where( (DbBarData.vt_symbol == vt_symbol) & (DbBarData.datetime >= start) & (DbBarData.datetime <= end) ) .order_by(DbBarData.datetime) ) for tick in s: callback(tick)