prediction-market-agent-tooling 0.31.0__py3-none-any.whl → 0.32.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.
@@ -273,11 +273,11 @@ class DeployableTraderAgent(DeployableAgent):
273
273
  for market in markets:
274
274
  result = self.answer_binary_market(market)
275
275
  if result is None:
276
- logger.debug(f"Skipping market {market} as no answer was provided")
276
+ logger.info(f"Skipping market {market} as no answer was provided")
277
277
  continue
278
278
  if self.place_bet:
279
279
  amount = self.calculate_bet_amount(result, market)
280
- logger.debug(
280
+ logger.info(
281
281
  f"Placing bet on {market} with result {result} and amount {amount}"
282
282
  )
283
283
  market.place_bet(
@@ -156,7 +156,7 @@ class OmenAgentMarket(AgentMarket):
156
156
  )
157
157
 
158
158
  def sell_tokens(
159
- self, outcome: bool, amount: TokenAmount, auto_withdraw: bool = True
159
+ self, outcome: bool, amount: TokenAmount, auto_withdraw: bool = False
160
160
  ) -> None:
161
161
  if not self.can_be_traded():
162
162
  raise ValueError(
@@ -205,8 +205,9 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
205
205
  finalized_before
206
206
  )
207
207
 
208
+ # `excluded_question_titles` can not be an empty list, otherwise the API bugs out and returns nothing.
208
209
  excluded_question_titles = [""]
209
- if excluded_questions is not None:
210
+ if excluded_questions:
210
211
  excluded_question_titles = [i for i in excluded_questions]
211
212
 
212
213
  where_stms["question_"]["title_not_in"] = excluded_question_titles
@@ -439,6 +440,8 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
439
440
  market_id: t.Optional[ChecksumAddress] = None,
440
441
  filter_by_answer_finalized_not_null: bool = False,
441
442
  type_: t.Literal["Buy", "Sell"] | None = None,
443
+ market_opening_after: datetime | None = None,
444
+ collateral_amount_more_than: Wei | None = None,
442
445
  ) -> list[OmenBet]:
443
446
  if not end_time:
444
447
  end_time = utcnow()
@@ -457,6 +460,12 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
457
460
  where_stms.append(trade.fpmm == market_id.lower())
458
461
  if filter_by_answer_finalized_not_null:
459
462
  where_stms.append(trade.fpmm.answerFinalizedTimestamp != None)
463
+ if market_opening_after is not None:
464
+ where_stms.append(
465
+ trade.fpmm.openingTimestamp > to_int_timestamp(market_opening_after)
466
+ )
467
+ if collateral_amount_more_than is not None:
468
+ where_stms.append(trade.collateralAmount > collateral_amount_more_than)
460
469
 
461
470
  trades = self.trades_subgraph.Query.fpmmTrades(
462
471
  first=sys.maxsize, where=where_stms
@@ -473,6 +482,8 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
473
482
  end_time: t.Optional[datetime] = None,
474
483
  market_id: t.Optional[ChecksumAddress] = None,
475
484
  filter_by_answer_finalized_not_null: bool = False,
485
+ market_opening_after: datetime | None = None,
486
+ collateral_amount_more_than: Wei | None = None,
476
487
  ) -> list[OmenBet]:
477
488
  return self.get_trades(
478
489
  better_address=better_address,
@@ -481,6 +492,8 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
481
492
  market_id=market_id,
482
493
  filter_by_answer_finalized_not_null=filter_by_answer_finalized_not_null,
483
494
  type_="Buy", # We consider `bet` to be only the `Buy` trade types.
495
+ market_opening_after=market_opening_after,
496
+ collateral_amount_more_than=collateral_amount_more_than,
484
497
  )
485
498
 
