Skip to content

Commit

Permalink
update: bet sampling process
Browse files Browse the repository at this point in the history
  • Loading branch information
keshav1998 committed Nov 28, 2024
1 parent 423a082 commit 5090305
Showing 1 changed file with 48 additions and 25 deletions.
73 changes: 48 additions & 25 deletions packages/valory/skills/decision_maker_abci/behaviours/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,55 @@ def _sampled_bet_idx(self, bets: List[Bet]) -> int:
:return: the index of the sampled bet, out of all the available bets, not only the given ones.
"""

# Filter out all the bets with the smallest queue number
least_queue_number = min([bet.queue_no for bet in bets])
priority_bets = [bet for bet in bets if bet.queue_no == least_queue_number]

# Filter out all the bets that have a processed_timestamp == 0
new_in_priority_bets = [bet for bet in bets if bet.processed_timestamp == 0]

if new_in_priority_bets:
# Order the list in Decreasing order of liquidity
new_in_priority_bets.sort(
key=lambda bet: (bet.scaledLiquidityMeasure, bet.openingTimestamp),
reverse=True,
)
return self.bets.index(new_in_priority_bets[0])
max_queue_number = max([bet.queue_no for bet in bets])

if max_queue_number == 0:
# Search if any bet is unprocessed
new_in_priority_bets = [bet for bet in bets if bet.processed_timestamp == 0]

if new_in_priority_bets:
# Order the list in Decreasing order of liquidity
new_in_priority_bets.sort(
key=lambda bet: (bet.scaledLiquidityMeasure, bet.openingTimestamp),
reverse=True,
)
return self.bets.index(new_in_priority_bets[0])
else:
# All bets have been processed once, bets can be sampled based on the priority logic
bets.sort(
key=lambda bet: (
bet.invested_amount,
-bet.processed_timestamp, # Increasing order of processed_timestamp
bet.scaledLiquidityMeasure,
bet.openingTimestamp,
),
reverse=True,
)
return self.bets.index(bets[0])
else:
# Order first in Decreasing order of invested_amount
priority_bets.sort(
key=lambda bet: (
bet.invested_amount,
-bet.processed_timestamp, # Increasing order of processed_timestamp
bet.scaledLiquidityMeasure,
bet.openingTimestamp,
),
reverse=True,
)
return self.bets.index(priority_bets[0])
# Check if all bets have processed_timestamp == 0
all_bets_not_processed = all(bet.processed_timestamp == 0 for bet in bets)

if all_bets_not_processed:
# Current processable list of bets have not been processed yet
# Order the list in Decreasing order of liquidity
bets.sort(
key=lambda bet: (bet.scaledLiquidityMeasure, bet.openingTimestamp),
reverse=True,
)
return self.bets.index(bets[0])
else:
# Bets available for rebetting and can be prioritized based on the priority logic
bets.sort(
key=lambda bet: (
bet.invested_amount,
-bet.processed_timestamp, # Increasing order of processed_timestamp
bet.scaledLiquidityMeasure,
bet.openingTimestamp,
),
reverse=True,
)
return self.bets.index(bets[0])

def _sample(self) -> Optional[int]:
"""Sample a bet, mark it as processed, and return its index."""
Expand Down

0 comments on commit 5090305

Please sign in to comment.