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

Allow dynamic bet amounts based on market - remove 'adjust_bet_amount' #430

Merged
merged 17 commits into from
Sep 25, 2024

Conversation

evangriffiths
Copy link
Contributor

@evangriffiths evangriffiths commented Sep 24, 2024

An alternative to #425

Fixes #377

How does it look to use? e.g.

class MyTraderAgent(DeployableTraderAgent):
    def get_betting_strategy(
        self, market_type: MarketType, market: AgentMarket
    ) -> BettingStrategy:
        user_id = APIKeys().bet_from_address

        total_amount = market.get_user_balance(user_id=user_id) * 0.1
        if existing_position := market.get_position(user_id=user_id):
            total_amount += existing_position.total_amount.amount

        return MaxAccuracyBettingStrategy(bet_amount=total_amount)

Pros: max flexibility
Cons: less pretty, more lines to create new agents

Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

The pull request introduces modifications across several components of the prediction market agent tooling. Key changes include the addition of a get_user_id method to handle user identification based on market types, enhancements to the DeployableTraderAgent class for improved betting strategy selection, and a refactoring of betting strategy classes to streamline bet amount calculations. Additionally, new static methods for retrieving user balances have been added to relevant market classes.

Changes

File Change Summary
prediction_market_agent_tooling/config.py Added get_user_id method to retrieve user IDs based on market_type.
prediction_market_agent_tooling/deploy/agent.py Removed strategy attribute from DeployableTraderAgent. Added get_betting_strategy method. Updated build_trades and process_market methods to include market as a parameter.
prediction_market_agent_tooling/deploy/betting_strategy.py Removed adjust_bet_amount method from BettingStrategy. Updated constructors of MaxAccuracyBettingStrategy and KellyBettingStrategy to require mandatory parameters for bet amounts. Simplified bet amount calculation logic.
prediction_market_agent_tooling/jobs/omen/omen_jobs.py Modified compute_job_reward to improve readability by separating the instantiation of KellyBettingStrategy from the method call to calculate_trades.
prediction_market_agent_tooling/markets/agent_market.py Added new static methods get_user_balance and get_user_id requiring implementation in subclasses.
prediction_market_agent_tooling/markets/omen/omen.py Added new static methods get_user_balance and get_user_id for retrieving user balance and ID, respectively.
tests/test_betting_strategy.py Updated test functions to instantiate MaxAccuracyBettingStrategy with specific bet_amount parameters.

Assessment against linked issues

Objective Addressed Explanation
Allow BettingStrategy.calculate_bet_amount_and_direction to accept wallet_balance (377) The changes do not implement a mechanism to adjust betting strategies based on wallet balance.

Possibly related issues

Possibly related PRs

  • Add partial Metaculus support #299: The main PR introduces a new method get_user_id in config.py, which is related to the changes in APIKeys in the retrieved PR that adds new properties for user IDs, enhancing user identification across different market types.
  • Create markets with sDai as collateral #320: The changes in the main PR regarding user ID retrieval based on market type may relate to the modifications in omen.py that enhance market functionalities, including user position management.
  • 423 sell prev positions #374: The main PR's focus on user positions and market interactions aligns with the enhancements in omen.py that introduce methods for liquidating existing positions, improving the overall trading strategy.
  • 383 move rebalancing logic involving previous positions to strategy #387: The main PR's introduction of a new method for calculating trades based on existing positions connects with the changes in betting_strategy.py, which also focuses on trade calculations and position management.
  • Integrate AgentMarket.outcome_token_pool into betting strategies #389: The main PR's updates to the betting strategies and their integration with market conditions relate to the modifications in kelly_criterion.py, which enhance the flexibility of the betting strategy based on market dynamics.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (2)
tests/test_betting_strategy.py (1)

29-29: LGTM. Consider adding a test for dynamic bet amounts.

The change aligns with the PR objective of allowing dynamic bet amounts. However, to ensure comprehensive test coverage:

  1. Consider adding a test case that explicitly verifies the dynamic bet amount functionality. This could involve creating multiple instances of MaxAccuracyBettingStrategy with different bet amounts and asserting that they behave correctly.

  2. It might be beneficial to parameterize this test to cover various bet amounts, ensuring the strategy works correctly across different scenarios.

prediction_market_agent_tooling/markets/omen/omen.py (1)

636-639: LGTM! Consider adding a return type hint.

The new get_user_balance static method is well-implemented and serves its purpose of retrieving a user's balance. It correctly converts the user_id to a checksum address and uses the get_balances function to fetch the total balance.

