Skip to content

Commit

Permalink
Option to get market resolution from reality response (HexBytes) (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Oct 9, 2024
1 parent 142e434 commit 2335bae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions prediction_market_agent_tooling/markets/omen/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,38 @@ def __repr__(self) -> str:
def is_binary(self) -> bool:
return len(self.outcomes) == 2

@property
def boolean_outcome(self) -> bool:
def boolean_outcome_from_answer(self, answer: HexBytes) -> bool:
if not self.is_binary:
raise ValueError(
f"Market with title {self.title} is not binary, it has {len(self.outcomes)} outcomes."
)
outcome: str = self.outcomes[answer.as_int()]
return get_boolean_outcome(outcome)

@property
def boolean_outcome(self) -> bool:
if not self.is_resolved_with_valid_answer:
raise ValueError(f"Bet with title {self.title} is not resolved.")
return self.boolean_outcome_from_answer(
check_not_none(
self.currentAnswer, "Can not be None if `is_resolved_with_valid_answer`"
)
)

outcome: str = self.outcomes[check_not_none(self.answer_index)]
return get_boolean_outcome(outcome)
def get_resolution_enum_from_answer(self, answer: HexBytes) -> Resolution:
if self.boolean_outcome_from_answer(answer):
return Resolution.YES
else:
return Resolution.NO

def get_resolution_enum(self) -> t.Optional[Resolution]:
if not self.is_resolved_with_valid_answer:
return None
if self.boolean_outcome:
return Resolution.YES
else:
return Resolution.NO
return self.get_resolution_enum_from_answer(
check_not_none(
self.currentAnswer, "Can not be None if `is_resolved_with_valid_answer`"
)
)

@property
def url(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prediction-market-agent-tooling"
version = "0.50.1"
version = "0.51.0"
description = "Tools to benchmark, deploy and monitor prediction market agents."
authors = ["Gnosis"]
readme = "README.md"
Expand Down

0 comments on commit 2335bae

Please sign in to comment.