prediction-market-agent-tooling 0.23.0__py3-none-any.whl → 0.24.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.
@@ -84,62 +84,30 @@ class Answer(BaseModel):
84
84
 
85
85
 
86
86
  class DeployableAgent:
87
- bet_on_n_markets_per_run: int = 1
88
-
89
87
  def __init__(self) -> None:
90
88
  self.langfuse_wrapper = LangfuseWrapper(agent_name=self.__class__.__name__)
91
89
  self.load()
92
90
 
93
91
  def __init_subclass__(cls, **kwargs: t.Any) -> None:
94
- if cls.__init__ is not DeployableAgent.__init__:
92
+ if "DeployableAgent" not in str(
93
+ cls.__init__
94
+ ) and "DeployableTraderAgent" not in str(cls.__init__):
95
95
  raise TypeError(
96
- "Cannot override __init__ method of DeployableAgent class, please override the `load` method to set up the agent."
96
+ "Cannot override __init__ method of deployable agent class, please override the `load` method to set up the agent."
97
97
  )
98
98
 
99
99
  def load(self) -> None:
100
100
  pass
101
101
 
102
- def have_bet_on_market_since(self, market: AgentMarket, since: timedelta) -> bool:
103
- return have_bet_on_market_since(keys=APIKeys(), market=market, since=since)
104
-
105
- def pick_markets(self, markets: t.Sequence[AgentMarket]) -> t.Sequence[AgentMarket]:
106
- """
107
- Subclasses can implement their own logic instead of this one, or on top of this one.
108
- By default, it picks only the first {n_markets_per_run} markets where user didn't bet recently and it's a reasonable question.
109
- """
110
- picked: list[AgentMarket] = []
111
-
112
- for market in markets:
113
- if len(picked) >= self.bet_on_n_markets_per_run:
114
- break
115
-
116
- if self.have_bet_on_market_since(market, since=timedelta(hours=24)):
117
- continue
118
-
119
- # Do as a last check, as it uses paid OpenAI API.
120
- if not is_predictable_binary(market.question):
121
- continue
122
-
123
- picked.append(market)
124
-
125
- return picked
126
-
127
- def answer_binary_market(self, market: AgentMarket) -> Answer | None:
128
- """
129
- Answer the binary market. This method must be implemented by the subclass.
130
- """
131
- raise NotImplementedError("This method must be implemented by the subclass")
132
-
133
102
  def deploy_local(
134
103
  self,
135
104
  market_type: MarketType,
136
105
  sleep_time: float,
137
106
  timeout: float,
138
- place_bet: bool,
139
107
  ) -> None:
140
108
  start_time = time.time()
141
109
  while True:
142
- self.run(market_type=market_type, _place_bet=place_bet)
110
+ self.run(market_type=market_type)
143
111
  time.sleep(sleep_time)
144
112
  if time.time() - start_time > timeout:
145
113
  break
@@ -223,6 +191,51 @@ def {entrypoint_function_name}(request) -> str:
223
191
  if cron_schedule:
224
192
  schedule_deployed_gcp_function(fname, cron_schedule=cron_schedule)
225
193
 
194
+ def run(self, market_type: MarketType) -> None:
195
+ raise NotImplementedError("This method must be implemented by the subclass.")
196
+
197
+ def get_gcloud_fname(self, market_type: MarketType) -> str:
198
+ return f"{self.__class__.__name__.lower()}-{market_type}-{datetime.now().strftime('%Y-%m-%d--%H-%M-%S')}"
199
+
200
+
201
+ class DeployableTraderAgent(DeployableAgent):
202
+ bet_on_n_markets_per_run: int = 1
203
+
204
+ def __init__(self, place_bet: bool = True) -> None:
205
+ super().__init__()
206
+ self.place_bet = place_bet
207
+
208
+ def have_bet_on_market_since(self, market: AgentMarket, since: timedelta) -> bool:
209
+ return have_bet_on_market_since(keys=APIKeys(), market=market, since=since)
210
+
211
+ def pick_markets(self, markets: t.Sequence[AgentMarket]) -> t.Sequence[AgentMarket]:
212
+ """
213
+ Subclasses can implement their own logic instead of this one, or on top of this one.
214
+ By default, it picks only the first {n_markets_per_run} markets where user didn't bet recently and it's a reasonable question.
215
+ """
216
+ picked: list[AgentMarket] = []
217
+
218
+ for market in markets:
219
+ if len(picked) >= self.bet_on_n_markets_per_run:
220
+ break
221
+
222
+ if self.have_bet_on_market_since(market, since=timedelta(hours=24)):
223
+ continue
224
+
225
+ # Do as a last check, as it uses paid OpenAI API.
226
+ if not is_predictable_binary(market.question):
227
+ continue
228
+
229
+ picked.append(market)
230
+
231
+ return picked
232
+
233
+ def answer_binary_market(self, market: AgentMarket) -> Answer | None:
234
+ """
235
+ Answer the binary market. This method must be implemented by the subclass.
236
+ """
237
+ raise NotImplementedError("This method must be implemented by the subclass")
238
+
226
239
  def calculate_bet_amount(self, answer: Answer, market: AgentMarket) -> BetAmount:
227
240
  """
228
241
  Calculate the bet amount. By default, it returns the minimum bet amount.
@@ -253,7 +266,7 @@ def {entrypoint_function_name}(request) -> str:
253
266
  # Omen is specific, because the user (agent) needs to manually withdraw winnings from the market.
254
267
  redeem_from_all_user_positions(private_credentials)
255
268
 
256
- def process_bets(self, market_type: MarketType, _place_bet: bool = True) -> None:
269
+ def process_bets(self, market_type: MarketType) -> None:
257
270
  """
