From de956ada336447fe7a05167fb64d840850f64ebd Mon Sep 17 00:00:00 2001 From: Keshav Mishra Date: Fri, 6 Dec 2024 22:17:23 +0530 Subject: [PATCH] update: bets file path for multi bets --- .../skills/market_manager_abci/behaviours.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/valory/skills/market_manager_abci/behaviours.py b/packages/valory/skills/market_manager_abci/behaviours.py index a4e29fde..c895a1b9 100644 --- a/packages/valory/skills/market_manager_abci/behaviours.py +++ b/packages/valory/skills/market_manager_abci/behaviours.py @@ -47,6 +47,7 @@ BETS_FILENAME = "bets.json" +MULTI_BETS_FILENAME = "multi_bets.json" READ_MODE = "r" WRITE_MODE = "w" @@ -58,6 +59,7 @@ def __init__(self, **kwargs: Any) -> None: """Initialize `BetsManagerBehaviour`.""" super().__init__(**kwargs) self.bets: List[Bet] = [] + self.multi_bets_filepath: str = self.params.store_path / MULTI_BETS_FILENAME self.bets_filepath: str = self.params.store_path / BETS_FILENAME def store_bets(self) -> None: @@ -68,14 +70,14 @@ def store_bets(self) -> None: return try: - with open(self.bets_filepath, WRITE_MODE) as bets_file: + with open(self.multi_bets_filepath, WRITE_MODE) as bets_file: try: bets_file.write(serialized) return except (IOError, OSError): - err = f"Error writing to file {self.bets_filepath!r}!" + err = f"Error writing to file {self.multi_bets_filepath!r}!" except (FileNotFoundError, PermissionError, OSError): - err = f"Error opening file {self.bets_filepath!r} in write mode!" + err = f"Error opening file {self.multi_bets_filepath!r} in write mode!" self.context.logger.error(err) @@ -83,29 +85,33 @@ def read_bets(self) -> None: """Read the bets from the agent's data dir as JSON.""" self.bets = [] - if not os.path.isfile(self.bets_filepath): + _read_path = self.multi_bets_filepath + if not os.path.isfile(_read_path): self.context.logger.warning( - f"No stored bets file was detected in {self.bets_filepath}. Assuming bets are empty." + f"No stored bets file was detected in {self.multi_bets_filepath}. Assuming trader is being run for the first time in multi-bets mode." + ) + _read_path = self.bets_filepath + elif not os.path.isfile(_read_path): + self.context.logger.warning( + f"No stored bets file was detected in {self.bets_filepath}. Assuming bets are empty" ) return try: - with open(self.bets_filepath, READ_MODE) as bets_file: + with open(_read_path, READ_MODE) as bets_file: try: self.bets = json.load(bets_file, cls=BetsDecoder) return except (JSONDecodeError, TypeError): - err = ( - f"Error decoding file {self.bets_filepath!r} to a list of bets!" - ) + err = f"Error decoding file {_read_path!r} to a list of bets!" except (FileNotFoundError, PermissionError, OSError): - err = f"Error opening file {self.bets_filepath!r} in read mode!" + err = f"Error opening file {_read_path!r} in read mode!" self.context.logger.error(err) def hash_stored_bets(self) -> str: """Get the hash of the stored bets' file.""" - return IPFSHashOnly.hash_file(self.bets_filepath) + return IPFSHashOnly.hash_file(self.multi_bets_filepath) class UpdateBetsBehaviour(BetsManagerBehaviour, QueryingBehaviour):