486
499
  def get_resolved_bets(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.31.0
3
+ Version: 0.32.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
@@ -61,7 +61,6 @@ Deploying and monitoring agents using GCP requires that you set up the gcloud CL
61
61
 
62
62
  ```bash
63
63
  MANIFOLD_API_KEY=...
64
- BET_FROM_ADDRESS=...
65
64
  BET_FROM_PRIVATE_KEY=...
66
65
  OPENAI_API_KEY=...
67
66
  ```
@@ -76,46 +75,54 @@ For example:
76
75
 
77
76
  ```python
78
77
  import prediction_market_agent_tooling.benchmark.benchmark as bm
78
+ from prediction_market_agent_tooling.benchmark.agents import RandomAgent
79
79
  from prediction_market_agent_tooling.markets.markets import MarketType, get_binary_markets
80
80
 
81
81
  benchmarker = bm.Benchmarker(
82
82
  markets=get_binary_markets(limit=10, market_type=MarketType.MANIFOLD),
83
- agents=[...],
83
+ agents=[RandomAgent(agent_name="a_random_agent")],
84
84
  )
85
85
  benchmarker.run_agents()
86
86
  md = benchmarker.generate_markdown_report()
87
87
  ```
88
88
 
89
- This produces a markdown report comparing agents:
89
+ This produces a markdown report that you can use for comparing agents side-by-side, like:
90
90
 
91
91
  ![Benchmark results](assets/comparison-report.png)
92
92
 
93
93
  ## Deploying
94
94
 
95
- Create a deployable agent by subclassing the `DeployableAgent` base class, and implementing the
95
+ > **Deprecated**: We suggest using your own infrastructure to deploy, but you may still find this useful.
96
+
97
+ Create a deployable agent by subclassing the `DeployableTraderAgent` base class, and implementing the `answer_binary_market` method.
96
98
 
97
99
  For example, deploy an agent that randomly picks an outcome:
98
100
 
99
101
  ```python
100
102
  import random
101
- from prediction_market_agent_tooling.deploy.agent import DeployableAgent
103
+ from prediction_market_agent_tooling.deploy.agent import DeployableTraderAgent
102
104
  from prediction_market_agent_tooling.markets.agent_market import AgentMarket
103
105
 
104
- class DeployableCoinFlipAgent(DeployableAgent):
106
+ class DeployableCoinFlipAgent(DeployableTraderAgent):
105
107
  def answer_binary_market(self, market: AgentMarket) -> bool | None:
106
108
  return random.choice([True, False])
107
109
 
108
110
  DeployableCoinFlipAgent().deploy_gcp(...)
109
111
  ```
110
112
 
111
- For deploying a Safe manually for a given agent, run the script below:
113
+ ### Safe
114
+
115
+ Agents can control funds via a wallet primary key only, or optionally via a [Safe](https://safe.global/) as well. For deploying a Safe manually for a given agent, run the script below:
112
116
 
113
117
  ```commandline
114
118
  poetry run python scripts/create_safe_for_agent.py --from-private-key <YOUR_AGENT_PRIVATE_KEY> --salt-nonce 42
115
119
  ```
120
+
116
121
  This will output the newly created Safe in the terminal, and it can then be copied over to the deployment part (e.g. Terraform).
117
122
  Note that `salt_nonce` can be passed so that the created safe is deterministically created for each agent, so that, if the same `salt_nonce` is used, the script will not create a new Safe for the agent, instead it will output the previously existent Safe.
118
123
 
124
+ You can then specify this agent's Safe address with the `SAFE_ADDRESS` environment variable.
125
+
119
126
  ## Monitoring
120
127
 
121
128
  Monitor the performance of the agents deployed to GCP, as well as meta-metrics of the prediction market platforms they are deployed to.
@@ -132,15 +139,42 @@ Which launches in the browser:
132
139
 
133
140
  ## The Market Platforms
134
141
 
135
- The following markets platforms are supported:
142
+ The following prediction market platforms are supported:
143
+
144
+ | Platform | Benchmarking | Deployment | Monitoring |
145
+ |---------------------------------------|--------------|------------|------------|
146
+ | [Manifold](https://manifold.markets/) | ✅ | ✅ | ✅ |
147
+ | [AIOmen](https://aiomen.eth.limo/) | ✅ | ✅ | ✅ |
148
+ | [Polymarket](https://polymarket.com/) | ✅ | ❌ | ❌ |
149
+
150
+ ## Prediction Markets Python API
151
+
152
+ We have built clean abstractions for taking actions on the different prediction market platforms (retrieving markets, buying and selling tokens, etc.). This is currently undocumented, but for now, inspecting the [`AgentMarket`](https://github.com/gnosis/prediction-market-agent-tooling/blob/1e497fff9f2b53e4e3e1beb5dda08b4d49da881b/prediction_market_agent_tooling/markets/agent_market.py) class and its methods is your best bet.
153
+
154
+ For example:
155
+
156
+ ```python
157
+ from prediction_market_agent_tooling.config import APIKeys
158
+ from prediction_market_agent_tooling.markets.agent_market import SortBy
159
+ from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket
160
+
161
+ # Place a bet on the market closing soonest
162
+ market = OmenAgentMarket.get_binary_markets(limit=1, sort_by=SortBy.CLOSING_SOONEST)[0]
163
+ market.place_bet(outcome=True, amount=market.get_bet_amount(0.1))
164
+
165
+ # View your positions
166
+ my_positions = OmenAgentMarket.get_positions(user_id=APIKeys().bet_from_address)
167
+ print(my_positions)
168
+
169
+ # Sell position (accounting for fees)
170
+ market.sell_tokens(outcome=True, amount=market.get_bet_amount(0.095))
171
+ ```
136
172
 
137
- - [Manifold](https://manifold.markets/)
138
- - [AIOmen](https://aiomen.eth.limo/)
139
- - [Polymarket](https://polymarket.com/) - Benchmarking only. Deploy and monitor TODO
173
+ This API can be built on top of to create your application. See [here](https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/microchain_agent) for an example.
140
174
 
141
175
  ## Contributing
142
176
 
143
- See the [Issues](https://github.com/gnosis/prediction-market-agent-tooling/issues) for ideas of things that need fixing or implementing. Or come up with your own :D.
177
+ See the [Issues](https://github.com/gnosis/prediction-market-agent-tooling/issues) for ideas of things that need fixing or implementing. The team is also receptive to new issues and PRs.
144
178
 
145
179
  We use `mypy` for static type checking, and `isort`, `black` and `autoflake` for linting. These all run as steps in CI.
146
180
 
@@ -12,7 +12,7 @@ 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=yELIlzAm2yBwZzGRvHtHBZZV3NZy5CllJfo3chMQMo0,4297
15
- prediction_market_agent_tooling/deploy/agent.py,sha256=P4MaueaXpNakAWXhB0EYsWLNRXSeRisaN55IVDb8AR8,10187
15
+ prediction_market_agent_tooling/deploy/agent.py,sha256=h33uU97x3DjBy8INONtS1Hc5B-NnNDV6MENeeCp0qoA,10185
16
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
@@ -31,10 +31,10 @@ prediction_market_agent_tooling/markets/manifold/utils.py,sha256=cPPFWXm3vCYH1jy
31
31
  prediction_market_agent_tooling/markets/markets.py,sha256=w05Oo7yCA2axpCw69Q9y4i9Gcdpht0u5bZGbWqld3rU,2964
32
32
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  prediction_market_agent_tooling/markets/omen/data_models.py,sha256=EXtjmcujx68Xu50BVkYXvLuf_Asx5o65RvFS3ZS6HGs,14405
34
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=wQIdECDREiRnUROlp1BF1W25so_Gs-9YXKjjj0kksAs,32041
34
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=9le-tvs-zclHtzpvK7bMVqg2lZV-VZh1c5OB_uAdSiY,32042
35
35
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=eDS8vN4Klv_-Y1wwfIeLDt3twhl9U_AJjPQov0JScb0,19888
36
36
  prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=g77QsQ5WnSI2rzBlX87L_EhWMwobkyXyfRhHQmpAdzo,9012
37
- prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=QZWwkqvOqQ-b15jidwTNsn1K64x3FY_Un-l6A6g3Twg,22299
37
+ prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=RlaQMDF75lo2fos8LUb_OAdrw_ILLOXQLdejzE7tOmA,23053
38
38
  prediction_market_agent_tooling/markets/polymarket/api.py,sha256=HXmA1akA0qDj0m3e-GEvWG8x75pm6BX4H7YJPQcST7I,4767
39
39
  prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=9CJzakyEcsn6DQBK2nOXjOMzTZBLAmK_KqevXvW17DI,4292
40
40
  prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=f8SRQy0Rn-gIHSEMrJJAI8H3J7l8lzOLj3aCMe0vJv8,11324
@@ -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.31.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
- prediction_market_agent_tooling-0.31.0.dist-info/METADATA,sha256=LKQcmOFaHJoGx4mocx4Gh04ErtMk-D-F9sRRJBNvE5s,5465
70
- prediction_market_agent_tooling-0.31.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
- prediction_market_agent_tooling-0.31.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
- prediction_market_agent_tooling-0.31.0.dist-info/RECORD,,
68
+ prediction_market_agent_tooling-0.32.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
+ prediction_market_agent_tooling-0.32.0.dist-info/METADATA,sha256=Xs3kCp-N5XHtsM_LuoVRJTg0orQMWgWLJT0U8DEah74,7514
70
+ prediction_market_agent_tooling-0.32.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
+ prediction_market_agent_tooling-0.32.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
+ prediction_market_agent_tooling-0.32.0.dist-info/RECORD,,