-
Notifications
You must be signed in to change notification settings - Fork 5
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
Pass in generic BetAmount to place_bet
#23
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
580604f
Pass in generic BetAmount to
evangriffiths d78c476
Move class definitions to avoid circular imports
evangriffiths 31bbfc2
Use black from python env for formatting
evangriffiths 101ce7c
Update prediction_market_agent/data_models/market_data_models.py
evangriffiths File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
from decimal import Decimal | ||
import typing as t | ||
from enum import Enum | ||
|
||
from pydantic import BaseModel | ||
from prediction_market_agent.markets import manifold, omen | ||
from prediction_market_agent.tools.gtypes import Mana | ||
from prediction_market_agent.tools.utils import should_not_happen, check_not_none | ||
from prediction_market_agent.utils import APIKeys | ||
|
||
|
||
class Currency(str, Enum): | ||
xDai = "xDai" | ||
Mana = "Mana" | ||
|
||
|
||
class BetAmount(BaseModel): | ||
amount: Decimal | ||
currency: Currency | ||
|
||
|
||
class MarketType(str, Enum): | ||
MANIFOLD = "manifold" | ||
OMEN = "omen" | ||
|
||
|
||
def get_bet_amount(amount: Decimal, market_type: MarketType) -> BetAmount: | ||
if market_type == MarketType.OMEN: | ||
return BetAmount(amount=amount, currency=Currency.xDai) | ||
elif market_type == MarketType.MANIFOLD: | ||
return BetAmount(amount=amount, currency=Currency.Mana) | ||
else: | ||
raise ValueError(f"Unknown market type: {market_type}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple and cool! Nicer than having N arguments for each currency :-D |
||
|
||
|
||
@t.overload | ||
def get_binary_markets( | ||
market_type: t.Literal[MarketType.MANIFOLD], | ||
) -> list[manifold.ManifoldMarket]: | ||
... | ||
) -> list[manifold.ManifoldMarket]: ... | ||
|
||
|
||
@t.overload | ||
def get_binary_markets( | ||
market_type: t.Literal[MarketType.OMEN], | ||
) -> list[omen.OmenMarket]: | ||
... | ||
) -> list[omen.OmenMarket]: ... | ||
|
||
|
||
@t.overload | ||
def get_binary_markets( | ||
market_type: MarketType, | ||
) -> t.Union[list[manifold.ManifoldMarket], list[omen.OmenMarket]]: | ||
... | ||
) -> t.Union[list[manifold.ManifoldMarket], list[omen.OmenMarket]]: ... | ||
|
||
|
||
def get_binary_markets( | ||
|
@@ -47,25 +67,29 @@ def place_bet( | |
outcome: bool, | ||
keys: APIKeys, | ||
omen_auto_deposit: bool, | ||
amount_mana: t.Optional[manifold.Mana] = None, | ||
amount_xdai: t.Optional[omen.xDai] = None, | ||
amount: BetAmount, | ||
) -> None: | ||
manifold.place_bet( | ||
amount=check_not_none(amount_mana), | ||
market_id=market.id, | ||
outcome=outcome, | ||
api_key=check_not_none(keys.manifold), | ||
) if isinstance( | ||
market, manifold.ManifoldMarket | ||
) else omen.binary_omen_buy_outcome_tx( | ||
amount=check_not_none(amount_xdai), | ||
from_address=check_not_none(keys.bet_from_address), | ||
from_private_key=check_not_none(keys.bet_from_private_key), | ||
market=market, | ||
binary_outcome=outcome, | ||
auto_deposit=omen_auto_deposit, | ||
) if isinstance( | ||
market, omen.OmenMarket | ||
) else should_not_happen( | ||
f"Unknown market {market}." | ||
) | ||
if isinstance(market, manifold.ManifoldMarket): | ||
if amount.currency != Currency.Mana: | ||
raise ValueError(f"Manifold bets are made in Mana. Got {amount.currency}.") | ||
amount_mana = Mana(amount.amount) | ||
manifold.place_bet( | ||
amount=check_not_none(amount_mana), | ||
market_id=market.id, | ||
outcome=outcome, | ||
api_key=check_not_none(keys.manifold), | ||
) | ||
elif isinstance(market, omen.OmenMarket): | ||
if amount.currency != Currency.xDai: | ||
raise ValueError(f"Omen bets are made in xDai. Got {amount.currency}.") | ||
amount_xdai = Mana(amount.amount) | ||
omen.binary_omen_buy_outcome_tx( | ||
amount=check_not_none(amount_xdai), | ||
from_address=check_not_none(keys.bet_from_address), | ||
from_private_key=check_not_none(keys.bet_from_private_key), | ||
market=market, | ||
binary_outcome=outcome, | ||
auto_deposit=omen_auto_deposit, | ||
) | ||
else: | ||
should_not_happen(f"Unknown market {market}.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an update since now
main.py
usestyper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!