Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collector metadata #1184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ async def start(self):

await self.check_timestamps()

# create description
await self._create_description()

self.total_steps = len(self.time_frames) * len(self.symbols)
self.in_progress = True

Expand All @@ -87,6 +84,8 @@ async def start(self):
f"[{time_frame_index}/{len(self.time_frames)}] Collecting {symbol} history on {time_frame}...")
await self.get_ohlcv_history(self.exchange_name, symbol, time_frame)
await self.get_kline_history(self.exchange_name, symbol, time_frame)
# create description
await self._create_description()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also move this line in bot_snapshot_with_history_collector.py please ?

except Exception as err:
await self.database.stop()
should_stop_database = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import octobot_commons.databases as databases
import octobot_commons.symbols as commons_symbols
import octobot_backtesting.data as data
import octobot_backtesting.enums as enums
import octobot_backtesting.errors as errors
import octobot_trading.enums as trading_enums
Expand Down Expand Up @@ -53,6 +54,8 @@ async def data_collector(exchange_name, tentacles_setup_config, symbols, time_fr
os.remove(collector_instance.file_path)
if collector_instance.temp_file_path and os.path.isfile(collector_instance.temp_file_path):
os.remove(collector_instance.temp_file_path)
if collector_instance.metadata_file_path and os.path.isfile(collector_instance.metadata_file_path):
os.remove(collector_instance.metadata_file_path)


@contextlib.asynccontextmanager
Expand All @@ -78,9 +81,11 @@ async def test_collect_valid_data():
assert collector.exchange_manager is None
assert isinstance(collector.exchange, tentacles_exchanges.Binance)
assert collector.file_path is not None
assert collector.metadata_file_path is not None
assert collector.temp_file_path is not None
assert not os.path.isfile(collector.temp_file_path)
assert os.path.isfile(collector.file_path)
assert os.path.isfile(collector.metadata_file_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

async with collector_database(collector) as database:
ohlcv = await database.select(enums.ExchangeDataTables.OHLCV)
# use > to take into account new possible candles since collect max time is not specified
Expand All @@ -101,7 +106,10 @@ async def test_collect_invalid_data():
assert collector.exchange_manager is None
assert collector.exchange is not None
assert collector.file_path is not None
assert collector.metadata_file_path is not None
assert collector.temp_file_path is not None
assert not os.path.isfile(collector.file_path)
assert not os.path.isfile(collector.metadata_file_path)
assert not os.path.isfile(collector.temp_file_path)


Expand All @@ -116,8 +124,10 @@ async def test_collect_valid_date_range():
assert collector.exchange_manager is None
assert isinstance(collector.exchange, tentacles_exchanges.Binance)
assert collector.file_path is not None
assert collector.metadata_file_path is not None
assert collector.temp_file_path is not None
assert os.path.isfile(collector.file_path)
assert os.path.isfile(collector.metadata_file_path)
assert not os.path.isfile(collector.temp_file_path)
async with collector_database(collector) as database:
ohlcv = await database.select(enums.ExchangeDataTables.OHLCV)
Expand Down Expand Up @@ -146,8 +156,10 @@ async def test_collect_invalid_date_range():
assert collector.exchange_manager is None
assert isinstance(collector.exchange, tentacles_exchanges.Binance)
assert collector.file_path is not None
assert collector.metadata_file_path is not None
assert collector.temp_file_path is not None
assert not os.path.isfile(collector.file_path)
assert not os.path.isfile(collector.metadata_file_path)
assert not os.path.isfile(collector.temp_file_path)


Expand All @@ -164,16 +176,19 @@ async def test_collect_multi_pair():
assert collector.exchange_manager is None
assert isinstance(collector.exchange, tentacles_exchanges.Binance)
assert collector.file_path is not None
assert collector.metadata_file_path is not None
assert collector.temp_file_path is not None
assert not os.path.isfile(collector.temp_file_path)
assert os.path.isfile(collector.metadata_file_path)
assert os.path.isfile(collector.file_path)
async with collector_database(collector) as database:
ohlcv = await database.select(enums.ExchangeDataTables.OHLCV)
# use > to take into account new possible candles since collect max time is not specified
assert len(ohlcv) > 19316
h_ohlcv = await database.select(enums.ExchangeDataTables.OHLCV, time_frame="4h")
assert len(h_ohlcv) == len(symbols) * BINANCE_MAX_CANDLES_COUNT
symbols_description = json.loads((await database.select(enums.DataTables.DESCRIPTION))[0][3])
symbols_description = data.get_metadata_description(collector.metadata_file_path)\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
symbols_description = data.get_metadata_description(collector.metadata_file_path)\
symbols_description = data.get_metadata_description(collector.file_path)\

[enums.DataFormatKeys.SYMBOLS.value]
assert all(symbol in symbols_description for symbol in symbols)
eth_btc_ohlcv = await database.select(enums.ExchangeDataTables.OHLCV, symbol="ETH/BTC")
assert len(eth_btc_ohlcv) > 6760
Expand All @@ -200,4 +215,5 @@ async def stop_soon():
assert collector.finished
assert collector.exchange_manager is None
assert not os.path.isfile(collector.temp_file_path)
assert not os.path.isfile(collector.metadata_file_path)
assert not os.path.isfile(collector.file_path)