Consider adding a return type hint for better code readability and type checking:

    @staticmethod
-   def get_user_balance(user_id: str) -> float:
+   def get_user_balance(user_id: str) -> float:
        return float(get_balances(Web3.to_checksum_address(user_id)).total)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e63f3e0 and 35f086e.

Files selected for processing (6)
  • prediction_market_agent_tooling/deploy/agent.py (3 hunks)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (4 hunks)
  • prediction_market_agent_tooling/jobs/omen/omen_jobs.py (1 hunks)
  • prediction_market_agent_tooling/markets/agent_market.py (1 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (1 hunks)
  • tests/test_betting_strategy.py (1 hunks)
Additional comments not posted (11)
tests/test_betting_strategy.py (2)

Line range hint 1-62: Overall, the changes look good but consider enhancing test coverage.

The modifications to both test_answer_decision and test_rebalance functions align well with the PR objective of allowing dynamic bet amounts. However, to further improve the test suite:

  1. Consider adding explicit tests for the dynamic bet amount functionality across various scenarios.
  2. Document the reasoning behind the chosen bet amounts, especially the very small amount in test_rebalance.
  3. Ensure that all assertions remain valid with the new bet amounts.

These enhancements will provide more robust test coverage for the new dynamic bet amount feature.


35-35: LGTM. Consider documenting the tiny bet amount and verifying assertions.

The change aligns with the PR objective of allowing dynamic bet amounts. To improve the test:

  1. Consider adding a comment explaining the rationale behind using such a small bet amount (0.0001). This helps other developers understand if it's testing a specific edge case or precision handling.

  2. Verify if the assertions later in the test (lines 56-62) need adjustment due to the tiny bet amount. Ensure that the expected behavior is still correctly captured with this change.

To verify the impact of the tiny bet amount on the test assertions, you can run the following script:

This will help ensure that the test logic remains correct with the new bet amount.

prediction_market_agent_tooling/jobs/omen/omen_jobs.py (1)

86-87: LGTM! Consider clarifying the PR objective.

The change improves code readability by separating the instantiation of the KellyBettingStrategy from the method call. This is a good practice and makes the code easier to understand and maintain.

However, the PR title mentions removing 'adjust_bet_amount', which is not directly visible in this change. Could you please clarify where this removal occurred or how the functionality has been adjusted? This will help ensure that the PR objectives are fully met and documented.

To verify the removal of 'adjust_bet_amount', let's search for its occurrences in the codebase:

If this search returns no results, it confirms that 'adjust_bet_amount' has been removed from the codebase as per the PR objective.

Verification successful

[/run_scripts]


'adjust_bet_amount' Successfully Removed

The search across all Python files returned no occurrences of adjust_bet_amount, confirming its removal from the codebase as per the PR objective.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for 'adjust_bet_amount' in the codebase
# Expected result: No occurrences of 'adjust_bet_amount' should be found

rg --type python 'adjust_bet_amount'

Length of output: 67


Script:

#!/bin/bash
# Description: Search for 'adjust_bet_amount' in all Python files using fd and rg
# Expected result: No occurrences of 'adjust_bet_amount' should be found

fd --extension py --type file | xargs rg 'adjust_bet_amount'

Length of output: 60

prediction_market_agent_tooling/deploy/betting_strategy.py (4)

96-97: LGTM: Constructor signature update improves type safety

The change to require a non-optional bet_amount parameter in the constructor aligns with the PR objective of allowing dynamic bet amounts. This update also improves type safety by eliminating the possibility of None values for bet_amount.


109-109: LGTM: Simplified betting logic with improved flexibility

The direct use of self.bet_amount simplifies the betting logic and aligns with the removal of the adjust_bet_amount method. This change allows for more flexible betting strategies as the bet amount can be set dynamically when initializing the strategy.


134-135: LGTM: Consistent implementation of dynamic bet amounts

The changes in KellyBettingStrategy are consistent with the PR objective and the modifications made to MaxAccuracyBettingStrategy:

  1. The constructor now requires a non-optional max_bet_amount, improving type safety.
  2. The calculate_trades method uses self.max_bet_amount directly in Kelly criterion calculations, allowing for dynamic bet amounts.

These changes successfully implement the goal of allowing dynamic bet amounts based on the market.

Also applies to: 153-153, 158-158


Line range hint 1-174: Summary: PR successfully implements dynamic bet amounts

This PR successfully achieves its objective of allowing dynamic bet amounts based on the market. The key changes include:

  1. Removal of the adjust_bet_amount method from the BettingStrategy class.
  2. Updated constructors in MaxAccuracyBettingStrategy and KellyBettingStrategy to require non-optional bet amount parameters.
  3. Simplified betting logic in both strategies to use the provided bet amounts directly.

These changes improve type safety, simplify the betting logic, and provide more flexibility in setting bet amounts. The implementation is consistent across the affected classes and aligns well with the PR objectives.

prediction_market_agent_tooling/markets/agent_market.py (2)

285-287: LGTM: New method get_user_balance added.

The new static method get_user_balance is a good addition to the AgentMarket class. It follows the existing pattern of abstract methods in the class, providing a consistent interface for subclasses to implement user balance retrieval.


Line range hint 1-287: Verify PR objectives: Removal of 'adjust_bet_amount'.

The PR title mentions removing 'adjust_bet_amount', but this change is not visible in the provided code. Please ensure that this removal has been implemented as intended.

To verify the removal of 'adjust_bet_amount', run the following script:

Verification successful

Verified PR Objective: Removal of adjust_bet_amount implemented successfully.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the presence of 'adjust_bet_amount' in the codebase

# Test: Search for 'adjust_bet_amount' in Python files
rg --type python 'adjust_bet_amount'

# If the above command returns results, the method might not have been removed as intended

Length of output: 67


Script:

#!/bin/bash
# Description: Check for the presence of 'adjust_bet_amount' in Python files

rg --glob '*.py' 'adjust_bet_amount'

Length of output: 36

prediction_market_agent_tooling/deploy/agent.py (2)

Line range hint 420-430: LGTM

The changes to the build_trades method correctly update the signature to include market_type, and the implementation is consistent.


459-462: LGTM

The updated call to build_trades in process_market now includes market_type, aligning with the new method signature.

prediction_market_agent_tooling/deploy/agent.py Outdated Show resolved Hide resolved
def get_betting_strategy(
self, market_type: MarketType, market: AgentMarket
) -> BettingStrategy:
user_id = APIKeys().bet_from_address
Copy link
Contributor

Choose a reason for hiding this comment

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

bet_from_address is Omen-only, it would be None and error out for other markets

Maybe new property on APIKeys that would return the correct user id (bet_from_address or manifold_user_id or something else) based on the MarketType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot! It's a bit of a major change fixing circular import issues after adding that to APIKeys, so I've put it as (another! 😢) method on AgentMarket and its subclasses

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (4)
prediction_market_agent_tooling/deploy/betting_strategy.py (4)

Line range hint 96-109: LGTM! Consider adding type hinting for self.bet_amount.

The changes to the MaxAccuracyBettingStrategy class align well with the PR objective of allowing dynamic bet amounts based on market conditions. The removal of the optional parameter in the constructor enforces that a bet amount must be provided, which is a good practice.

Consider adding type hinting for self.bet_amount in the constructor:

class MaxAccuracyBettingStrategy(BettingStrategy):
-    def __init__(self, bet_amount: float):
+    def __init__(self, bet_amount: float):
+        self.bet_amount: float = bet_amount
-        self.bet_amount = bet_amount

This will improve code readability and help with static type checking.


Line range hint 137-161: LGTM! Consider adding type hinting for self.max_bet_amount.

The changes to the KellyBettingStrategy class are in line with the PR objective of allowing dynamic bet amounts based on market conditions. Removing the default value for max_bet_amount in the constructor is a good practice as it ensures that a maximum bet amount is always provided.

Consider adding type hinting for self.max_bet_amount in the constructor:

class KellyBettingStrategy(BettingStrategy):
-    def __init__(self, max_bet_amount: float):
+    def __init__(self, max_bet_amount: float):
+        self.max_bet_amount: float = max_bet_amount
-        self.max_bet_amount = max_bet_amount

This will improve code readability and help with static type checking.


Line range hint 180-238: Update MaxAccuracyWithKellyScaledBetsStrategy to align with other classes.

The MaxAccuracyWithKellyScaledBetsStrategy class still contains the adjust_bet_amount method and uses adjusted_bet_amount in the calculate_trades method. This is inconsistent with the changes made to other classes and doesn't align with the PR objective of removing the adjust_bet_amount method.

Consider updating this class to follow the same pattern as MaxAccuracyBettingStrategy and KellyBettingStrategy:

  1. Remove the adjust_bet_amount method.
  2. Update the constructor to take a non-optional max_bet_amount parameter.
  3. Use self.max_bet_amount directly in the calculate_trades method.

Here's a suggested implementation:

class MaxAccuracyWithKellyScaledBetsStrategy(BettingStrategy):
    def __init__(self, max_bet_amount: float):
        self.max_bet_amount: float = max_bet_amount

    def calculate_trades(
        self,
        existing_position: Position | None,
        answer: ProbabilisticAnswer,
        market: AgentMarket,
    ) -> list[Trade]:
        outcome_token_pool = check_not_none(market.outcome_token_pool)

        # Fixed direction of bet, only use Kelly to adjust the bet size based on market's outcome pool size.
        estimated_p_yes = float(answer.p_yes > 0.5)
        confidence = 1.0

        kelly_bet = (
            get_kelly_bet_full(
                yes_outcome_pool_size=outcome_token_pool[
                    market.get_outcome_str_from_bool(True)
                ],
                no_outcome_pool_size=outcome_token_pool[
                    market.get_outcome_str_from_bool(False)
                ],
                estimated_p_yes=estimated_p_yes,
                max_bet=self.max_bet_amount,
                confidence=confidence,
            )
            if market.has_token_pool()
            else get_kelly_bet_simplified(
                self.max_bet_amount,
                market.current_p_yes,
                estimated_p_yes,
                confidence,
            )
        )

        amounts = {
            market.get_outcome_str_from_bool(kelly_bet.direction): TokenAmount(
                amount=kelly_bet.size, currency=market.currency
            ),
        }
        target_position = Position(market_id=market.id, amounts=amounts)
        trades = self._build_rebalance_trades_from_positions(
            existing_position, target_position, market=market
        )
        return trades

    def __repr__(self) -> str:
        return f"{self.__class__.__name__}(max_bet_amount={self.max_bet_amount})"

This change will ensure consistency across all betting strategy classes and align with the PR objectives.


Line range hint 1-238: Summary of review findings and recommendations

The changes made to MaxAccuracyBettingStrategy and KellyBettingStrategy classes align well with the PR objective of allowing dynamic bet amounts based on market conditions. The removal of the adjust_bet_amount method and the updates to the constructors enforce better practices for setting bet amounts.

However, the MaxAccuracyWithKellyScaledBetsStrategy class needs to be updated to maintain consistency with the other classes and fully align with the PR objectives.

To improve the overall architecture and consistency of the betting strategies:

  1. Update the MaxAccuracyWithKellyScaledBetsStrategy class as suggested in the previous comment.
  2. Consider creating a base class for strategies that use a maximum bet amount, which could be inherited by both KellyBettingStrategy and MaxAccuracyWithKellyScaledBetsStrategy. This would help reduce code duplication and enforce consistency in how maximum bet amounts are handled across different strategies.
  3. Add comprehensive unit tests for each betting strategy to ensure they behave correctly with the new dynamic bet amount calculations.

These changes will result in a more consistent and maintainable codebase that fully achieves the objectives of this pull request.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35f086e and 4355996.

Files selected for processing (2)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (4 hunks)
  • tests/test_betting_strategy.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_betting_strategy.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
prediction_market_agent_tooling/config.py (1)

163-171: LGTM: New get_user_id method with minor suggestions.

The get_user_id method is well-implemented and aligns with the PR objectives. It correctly handles different market types and includes proper error handling for unknown types.

Suggestions for improvement:

  1. Consider using a dictionary mapping or match-case statement for better scalability as new market types are added.
  2. Add a docstring to explain the method's purpose and parameters.

Here's an example of how you could refactor the method using a dictionary mapping:

def get_user_id(self, market_type: MarketType) -> str:
    """
    Get the user ID for the specified market type.

    Args:
        market_type (MarketType): The type of market to get the user ID for.

    Returns:
        str: The user ID for the specified market type.

    Raises:
        ValueError: If an unknown market type is provided.
    """
    user_id_map = {
        MarketType.MANIFOLD: self.manifold_user_id,
        MarketType.METACULUS: str(self.metaculus_user_id),
        MarketType.OMEN: self.bet_from_address,
        MarketType.POLYMARKET: self.bet_from_address,
    }
    
    try:
        return user_id_map[market_type]
    except KeyError:
        raise ValueError(f"Unknown market type: {market_type}")

This refactored version improves readability and makes it easier to add new market types in the future.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 64d2bef and 1c5499a.

Files selected for processing (2)
  • prediction_market_agent_tooling/config.py (2 hunks)
  • prediction_market_agent_tooling/deploy/agent.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • prediction_market_agent_tooling/deploy/agent.py
Additional comments not posted (2)
prediction_market_agent_tooling/config.py (2)

15-15: LGTM: Import statement for MarketType.

The new import statement for MarketType is correctly placed and necessary for the newly added get_user_id method.


15-15: Summary: Changes align with PR objectives and enhance flexibility.

The introduced changes, including the new import and get_user_id method, align well with the PR objectives of enabling dynamic bet amounts based on market conditions. The get_user_id method provides a flexible way to retrieve user IDs for different market types, which is crucial for implementing dynamic betting strategies.

These changes lay the groundwork for agents to adapt their bet sizes based on market conditions and their current balances, addressing the limitations mentioned in issue #377. The implementation is solid, with only minor suggestions for improvement in terms of scalability and documentation.

Overall, this is a well-executed step towards achieving the goal of more flexible and adaptive betting strategies.

Also applies to: 163-171

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (3)
prediction_market_agent_tooling/monitor/markets/polymarket.py (2)

47-49: LGTM! Consider adding input validation.

The new get_user_id static method is a good addition that aligns with the PR objectives. It provides a clean way to retrieve the user's ID from the API keys, which can be useful for implementing dynamic bet amounts based on the user's balance.

Consider adding input validation to ensure bet_from_address is present in the APIKeys instance. This could prevent potential AttributeErrors:

 @staticmethod
 def get_user_id(api_keys: APIKeys) -> str:
+    if not hasattr(api_keys, 'bet_from_address'):
+        raise ValueError("APIKeys instance does not have 'bet_from_address' attribute")
     return api_keys.bet_from_address

Line range hint 1-49: Summary and Next Steps

The addition of the get_user_id method is a good first step towards implementing dynamic bet amounts. However, to fully achieve the PR objectives, consider the following next steps:

  1. Implement the changes to BettingStrategy.calculate_bet_amount_and_direction to accept a wallet_balance argument.
  2. Create a mechanism to retrieve the user's current balance using the ID obtained from get_user_id.
  3. Update the betting logic to calculate bet amounts based on the user's current balance and market conditions.
  4. Add unit tests to ensure the new functionality works as expected.
  5. Update documentation to reflect these changes and explain how to use the new dynamic betting feature.

These steps will help ensure that the PR fully addresses the objectives outlined in issue #377 and provides a comprehensive solution for dynamic bet amounts.

prediction_market_agent_tooling/markets/manifold/manifold.py (1)

123-125: Approve with suggestions for improvement

The new get_user_id method is a good addition to the ManifoldAgentMarket class. It provides a clean way to retrieve the user ID from the API keys. However, I have a few suggestions to enhance it:

  1. Add a return type hint for consistency:
@staticmethod
def get_user_id(api_keys: APIKeys) -> str:
    return api_keys.manifold_user_id
  1. Consider adding basic error handling in case manifold_user_id is not present in the api_keys object:
@staticmethod
def get_user_id(api_keys: APIKeys) -> str:
    if not hasattr(api_keys, 'manifold_user_id'):
        raise AttributeError("manifold_user_id not found in APIKeys")
    return api_keys.manifold_user_id
  1. Could you please clarify how this method supports the PR objectives of allowing dynamic bet amounts based on market conditions? It would be helpful to understand the broader context of this addition.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c5499a and caf06d7.

Files selected for processing (6)
  • prediction_market_agent_tooling/deploy/agent.py (3 hunks)
  • prediction_market_agent_tooling/markets/agent_market.py (1 hunks)
  • prediction_market_agent_tooling/markets/manifold/manifold.py (1 hunks)
  • prediction_market_agent_tooling/markets/metaculus/metaculus.py (2 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (1 hunks)
  • prediction_market_agent_tooling/monitor/markets/polymarket.py (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • prediction_market_agent_tooling/deploy/agent.py
  • prediction_market_agent_tooling/markets/agent_market.py
  • prediction_market_agent_tooling/markets/omen/omen.py
Additional comments not posted (2)
prediction_market_agent_tooling/markets/metaculus/metaculus.py (2)

4-4: LGTM: New import statement for APIKeys

The addition of the import statement for APIKeys is correct and necessary for the new get_user_id method. It's properly placed with other imports from the same package.


109-111: Approve new get_user_id method, but clarification needed

The new get_user_id static method is implemented correctly. It provides a clean way to retrieve the Metaculus user ID from the API keys.

However, could you please clarify how this method contributes to the PR's objective of allowing dynamic bet amounts based on market conditions? While it doesn't directly implement this functionality, it might be a prerequisite for user-specific operations. Some context on its intended use would be helpful.

To ensure this method is used appropriately, let's check for its usage:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BettingStrategy.calculate_bet_amount_and_direction should be able to take wallet_balance arg
3 participants