Skip to content

Commit

Permalink
Fix manifold bet profit calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
evangriffiths committed Feb 18, 2024
1 parent b04007c commit af9fca8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 16 additions & 0 deletions prediction_market_agent_tooling/markets/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
11 changes: 3 additions & 8 deletions prediction_market_agent_tooling/markets/manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
ManifoldContractMetric,
ManifoldMarket,
ManifoldUser,
ProfitAmount,
ResolvedBet,
)

Expand Down Expand Up @@ -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),
)


Expand Down

0 comments on commit af9fca8

Please sign in to comment.