prediction-market-agent-tooling 0.46.0__py3-none-any.whl → 0.47.1__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__()
@@ -209,6 +216,19 @@ class DeployableTraderAgent(DeployableAgent):
209
216
  def have_bet_on_market_since(self, market: AgentMarket, since: timedelta) -> bool:
210
217
  return have_bet_on_market_since(keys=APIKeys(), market=market, since=since)
211
218
 
219
+ def check_min_required_balance_to_operate(self, market_type: MarketType) -> None:
220
+ api_keys = APIKeys()
221
+ if self.min_required_balance_to_operate is None:
222
+ return
223
+ if market_type == MarketType.OMEN and not is_minimum_required_balance(
224
+ api_keys.public_key,
225
+ min_required_balance=self.min_required_balance_to_operate,
226
+ ):
227
+ raise OutOfFundsError(
228
+ f"Minimum required balance {self.min_required_balance_to_operate} "
229
+ f"for agent with address {api_keys.public_key} is not met."
230
+ )
231
+
212
232
  def pick_markets(
213
233
  self, market_type: MarketType, markets: t.Sequence[AgentMarket]
214
234
  ) -> t.Sequence[AgentMarket]:
@@ -273,10 +293,14 @@ class DeployableTraderAgent(DeployableAgent):
273
293
  if market_type == MarketType.OMEN:
274
294
  # Omen is specific, because the user (agent) needs to manually withdraw winnings from the market.
275
295
  redeem_from_all_user_positions(api_keys)
296
+ self.check_min_required_balance_to_operate(market_type)
276
297
  # 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
- )
298
+ if self.min_balance_to_keep_in_native_currency is not None:
299
+ withdraw_wxdai_to_xdai_to_keep_balance(
300
+ api_keys,
301
+ min_required_balance=self.min_balance_to_keep_in_native_currency,
302
+ withdraw_multiplier=2,
303
+ )
280
304
 
281
305
  def process_bets(self, market_type: MarketType) -> None:
282
306
  """
@@ -285,6 +309,8 @@ class DeployableTraderAgent(DeployableAgent):
285
309
  available_markets = self.get_markets(market_type)
286
310
  markets = self.pick_markets(market_type, available_markets)
287
311
  for market in markets:
312
+ # We need to check it again before each market bet, as the balance might have changed.
313
+ self.check_min_required_balance_to_operate(market_type)
288
314
  result = self.answer_binary_market(market)
289
315
  if result is None:
290
316
  logger.info(f"Skipping market {market} as no answer was provided")
@@ -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.1
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=Bj4L-zgUprLqcCENGZR205GaK52lu2iQwFspJDN0jgY,12017
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.1.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
79
+ prediction_market_agent_tooling-0.47.1.dist-info/METADATA,sha256=jgYABVYq6hJlFc-OorHN0sGi74IDD34xqhthepX26vM,7634
80
+ prediction_market_agent_tooling-0.47.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
81
+ prediction_market_agent_tooling-0.47.1.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
82
+ prediction_market_agent_tooling-0.47.1.dist-info/RECORD,,