Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the bets so that we map all the investments per vote #367

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/merge_rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Check Branch'

on:
pull_request:

jobs:
check_branch:
runs-on: ubuntu-latest
steps:
- name: Check branch
if: github.base_ref == 'main' && github.head_ref != 'develop'
run: |
echo "ERROR: You can only merge to main from develop."
exit 1
10 changes: 6 additions & 4 deletions packages/valory/skills/decision_maker_abci/behaviours/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,14 @@ def check_balance(self) -> WaitableConditionType:
def update_bet_transaction_information(self) -> None:
"""Get whether the bet's invested amount should be updated."""
sampled_bet = self.sampled_bet
# Update the bet's invested amount, the new bet amount is added to previously invested amount
sampled_bet.invested_amount += self.synchronized_data.bet_amount

# Update the bet's invested amount
updated = sampled_bet.update_investments(self.synchronized_data.bet_amount)
if not updated:
self.context.logger.error("Could not update the investments!")

# Update bet transaction timestamp
sampled_bet.processed_timestamp = self.synced_timestamp
# update no of bets made
sampled_bet.n_bets += 1
# Update Queue number for priority logic
sampled_bet.queue_status = sampled_bet.queue_status.next_status()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ def _update_selected_bet(
self.context.logger.info(
f"with the timestamp:{datetime.fromtimestamp(active_sampled_bet.processed_timestamp)}"
)
if prediction_response is not None:
active_sampled_bet.n_bets += 1
Comment on lines -521 to -522
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyberosa this is now automatically calculated from the stored investments. Where should the investments be updated in the benchmarking flow?


self.store_bets()

Expand Down
60 changes: 57 additions & 3 deletions packages/valory/skills/market_manager_abci/bets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from typing import Any, Dict, List, Optional, Union


YES = "yes"
NO = "no"
P_YES_FIELD = "p_yes"
P_NO_FIELD = "p_no"
CONFIDENCE_FIELD = "confidence"
Expand Down Expand Up @@ -136,18 +138,59 @@ class Bet:
prediction_response: PredictionResponse = dataclasses.field(
default_factory=get_default_prediction_response
)
invested_amount: int = 0
position_liquidity: int = 0
potential_net_profit: int = 0
processed_timestamp: int = 0
n_bets: int = 0
queue_status: QueueStatus = QueueStatus.FRESH
# a mapping from vote to investment amounts
investments: Dict[str, List[int]] = dataclasses.field(default_factory=dict)

@property
def yes_investments(self) -> List[int]:
"""Get the yes investments."""
return self.investments[self.yes]

@property
def no_investments(self) -> List[int]:
"""Get the no investments."""
return self.investments[self.no]

@property
def n_yes_bets(self) -> int:
"""Get the number of yes bets."""
return len(self.yes_investments)

@property
def n_no_bets(self) -> int:
"""Get the number of no bets."""
return len(self.no_investments)

@property
def n_bets(self) -> int:
"""Get the number of bets."""
return self.n_yes_bets + self.n_no_bets

@property
def invested_amount_yes(self) -> int:
"""Get the amount invested in yes bets."""
return sum(self.yes_investments)

@property
def invested_amount_no(self) -> int:
"""Get the amount invested in no bets."""
return sum(self.no_investments)

@property
def invested_amount(self) -> int:
"""Get the amount invested in bets."""
return self.invested_amount_yes + self.invested_amount_no

def __post_init__(self) -> None:
"""Post initialization to adjust the values."""
self._validate()
self._cast()
self._check_usefulness()
self.investments = {self.yes: [], self.no: []}

def __lt__(self, other: "Bet") -> bool:
"""Implements less than operator."""
Expand Down Expand Up @@ -225,7 +268,7 @@ def _get_binary_outcome(self, no: bool) -> str:
"""Get an outcome only if it is binary."""
if self.outcomeSlotCount == BINARY_N_SLOTS:
return self.get_outcome(int(no))
requested_outcome = "no" if no else "yes"
requested_outcome = NO if no else YES
error = (
f"A {requested_outcome!r} outcome is only available for binary questions."
)
Expand All @@ -241,6 +284,17 @@ def no(self) -> str:
"""Return the "no" outcome."""
return self._get_binary_outcome(True)

def update_investments(self, amount: int) -> bool:
"""Get the investments for the current vote type."""
vote = self.prediction_response.vote
if vote is None:
return False

vote_name = self.get_outcome(vote)
to_update = self.investments[vote_name]
to_update.append(amount)
return True

def update_market_info(self, bet: "Bet") -> None:
"""Update the bet's market information."""
if (
Expand Down