Skip to content

Commit

Permalink
Add lock to liquiate
Browse files Browse the repository at this point in the history
  • Loading branch information
math-a3k committed Apr 20, 2024
1 parent 1d3c856 commit 2106d52
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,13 +1568,23 @@ def off(self):
return True

def liquidate(self):
for bot in self.bots.all():
if bot.status == TraderoBot.Status.SELLING:
bot.sell()
bot.off()
elif bot.status == TraderoBot.Status.BUYING:
bot.off()
return True
cache_key = f"{settings.BOTS_UPDATE_GROUP_KEY}_{self.pk}"
if not cache.get(cache_key, False) or "pytest" in sys.modules:
cache.set(cache_key, True, 60)
for bot in self.bots.all():
if bot.status == TraderoBot.Status.SELLING:
bot.sell()
bot.off()
elif bot.status == TraderoBot.Status.BUYING:
bot.off()
return True
else: # pragma: no cover
message = (
f"GROUP [{self.pk}] {self}: Other process updating bots for "
"the group is running, please wait."
)
logger.warning(message)
return message

def jump(self, to_symbol):
for bot in self.bots.all():
Expand Down

0 comments on commit 2106d52

Please sign in to comment.