258
271
  Processes bets placed by agents on a given market.
259
272
  """
@@ -264,7 +277,7 @@ def {entrypoint_function_name}(request) -> str:
264
277
  if result is None:
265
278
  logger.debug(f"Skipping market {market} as no answer was provided")
266
279
  continue
267
- if _place_bet:
280
+ if self.place_bet:
268
281
  amount = self.calculate_bet_amount(result, market)
269
282
  logger.debug(
270
283
  f"Placing bet on {market} with result {result} and amount {amount}"
@@ -277,10 +290,7 @@ def {entrypoint_function_name}(request) -> str:
277
290
  def after(self, market_type: MarketType) -> None:
278
291
  pass
279
292
 
280
- def run(self, market_type: MarketType, _place_bet: bool = True) -> None:
293
+ def run(self, market_type: MarketType) -> None:
281
294
  self.before(market_type)
282
- self.process_bets(market_type, _place_bet)
295
+ self.process_bets(market_type)
283
296
  self.after(market_type)
284
-
285
- def get_gcloud_fname(self, market_type: MarketType) -> str:
286
- return f"{self.__class__.__name__.lower()}-{market_type}-{datetime.now().strftime('%Y-%m-%d--%H-%M-%S')}"
@@ -3,13 +3,13 @@ import typing as t
3
3
 
4
4
  from prediction_market_agent_tooling.deploy.agent import (
5
5
  Answer,
6
- DeployableAgent,
6
+ DeployableTraderAgent,
7
7
  Probability,
8
8
  )
9
9
  from prediction_market_agent_tooling.markets.agent_market import AgentMarket
10
10
 
11
11
 
12
- class DeployableCoinFlipAgent(DeployableAgent):
12
+ class DeployableCoinFlipAgent(DeployableTraderAgent):
13
13
  def pick_markets(self, markets: t.Sequence[AgentMarket]) -> t.Sequence[AgentMarket]:
14
14
  return random.sample(markets, 1)
15
15
 
@@ -23,6 +23,6 @@ class DeployableCoinFlipAgent(DeployableAgent):
23
23
  )
24
24
 
25
25
 
26
- class DeployableAlwaysRaiseAgent(DeployableAgent):
26
+ class DeployableAlwaysRaiseAgent(DeployableTraderAgent):
27
27
  def answer_binary_market(self, market: AgentMarket) -> Answer | None:
28
28
  raise RuntimeError("I always raise!")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.23.0
3
+ Version: 0.24.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
@@ -12,8 +12,8 @@ prediction_market_agent_tooling/benchmark/agents.py,sha256=HPIFJvackW110ch3Ukktb
12
12
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=xiHKzZx5GHSsDerFHMZ9j_LXAXnSaITSvv67iPe3MEU,21095
13
13
  prediction_market_agent_tooling/benchmark/utils.py,sha256=iS1BzyXcCMfMm1Rx--1QCH0pHvBTblTndcDQFbTUJ2s,2897
14
14
  prediction_market_agent_tooling/config.py,sha256=FI8feNLmA0QYmN-llvyDh3c6tN2ZGl7Eerw1e27v51A,4757
15
- prediction_market_agent_tooling/deploy/agent.py,sha256=OxSL1w51GumyBUxN2cx6VPgvf8NWsq3-7wAy9g3hsFA,10018
16
- prediction_market_agent_tooling/deploy/agent_example.py,sha256=KaTJm43cwbBZR2BmTEyB1ohChAqwYlBUqaaVumsWQe4,891
15
+ prediction_market_agent_tooling/deploy/agent.py,sha256=M6qSZ1mN0AEwyix3WJal7ulifI0o-v89S2K_s_zTBbs,10292
16
+ prediction_market_agent_tooling/deploy/agent_example.py,sha256=tqXVA2HSFK3pdZ49tMmta8aKdJFT8JN8WeJ1akjrpBk,909
17
17
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
18
18
  prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5yp0GE9Mw5caYqlFUZQ2j3ks,3739
19
19
  prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py,sha256=qYIHRxQLac3yxtZ8ChikiPG9O1aUQucHW0muTSm1nto,2627
@@ -65,8 +65,8 @@ prediction_market_agent_tooling/tools/safe.py,sha256=h0xOO0eNtitClf0fPkn-0oTc6A_
65
65
  prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0rnVhtQGzwoUdAgn_7u_GBM,729
66
66
  prediction_market_agent_tooling/tools/utils.py,sha256=zkmwPi3YisgZDPCeNwaRbL8sInOYOkvFgFY4Q8PbEo4,5077
67
67
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=cboATXNmEdn5RmPbVblHOwOdUMKBYrUK3GiI6i6Vzxo,9855
68
- prediction_market_agent_tooling-0.23.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
- prediction_market_agent_tooling-0.23.0.dist-info/METADATA,sha256=gkLdQmTB2vbEO3toPUFru7h7BqsIvLm50aXGbNDK1xM,5563
70
- prediction_market_agent_tooling-0.23.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
- prediction_market_agent_tooling-0.23.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
- prediction_market_agent_tooling-0.23.0.dist-info/RECORD,,
68
+ prediction_market_agent_tooling-0.24.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
+ prediction_market_agent_tooling-0.24.0.dist-info/METADATA,sha256=k0OnkcYQbBhcrWsBS3hX8LjHzY_j3SJ3PHhEHgiIkJ4,5563
70
+ prediction_market_agent_tooling-0.24.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
+ prediction_market_agent_tooling-0.24.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
+ prediction_market_agent_tooling-0.24.0.dist-info/RECORD,,