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

383 move rebalancing logic involving previous positions to strategy #387

Conversation

gabrielfior
Copy link
Contributor

-> Exposing method calculate_trades from BettingStrategy, so that agent gets a list of trades and executes these.
-> Implemented rebalance with lower gas fees (don't necessarily sell, buy only diff amount, etc)

@gabrielfior gabrielfior linked an issue Sep 6, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Sep 6, 2024

Warning

Rate limit exceeded

@gabrielfior has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 53 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 1fe9aa2 and 9ae4d5b.

Walkthrough

The changes involve significant modifications to the prediction_market_agent_tooling module, particularly in the handling of bets and trades. Key updates include the removal of the calculate_bet_amount_and_direction method, replaced by a new calculate_trades method that generates trade objects based on existing positions. Additionally, new data models for trades and trade types have been introduced, along with enhancements to outcome handling in related classes.

Changes

Files Change Summary
prediction_market_agent_tooling/deploy/agent.py, prediction_market_agent_tooling/deploy/betting_strategy.py Removed calculate_bet_amount_and_direction method; added calculate_trades method in BettingStrategy and its subclasses, which now returns a list of Trade objects. Updated process_market method to retrieve existing positions.
prediction_market_agent_tooling/markets/agent_market.py, prediction_market_agent_tooling/markets/omen/omen.py Added get_liquidatable_amount and get_outcome_str_from_bool methods for enhanced outcome and financial handling. Updated liquidate_existing_positions to accept a larger_than parameter.
prediction_market_agent_tooling/markets/data_models.py Introduced TradeType enumeration and Trade class to represent trade details, enhancing the structure of trade-related data.

Possibly related issues

Possibly related PRs

  • 423 sell prev positions #374: The modifications to the process_market method to allow for the liquidation of existing positions are directly related to the changes in how bets are processed in the main PR.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

@gabrielfior gabrielfior marked this pull request as ready for review September 6, 2024 17:40
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: 3

Outside diff range, codebase verification and nitpick comments (1)
prediction_market_agent_tooling/deploy/agent.py (1)

Line range hint 423-455: Approved: Updated process_market method.

The updates to the process_market method, which now uses the get_existing_position_for_market function to calculate trades based on existing positions, align well with the PR's objectives. Consider enhancing the logging within this method to include more details about the trades being executed for better traceability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81affd1 and 30134d7.

Files selected for processing (5)
  • prediction_market_agent_tooling/deploy/agent.py (7 hunks)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (1 hunks)
  • prediction_market_agent_tooling/markets/agent_market.py (2 hunks)
  • prediction_market_agent_tooling/markets/data_models.py (1 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (1 hunks)
Additional context used
Learnings (1)
Common learnings
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#224
File: prediction_market_agent_tooling/markets/markets.py:67-67
Timestamp: 2024-04-29T14:14:38.751Z
Learning: The function `have_bet_on_market_since` is suggested to be refactored into a method on the `AgentMarket` class, potentially reusing code from `DeployedAgent.get_resolved_bets`. This task is planned for future work, not within the scope of the current PR.
Additional comments not posted (9)
prediction_market_agent_tooling/markets/data_models.py (1)

120-122: Well-implemented TradeType enum.

The use of an enumeration for trade types (SELL and BUY) enhances clarity and type safety in trade operations.

prediction_market_agent_tooling/deploy/agent.py (1)

18-18: Approved: Changes to ProcessedMarket class.

The removal of the amount attribute from the ProcessedMarket class reflects the new focus on trade execution rather than bet placement, aligning with the PR's objectives to enhance efficiency in trade execution and rebalancing.

prediction_market_agent_tooling/deploy/betting_strategy.py (5)

19-24: New Method: calculate_trades

The introduction of the calculate_trades method is a significant change. It shifts the focus from simple bet calculation to a more complex trade construction based on existing positions. This aligns well with the PR's objectives of improving trade efficiency and rebalancing.


28-35: New Static Method: _assert_trades_currency_match_markets

This method ensures that all trades are in the same currency as the market, which is crucial for maintaining consistency and avoiding errors during trade execution. It's a good practice to enforce such validations.


38-85: New Static Method: _build_rebalance_trades_from_positions

This method constructs trades by comparing existing and target positions, which is central to the new rebalancing logic. The detailed documentation and example provided in the comments enhance understanding and maintainability. Sorting trades to prioritize buys before sells (line 83) is a strategic choice that could impact market dynamics favorably.


92-118: Method Implementation: calculate_trades in MaxAccuracyBettingStrategy

The implementation of calculate_trades in this class uses a simple decision-making process based on the market's current probability and the probabilistic answer to determine trade directions. The use of the helper method _build_rebalance_trades_from_positions ensures that the trades are constructed correctly based on the calculated target positions.


132-154: Method Implementation: calculate_trades in KellyBettingStrategy

The implementation of calculate_trades in this class correctly applies the Kelly criterion to determine the optimal size of trades based on the market's current probability, the probabilistic answer, and the user's confidence. This approach is appropriate for a strategy aimed at maximizing expected logarithmic utility, which is the goal of Kelly betting.

prediction_market_agent_tooling/markets/agent_market.py (2)

9-9: Updated Import Statement

The addition of OutcomeStr to the import statement supports the new method get_outcome_str_from_bool, which is expected to handle outcome representations based on boolean values. This update is necessary for the new functionality introduced in this file.


196-197: New Method: get_outcome_str_from_bool

The introduction of get_outcome_str_from_bool is a critical enhancement for handling outcomes based on boolean values. Marking it with NotImplementedError ensures that subclasses provide specific implementations, which is a good practice for abstract methods in base classes.

def get_existing_position_for_market(
market: AgentMarket, user_id: str
) -> Position | None:
minimum_liquidatable_amount = market.get_tiny_bet_amount().amount / 10
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this tiny_bet / 10 logic was used somewhere already. What about refactoring it to a common property on AgentMarket ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a method liquidatable_amount to market

prediction_market_agent_tooling/deploy/agent.py Outdated Show resolved Hide resolved
prediction_market_agent_tooling/deploy/agent.py Outdated Show resolved Hide resolved
prediction_market_agent_tooling/deploy/agent.py Outdated Show resolved Hide resolved
Copy link
Contributor

@evangriffiths evangriffiths left a comment

Choose a reason for hiding this comment

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

Currently if we do

market0 = OmenAgentMarket(id=...)
agent.process_market(market=market0) # once
agent.process_market(market=market0) # twice

current behaviour (assuming the prediction made in each case is the same):

  • MaxAccuracyBettingStrategy - place bet_amount both times
  • KellyBettingStrategy - place x <= max_bet both times

new behaviour:

  • MaxAccuracyBettingStrategy
    • place bet_amount first time
    • place no bet the second time
  • KellyBettingStrategy
    • place x <= max_bet first time
    • place no bet the second time

Is this what you intended? I would have thought for Kelly at least it would be:

  • place x <= max_bet first time
  • place x <= y <= max_bet second time

for MaxAccuracyBettingStrategy I'm not sure.

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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 30134d7 and 0b8a004.

Files selected for processing (4)
  • prediction_market_agent_tooling/deploy/agent.py (6 hunks)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (1 hunks)
  • prediction_market_agent_tooling/markets/agent_market.py (4 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (3 hunks)
Additional context used
Learnings (2)
Common learnings
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#224
File: prediction_market_agent_tooling/markets/markets.py:67-67
Timestamp: 2024-04-29T14:14:38.751Z
Learning: The function `have_bet_on_market_since` is suggested to be refactored into a method on the `AgentMarket` class, potentially reusing code from `DeployedAgent.get_resolved_bets`. This task is planned for future work, not within the scope of the current PR.
prediction_market_agent_tooling/markets/omen/omen.py (3)
Learnt from: evangriffiths
PR: gnosis/prediction-market-agent-tooling#300
File: prediction_market_agent_tooling/markets/omen/omen.py:344-352
Timestamp: 2024-07-08T07:05:58.507Z
Learning: The `get_resolved_bets_made_since` method in the `OmenAgentMarket` class should include an `end_time` argument to make it more flexible.
Learnt from: evangriffiths
PR: gnosis/prediction-market-agent-tooling#300
File: prediction_market_agent_tooling/markets/omen/omen.py:344-352
Timestamp: 2024-07-08T07:08:57.156Z
Learning: The `get_resolved_bets` method in the `OmenAgentMarket` class should include an `end_time` argument to make it more flexible.
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#139
File: tests/markets/omen/test_omen.py:144-154
Timestamp: 2024-03-28T15:05:28.580Z
Learning: A GitHub issue was created to track the implementation of the `create_market_fund_market_remove_funding` test function in `test_omen.py` for the Gnosis prediction market agent tooling project. The issue number is 143.
Additional comments not posted (10)
prediction_market_agent_tooling/deploy/betting_strategy.py (5)

19-24: Approved: New method calculate_trades in BettingStrategy.

The new method calculate_trades effectively replaces the old bet calculation logic with a more robust trading mechanism. Consider adding detailed documentation explaining the parameters and expected structure of the returned Trade objects.


33-41: Approved: Method assert_trades_currency_match_markets.

This method ensures currency consistency across trades, which is crucial for maintaining financial integrity. Consider handling cases where the trades list might be empty to avoid unnecessary computations.


44-90: Approved: Method _build_rebalance_trades_from_positions.

This method is well-implemented with clear documentation and examples. The sorting of trades to optimize pricing is a thoughtful addition. Consider evaluating the impact of this sorting on trade execution times and whether it aligns with real-world trading scenarios.


100-141: Approved: Class MaxAccuracyBettingStrategy.

The implementation of calculate_trades in this class is tailored to its strategy of maximizing accuracy, effectively utilizing existing positions. Consider adding unit tests to verify the behavior under various market conditions and positions.


160-194: Approved: Class KellyBettingStrategy.

The calculate_trades method integrates the Kelly criterion effectively, considering both existing positions and a maximum bet amount. Evaluate the implications of this max bet amount on trade sizes, especially in scenarios with highly volatile markets.

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

166-178: Approved: Modification to liquidate_existing_positions.

The addition of the larger_than parameter and its default handling using get_liquidatable_amount enhances the flexibility of the liquidation process. This change aligns well with the PR objectives of improving efficiency.


444-456: Approved: Addition of get_existing_position_for_market.

The method effectively uses the get_liquidatable_amount to filter positions, enhancing the management of market positions. This addition aligns with the PR objectives of improving trading efficiency.

prediction_market_agent_tooling/markets/agent_market.py (2)

9-9: Approved: Updated import statement.

The addition of OutcomeStr to the import statement aligns with the new methods introduced in the class, which utilize this type.


202-204: Approved: Interface method get_outcome_str_from_bool.

The method correctly sets up an interface for subclasses to implement, ensuring that specific behaviors are customized according to the needs of different market types.

prediction_market_agent_tooling/deploy/agent.py (1)

112-112: Approved: Updated ProcessedMarket class.

The addition of the trades attribute aligns with the new trading logic, enhancing the clarity and maintainability of the code by separating the concerns of trade calculation and execution.

prediction_market_agent_tooling/markets/omen/omen.py Outdated Show resolved Hide resolved
prediction_market_agent_tooling/deploy/agent.py Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0b8a004 and 6697e6b.

Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
Files selected for processing (2)
  • prediction_market_agent_tooling/markets/agent_market.py (4 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • prediction_market_agent_tooling/markets/omen/omen.py
Additional context used
Learnings (1)
Common learnings
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#224
File: prediction_market_agent_tooling/markets/markets.py:67-67
Timestamp: 2024-04-29T14:14:38.751Z
Learning: The function `have_bet_on_market_since` is suggested to be refactored into a method on the `AgentMarket` class, potentially reusing code from `DeployedAgent.get_resolved_bets`. This task is planned for future work, not within the scope of the current PR.
Additional comments not posted (2)
prediction_market_agent_tooling/markets/agent_market.py (2)

10-10: Approved: Updated import statement.

The import statement has been modified to include OutcomeStr alongside Probability. This change supports the new methods introduced in this PR that deal with outcome representations, aligning with the PR's objectives to enhance outcome handling.


222-223: Approved: Method get_outcome_str_from_bool correctly raises NotImplementedError.

This method serves as a template for subclasses to implement their specific logic for converting a boolean to an OutcomeStr. It would be beneficial to include documentation or comments in the code to guide developers on how to implement this method in 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6697e6b and 60b92e6.

Files selected for processing (2)
  • prediction_market_agent_tooling/markets/agent_market.py (4 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • prediction_market_agent_tooling/markets/agent_market.py
  • prediction_market_agent_tooling/markets/omen/omen.py
Additional context used
Learnings (1)
Common learnings
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#224
File: prediction_market_agent_tooling/markets/markets.py:67-67
Timestamp: 2024-04-29T14:14:38.751Z
Learning: The function `have_bet_on_market_since` is suggested to be refactored into a method on the `AgentMarket` class, potentially reusing code from `DeployedAgent.get_resolved_bets`. This task is planned for future work, not within the scope of the current PR.

@@ -230,6 +239,9 @@ def get_outcome_index(self, outcome: str) -> int:
def get_token_balance(self, user_id: str, outcome: str) -> TokenAmount:
raise NotImplementedError("Subclasses must implement this method")

def get_existing_position_for_market(self, api_keys: APIKeys) -> Position | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this only needs user_id: str, like get_positions. And could rename to just get_position.

prediction_market_agent_tooling/deploy/betting_strategy.py Outdated Show resolved Hide resolved
prediction_market_agent_tooling/deploy/betting_strategy.py Outdated Show resolved Hide resolved
prediction_market_agent_tooling/markets/omen/omen.py Outdated Show resolved Hide resolved
@@ -432,6 +445,19 @@ def get_token_balance(
currency=self.currency,
)

def get_existing_position_for_market(self, api_keys: APIKeys) -> Position | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing in this looks omen-specific, so it could be moved to the base class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not present in the updated version

amount=adjusted_bet_amount,
currency=market.currency,
),
market.get_outcome_str_from_bool(not direction): TokenAmount(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to specify these 0 TokenAmounts when instantiating the target position (here, and in KellyBettingStrategy.calculate_trades)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the current setup yes, otherwise Pydantic complains - we could set a default value in TokenAmount of 0, but I would advise against that to make sure people assign a value to amount.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, i mean why not just:

        amounts = {
            market.get_outcome_str_from_bool(direction): TokenAmount(
                amount=adjusted_bet_amount,
                currency=market.currency,
            ),
        }

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 point, we can simply not create an amount for the other direction. This will get caught on _build_rebalance_trades_from_positions.

prediction_market_agent_tooling/deploy/betting_strategy.py Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 60b92e6 and 957d173.

Files selected for processing (2)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (1 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • prediction_market_agent_tooling/markets/omen/omen.py
Additional context used
Learnings (1)
Common learnings
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#224
File: prediction_market_agent_tooling/markets/markets.py:67-67
Timestamp: 2024-04-29T14:14:38.751Z
Learning: The function `have_bet_on_market_since` is suggested to be refactored into a method on the `AgentMarket` class, potentially reusing code from `DeployedAgent.get_resolved_bets`. This task is planned for future work, not within the scope of the current PR.
Additional comments not posted (6)
prediction_market_agent_tooling/deploy/betting_strategy.py (6)

5-5: LGTM!

The new imports for Position, Trade, and TradeType data models are consistent with the changes made in the rest of the code.

Also applies to: 7-9


19-24: LGTM!

The changes to the calculate_trades method signature in the BettingStrategy class are consistent with the overall changes made in the file. Making the method abstract is appropriate as it is meant to be implemented by the derived classes.


27-31: LGTM!

The changes to the adjust_bet_amount method signature in the BettingStrategy class are consistent with the overall changes made in the file. Making the method abstract is appropriate as it is meant to be implemented by the derived classes.


33-41: LGTM!

The new assert_trades_currency_match_markets method in the BettingStrategy class is a useful addition to ensure that the trades are in the same currency as the market. It enhances the robustness of the trading logic.


44-90: LGTM!

The new _build_rebalance_trades_from_positions method in the BettingStrategy class is a well-designed helper method that encapsulates the logic for building rebalance trades based on existing and target positions. It handles various edge cases and ensures the correctness of the trades.


112-135: LGTM!

The changes to the calculate_trades method in the MaxAccuracyBettingStrategy and KellyBettingStrategy classes are consistent with the changes made in the base class and the overall changes made in the file. The method now takes into account the existing position and builds rebalance trades based on it, which is a significant improvement over the previous implementation.

Also applies to: 163-189

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, codebase verification and nitpick comments (2)
prediction_market_agent_tooling/markets/agent_market.py (2)

156-160: LGTM: Approved new get_liquidatable_amount method.

The new class method is a useful addition for financial calculations. It correctly calculates a reduced bet amount based on a tiny bet amount.

Consider refactoring this logic into a common property or method to avoid duplication across different parts of the codebase.


242-243: LGTM: Approved new get_position method.

The new method is a good addition to the class, as it provides a way to get a user's position in a market. Marking the function with a NotImplementedError is a good design choice, as it ensures that subclasses implement this method.

Consider renaming the function to get_position and removing the outcome parameter, as it is not used.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 957d173 and 1fe9aa2.

Files selected for processing (4)
  • prediction_market_agent_tooling/deploy/agent.py (6 hunks)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (1 hunks)
  • prediction_market_agent_tooling/markets/agent_market.py (4 hunks)
  • prediction_market_agent_tooling/markets/omen/omen.py (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • prediction_market_agent_tooling/deploy/agent.py
  • prediction_market_agent_tooling/markets/omen/omen.py
Additional context used
Learnings (1)
Common learnings
Learnt from: kongzii
PR: gnosis/prediction-market-agent-tooling#224
File: prediction_market_agent_tooling/markets/markets.py:67-67
Timestamp: 2024-04-29T14:14:38.751Z
Learning: The function `have_bet_on_market_since` is suggested to be refactored into a method on the `AgentMarket` class, potentially reusing code from `DeployedAgent.get_resolved_bets`. This task is planned for future work, not within the scope of the current PR.
Additional comments not posted (7)
prediction_market_agent_tooling/deploy/betting_strategy.py (6)

19-24: LGTM: Approved changes to calculate_trades method.

The changes to the method signature and return type reflect a shift in focus from simply determining the amount and direction of a bet to constructing a series of trades based on existing and target positions. Making the method abstract is a good design choice, as it ensures that subclasses implement this method.


27-31: LGTM: Approved changes to adjust_bet_amount method.

The changes to the method signature to include existing_position parameter indicate that the function now considers the current holdings of the user when adjusting the bet amount. Making the method abstract is a good design choice, as it ensures that subclasses implement this method.


33-41: LGTM: Approved new assert_trades_currency_match_markets method.

The new static method enhances the robustness of the trading logic by validating that all trades are in the same currency as the market, ensuring consistency in currency across trades.


44-90: LGTM: Approved new _build_rebalance_trades_from_positions method.

The new static method is a well-designed helper function that constructs trades by comparing existing and target positions, ensuring that trades are created to rebalance token allocations. The error handling for currency mismatches enhances the robustness of the trading logic.


110-130: LGTM: Approved changes to calculate_trades method.

The changes to the method signature and return type reflect a shift in focus from simply determining the amount and direction of a bet to constructing a series of trades based on existing and target positions. Using the _build_rebalance_trades_from_positions method to construct trades is a good design choice, as it promotes code reuse and maintainability.


158-181: LGTM: Approved changes to calculate_trades method.

The changes to the method signature and return type reflect a shift in focus from simply determining the amount and direction of a bet to constructing a series of trades based on existing and target positions. Using the _build_rebalance_trades_from_positions method to construct trades is a good design choice, as it promotes code reuse and maintainability.

prediction_market_agent_tooling/markets/agent_market.py (1)

222-223: LGTM: Approved new get_outcome_str_from_bool method.

The new method is a good addition to the class, as it provides a way to convert a boolean outcome to an OutcomeStr. Marking the function with a NotImplementedError is a good design choice, as it ensures that subclasses implement this method.

@gabrielfior gabrielfior merged commit 4caab11 into main Sep 9, 2024
8 checks passed
@gabrielfior gabrielfior deleted the 383-move-rebalancing-logic-involving-previous-positions-to-strategy branch September 9, 2024 21:05
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.

Move rebalancing logic involving previous positions to strategy
3 participants