Skip to content

Commit

Permalink
Merge pull request #32 from hummingbot/fix/bot_metrics_collection
Browse files Browse the repository at this point in the history
(feat) add update bots on loop
  • Loading branch information
nikspz authored Aug 30, 2024
2 parents ac36c29 + 8e41337 commit d523b8b
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions services/bots_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,30 @@ def stop_update_active_bots_loop(self):
self._update_bots_task.cancel()
self._update_bots_task = None

async def update_active_bots(self, sleep_time=10):
active_hbot_containers = self.get_active_containers()
# Remove bots that are no longer active
for bot in list(self.active_bots):
if bot not in active_hbot_containers:
del self.active_bots[bot]

# Add new bots or update existing ones
for bot in active_hbot_containers:
if bot not in self.active_bots:
hbot_listener = HummingbotPerformanceListener(host=self.broker_host, port=self.broker_port,
username=self.broker_username,
password=self.broker_password,
bot_id=bot)
hbot_listener.start()
self.active_bots[bot] = {
"bot_name": bot,
"broker_client": BotCommands(host=self.broker_host, port=self.broker_port,
username=self.broker_username, password=self.broker_password,
bot_id=bot),
"broker_listener": hbot_listener,
}
await asyncio.sleep(sleep_time)
async def update_active_bots(self, sleep_time=1):
while True:
active_hbot_containers = self.get_active_containers()
# Remove bots that are no longer active
for bot in list(self.active_bots):
if bot not in active_hbot_containers:
del self.active_bots[bot]

# Add new bots or update existing ones
for bot in active_hbot_containers:
if bot not in self.active_bots:
hbot_listener = HummingbotPerformanceListener(host=self.broker_host, port=self.broker_port,
username=self.broker_username,
password=self.broker_password,
bot_id=bot)
hbot_listener.start()
self.active_bots[bot] = {
"bot_name": bot,
"broker_client": BotCommands(host=self.broker_host, port=self.broker_port,
username=self.broker_username, password=self.broker_password,
bot_id=bot),
"broker_listener": hbot_listener,
}
await asyncio.sleep(sleep_time)

# Interact with a specific bot
def start_bot(self, bot_name, **kwargs):
Expand Down

0 comments on commit d523b8b

Please sign in to comment.