mirror of
https://github.com/aljazceru/hummingbot-dashboard.git
synced 2025-12-28 10:44:20 +01:00
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import asyncio
|
|
from typing import List
|
|
|
|
from tqdm import tqdm
|
|
|
|
from hummingbot.data_feed.candles_feed.candles_factory import CandlesFactory, CandlesConfig
|
|
|
|
|
|
async def aget_candles_list(candles_configs: List[CandlesConfig]):
|
|
tasks = [aget_candles(config.connector, config.trading_pair, config.interval, config.max_records) for config in candles_configs]
|
|
return await asyncio.gather(*tasks)
|
|
|
|
|
|
async def aget_candles(connector_name: str, trading_pair: str, interval: str, max_records: int):
|
|
candles = CandlesFactory.get_candle(CandlesConfig(connector=connector_name,
|
|
trading_pair=trading_pair,
|
|
interval=interval, max_records=max_records))
|
|
candles.start()
|
|
|
|
pbar = tqdm(total=candles._candles.maxlen)
|
|
while not candles.is_ready:
|
|
await asyncio.sleep(1)
|
|
awaited_records = candles._candles.maxlen - len(candles._candles)
|
|
pbar.update(candles._candles.maxlen - awaited_records - pbar.n)
|
|
|
|
pbar.close()
|
|
df = candles.candles_df
|
|
candles.stop()
|
|
return df
|
|
|
|
|
|
async def adownload_candles(connector_name: str, trading_pair: str, interval: str, max_records: int, download_path: str):
|
|
candles = CandlesFactory.get_candle(CandlesConfig(connector_name, trading_pair, interval, max_records))
|
|
candles.start()
|
|
while not candles.is_ready:
|
|
print(f"Candles not ready yet! Missing {candles._candles.maxlen - len(candles._candles)}")
|
|
await asyncio.sleep(1)
|
|
df = candles.candles_df
|
|
df.to_csv(download_path, index=False)
|
|
candles.stop()
|
|
|