diff --git a/prediction_market_agent_tooling/markets/data_models.py b/prediction_market_agent_tooling/markets/data_models.py index 68cc5e4f..1b04a443 100644 --- a/prediction_market_agent_tooling/markets/data_models.py +++ b/prediction_market_agent_tooling/markets/data_models.py @@ -235,6 +235,9 @@ class ManifoldBetFees(BaseModel): liquidityFee: Decimal creatorFee: Decimal + def get_total(self) -> Decimal: + return sum([self.platformFee, self.liquidityFee, self.creatorFee]) + class ManifoldBet(BaseModel): """ @@ -257,6 +260,19 @@ class ManifoldBet(BaseModel): createdTime: datetime outcome: str + def get_profit(self, market_outcome: bool) -> ProfitAmount: + outcome_bool = self.outcome == "YES" + profit = ( + self.shares - self.amount + if outcome_bool == market_outcome + else -self.amount + ) + profit -= self.fees.get_total() + return ProfitAmount( + amount=profit, + currency=Currency.Mana, + ) + class ManifoldContractMetric(BaseModel): """ diff --git a/prediction_market_agent_tooling/markets/manifold.py b/prediction_market_agent_tooling/markets/manifold.py index c5783a21..ea0ecf62 100644 --- a/prediction_market_agent_tooling/markets/manifold.py +++ b/prediction_market_agent_tooling/markets/manifold.py @@ -12,7 +12,6 @@ ManifoldContractMetric, ManifoldMarket, ManifoldUser, - ProfitAmount, ResolvedBet, ) @@ -124,19 +123,15 @@ def manifold_to_generic_resolved_bet(bet: ManifoldBet) -> ResolvedBet: if not market.resolutionTime: raise ValueError(f"Market {market.id} has no resolution time.") - # Get the profit for this bet from the corresponding position - positions = get_market_positions(market.id, bet.userId) - bet_position = next(p for p in positions if p.contractId == bet.contractId) - profit = bet_position.profit - + market_outcome = market.resolution == "YES" return ResolvedBet( amount=BetAmount(amount=bet.amount, currency=Currency.Mana), outcome=bet.outcome == "YES", created_time=bet.createdTime, market_question=market.question, - market_outcome=market.resolution == "YES", + market_outcome=market_outcome, resolved_time=market.resolutionTime, - profit=ProfitAmount(amount=profit, currency=Currency.Mana), + profit=bet.get_profit(market_outcome=market_outcome), )