prediction-market-agent-tooling 0.46.0__py3-none-any.whl → 0.47.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ from prediction_market_agent_tooling.deploy.gcp.utils import (
22
22
  gcp_function_is_active,
23
23
  gcp_resolve_api_keys_secrets,
24
24
  )
25
- from prediction_market_agent_tooling.gtypes import Probability, xdai_type
25
+ from prediction_market_agent_tooling.gtypes import Probability, xDai, xdai_type
26
26
  from prediction_market_agent_tooling.loggers import logger
27
27
  from prediction_market_agent_tooling.markets.agent_market import (
28
28
  AgentMarket,
@@ -35,6 +35,7 @@ from prediction_market_agent_tooling.markets.markets import (
35
35
  have_bet_on_market_since,
36
36
  )
37
37
  from prediction_market_agent_tooling.markets.omen.omen import (
38
+ is_minimum_required_balance,
38
39
  redeem_from_all_user_positions,
39
40
  withdraw_wxdai_to_xdai_to_keep_balance,
40
41
  )
@@ -73,6 +74,10 @@ def to_boolean_outcome(value: str | bool) -> bool:
73
74
  Decision = Annotated[bool, BeforeValidator(to_boolean_outcome)]
74
75
 
75
76
 
77
+ class OutOfFundsError(ValueError):
78
+ pass
79
+
80
+
76
81
  class Answer(BaseModel):
77
82
  decision: Decision # Warning: p_yes > 0.5 doesn't necessarily mean decision is True! For example, if our p_yes is 55%, but market's p_yes is 80%, then it might be profitable to bet on False.
78
83
  p_yes: Probability
@@ -201,6 +206,8 @@ def {entrypoint_function_name}(request) -> str:
201
206
 
202
207
  class DeployableTraderAgent(DeployableAgent):
203
208
  bet_on_n_markets_per_run: int = 1
209
+ min_required_balance_to_operate: xDai | None = xdai_type(1)
210
+ min_balance_to_keep_in_native_currency: xDai | None = xdai_type(0.1)
204
211
 
205
212
  def __init__(self, place_bet: bool = True) -> None:
206
213
  super().__init__()
@@ -273,10 +280,22 @@ class DeployableTraderAgent(DeployableAgent):
273
280
  if market_type == MarketType.OMEN:
274
281
  # Omen is specific, because the user (agent) needs to manually withdraw winnings from the market.
275
282
  redeem_from_all_user_positions(api_keys)
283
+ # Check if we have enough of balance to operate.
284
+ if self.min_required_balance_to_operate is not None:
285
+ if not is_minimum_required_balance(
286
+ api_keys.public_key,
287
+ min_required_balance=self.min_required_balance_to_operate,
288
+ ):
289
+ raise OutOfFundsError(
290
+ f"Minimum required balance {self.min_required_balance_to_operate} is not met."
291
+ )
276
292
  # Exchange wxdai back to xdai if the balance is getting low, so we can keep paying for fees.
277
- withdraw_wxdai_to_xdai_to_keep_balance(
278
- api_keys, min_required_balance=xdai_type(1), withdraw_multiplier=2
279
- )
293
+ if self.min_balance_to_keep_in_native_currency is not None:
294
+ withdraw_wxdai_to_xdai_to_keep_balance(
295
+ api_keys,
296
+ min_required_balance=self.min_balance_to_keep_in_native_currency,
297
+ withdraw_multiplier=2,
298
+ )
280
299
 
281
300
  def process_bets(self, market_type: MarketType) -> None:
282
301
  """
@@ -1043,6 +1043,20 @@ def get_binary_market_p_yes_history(market: OmenAgentMarket) -> list[Probability
1043
1043
  return history
1044
1044
 
1045
1045
 
1046
+ def is_minimum_required_balance(
1047
+ address: ChecksumAddress,
1048
+ min_required_balance: xDai,
1049
+ web3: Web3 | None = None,
1050
+ ) -> bool:
1051
+ """
1052
+ Checks if the total balance of xDai and wxDai in the wallet is above the minimum required balance.
1053
+ """
1054
+ current_balances = get_balances(address, web3)
1055
+ # xDai and wxDai have equal value and can be exchanged for almost no cost, so we can sum them up.
1056
+ total_balance = current_balances.xdai + current_balances.wxdai
1057
+ return total_balance >= min_required_balance
1058
+
1059
+
1046
1060
  def withdraw_wxdai_to_xdai_to_keep_balance(
1047
1061
  api_keys: APIKeys,
1048
1062
  min_required_balance: xDai,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.46.0
3
+ Version: 0.47.0
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -15,7 +15,7 @@ prediction_market_agent_tooling/benchmark/agents.py,sha256=HPIFJvackW110ch3Ukktb
15
15
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=xiHKzZx5GHSsDerFHMZ9j_LXAXnSaITSvv67iPe3MEU,21095
16
16
  prediction_market_agent_tooling/benchmark/utils.py,sha256=iS1BzyXcCMfMm1Rx--1QCH0pHvBTblTndcDQFbTUJ2s,2897
17
17
  prediction_market_agent_tooling/config.py,sha256=3j1iMiJWntSkqQv5HllJgihgqf9I2_0e0LPncVFRi7g,5260
18
- prediction_market_agent_tooling/deploy/agent.py,sha256=QY19_fmYzhQCnS_BfnWbEF59gtNAD8dNebKZEcOI1uw,10809
18
+ prediction_market_agent_tooling/deploy/agent.py,sha256=qaFbPaiVlxOV_drXUasYwuJgoA37wyMoTRA5MRPDarg,11672
19
19
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=V_yakxDvG3WZWRsQq6-b2ZLA8pPPnf0Jrw8iGkGZGG8,1019
20
20
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
21
21
  prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5yp0GE9Mw5caYqlFUZQ2j3ks,3739
@@ -37,7 +37,7 @@ prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=6TBy17xn
37
37
  prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=uNF7LP4evvubk818g2zbX1VlnFxeUQOkNgx_e_LwaJA,3416
38
38
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
39
  prediction_market_agent_tooling/markets/omen/data_models.py,sha256=VCY-TD4RBCd63T1PtF5AwjPWbZ3MC02TGw_BAOEZSyc,14591
40
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=7n-UwtXVKVqbZoJhRGDPlsYPyHcdMGuiJpJCaQMsG3A,39488
40
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=fL8Lk1H0guwNBcgvT8Ymy3jRewbWLbJ9m8br4HN7vPg,40014
41
41
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=DWJk7GZgw_UxxFxdVeDJTcskWlJ8AchN0QaXWZrrh4E,23633
42
42
  prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=8uHWH1nMYiop4wOhSSoz3tdaexa-qb6KX10SiyaYYhA,10981
43
43
  prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=4F4QR8MDwyEw52rolEJNxtbCcIipX6ccNHANfWyCBjg,25945
@@ -75,8 +75,8 @@ prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0r
75
75
  prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
76
76
  prediction_market_agent_tooling/tools/utils.py,sha256=JE9YWtPPhnTgLiOyGAZDNG5K8nCwUY9IZEuAlm9UcxA,6611
77
77
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=nKRHmdLnWSKd3wpo-cysXGvhhrJ2Yf69sN2FFQfSt6s,10578
78
- prediction_market_agent_tooling-0.46.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
79
- prediction_market_agent_tooling-0.46.0.dist-info/METADATA,sha256=JPJovvxur7nBmA-1OSYVTWbsLtZxhR0AAvJkOHrVxhU,7634
80
- prediction_market_agent_tooling-0.46.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
81
- prediction_market_agent_tooling-0.46.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
82
- prediction_market_agent_tooling-0.46.0.dist-info/RECORD,,
78
+ prediction_market_agent_tooling-0.47.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
79
+ prediction_market_agent_tooling-0.47.0.dist-info/METADATA,sha256=y9NRHOcSEBx1b32DwPINwQQ1lqiaDoappIIayDz1rOI,7634
80
+ prediction_market_agent_tooling-0.47.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
81
+ prediction_market_agent_tooling-0.47.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
82
+ prediction_market_agent_tooling-0.47.0.dist-info/RECORD,,