async def collector_database(collector): database = backtesting_data.DataBase(collector.file_path) try: await database.initialize() yield database finally: await database.stop()
async def get_database(data_file=DATA_FILE1): database_file = os.path.join("tests", "static", data_file) database = backtesting_data.DataBase(database_file) try: await database.initialize() yield database finally: await database.stop()
async def get_temp_empty_database(): database_name = "temp_empty_database" database = backtesting_data.DataBase(database_name) try: await database.initialize() yield database finally: await database.stop() os.remove(database_name)
async def test_invalid_file(): file_name = "plop" db = backtesting_data.DataBase(file_name) try: await db.initialize() assert not await db.check_table_exists(enums.ExchangeDataTables.KLINE) with pytest.raises(sqlite3.OperationalError): await db.check_table_not_empty(enums.ExchangeDataTables.KLINE) finally: await db.stop() os.remove(file_name)
async def get_file_description(database_file): database = None try: database = data.DataBase(database_file) await database.initialize() description = await get_database_description(database) except (errors.DataBaseNotExists, TypeError): description = None finally: if database is not None: await database.stop() return description
async def convert(self) -> bool: try: self.database = backtesting_data.DataBase( path.join(backtesting_constants.BACKTESTING_FILE_PATH, self.converted_file)) await self.database.initialize() await self._create_description() for time_frame in self.time_frames: await self._convert_ohlcv(time_frame) return True except Exception as e: self.logger.exception(e, True, f"Error while converting data file: {e}") return False finally: if self.database is not None: await self.database.stop()
def load_database(self) -> None: file_path = self.adapt_file_path_if_necessary() if not self.database: self.database = data.DataBase(file_path)
def create_database(self) -> None: if not self.database: self.database = data.DataBase(self.file_path)