prediction-market-agent-tooling 0.28.0__py3-none-any.whl → 0.29.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.
@@ -88,7 +88,9 @@ def print_using_loguru_info(
88
88
 
89
89
 
90
90
  def simple_warning_format(message, category, filename, lineno, line=None): # type: ignore[no-untyped-def] # Not typed in the standard library neither.
91
- return f"{category.__name__}: {message}"
91
+ return f"{category.__name__}: {message}".strip().replace(
92
+ "\n", "\\n"
93
+ ) # Escape new lines, because otherwise logs will be broken.
92
94
 
93
95
 
94
96
  if not getattr(logger, "_patched", False):
@@ -422,7 +422,7 @@ class RealityQuestion(BaseModel):
422
422
  # And because all the contract methods so far needed bytes32 input, when asked for question id, `questionId` field was the correct one to use so far.
423
423
  id: str
424
424
  user: HexAddress
425
- historyHash: HexBytes
425
+ historyHash: HexBytes | None
426
426
  updatedTimestamp: datetime
427
427
  contentHash: HexBytes
428
428
  questionId: HexBytes
@@ -31,6 +31,7 @@ from prediction_market_agent_tooling.markets.omen.omen_subgraph_handler import (
31
31
  from prediction_market_agent_tooling.markets.polymarket.utils import (
32
32
  find_resolution_on_polymarket,
33
33
  )
34
+ from prediction_market_agent_tooling.tools.utils import check_not_none
34
35
  from prediction_market_agent_tooling.tools.web3_utils import ZERO_BYTES, xdai_to_wei
35
36
 
36
37
 
@@ -95,7 +96,12 @@ def claim_bonds_on_realitio_question(
95
96
  # TODO: See `if len(answers_objects) > 1` above.
96
97
  # This is from the original Olas implementation (https://github.com/kongzii/trader/blob/700af475a4538cc3d5d22caf9dec9e9d22d72af1/packages/valory/skills/market_manager_abci/graph_tooling/requests.py#L297),
97
98
  # but it's most probably wrong (see comment above).
98
- history_hashes.append(answers_objects[i + 1].question.historyHash)
99
+ history_hashes.append(
100
+ check_not_none(
101
+ answers_objects[i + 1].question.historyHash,
102
+ "Shouldn't be None here.",
103
+ )
104
+ )
99
105
 
100
106
  # last-to-first, the address of each answerer or commitment sender
101
107
  addresses.append(Web3.to_checksum_address(answer.question.user))
@@ -1,6 +1,8 @@
1
1
  import typing as t
2
2
 
3
3
  import requests
4
+ import tenacity
5
+ from loguru import logger
4
6
 
5
7
  from prediction_market_agent_tooling.markets.polymarket.data_models import (
6
8
  POLYMARKET_FALSE_OUTCOME,
@@ -18,6 +20,27 @@ POLYMARKET_API_BASE_URL = "https://clob.polymarket.com/"
18
20
  MARKETS_LIMIT = 100 # Polymarket will only return up to 100 markets
19
21
 
20
22
 
23
+ @tenacity.retry(
24
+ stop=tenacity.stop_after_attempt(5),
25
+ wait=tenacity.wait_chain(*[tenacity.wait_fixed(n) for n in range(1, 6)]),
26
+ after=lambda x: logger.debug(f"get_polymarkets failed, {x.attempt_number=}."),
27
+ )
28
+ def get_polymarkets(
29
+ limit: int,
30
+ with_rewards: bool = False,
31
+ next_cursor: str | None = None,
32
+ ) -> MarketsEndpointResponse:
33
+ url = (
34
+ f"{POLYMARKET_API_BASE_URL}/{'sampling-markets' if with_rewards else 'markets'}"
35
+ )
36
+ params: dict[str, str | int | float | None] = {
37
+ "limit": min(limit, MARKETS_LIMIT),
38
+ }
39
+ if next_cursor is not None:
40
+ params["next_cursor"] = next_cursor
41
+ return response_to_model(requests.get(url, params=params), MarketsEndpointResponse)
42
+
43
+
21
44
  def get_polymarket_binary_markets(
22
45
  limit: int,
23
46
  closed: bool | None = False,
@@ -28,17 +51,13 @@ def get_polymarket_binary_markets(
28
51
  """
29
52
  See https://learn.polymarket.com/trading-rewards for information about rewards.
30
53
  """
31
- url = (
32
- f"{POLYMARKET_API_BASE_URL}/{'sampling-markets' if with_rewards else 'markets'}"
33
- )
54
+
34
55
  all_markets: list[PolymarketMarketWithPrices] = []
35
- params: dict[str, str | int | float | None] = {
36
- "limit": min(limit, MARKETS_LIMIT),
37
- }
56
+ next_cursor: str | None = None
38
57
 
39
58
  while True:
40
- response = response_to_model(
41
- requests.get(url, params=params), MarketsEndpointResponse
59
+ response = get_polymarkets(
60
+ limit, with_rewards=with_rewards, next_cursor=next_cursor
42
61
  )
43
62
 
44
63
  for market in response.data:
@@ -81,12 +100,12 @@ def get_polymarket_binary_markets(
81
100
  if len(all_markets) >= limit:
82
101
  break
83
102
 
84
- if response.next_cursor == "LTE=":
103
+ next_cursor = response.next_cursor
104
+
105
+ if next_cursor == "LTE=":
85
106
  # 'LTE=' means the end.
86
107
  break
87
108
 
88
- params["next_cursor"] = response.next_cursor
89
-
90
109
  return all_markets[:limit]
91
110
 
92
111
 
@@ -32,8 +32,8 @@ class PolymarketMarket(BaseModel):
32
32
  active: bool
33
33
  closed: bool
34
34
  archived: bool
35
- minimum_order_size: str
36
- minimum_tick_size: str
35
+ minimum_order_size: str | float
36
+ minimum_tick_size: str | float
37
37
  condition_id: str
38
38
  question_id: str
39
39
  question: str
@@ -54,8 +54,8 @@ class PolymarketMarket(BaseModel):
54
54
  rewards: PolymarketRewards
55
55
  tokens: tuple[PolymarketToken, ...]
56
56
  is_50_50_outcome: bool
57
- categories: list[str]
58
- parent_categories: list[str]
57
+ categories: list[str] | None = None
58
+ parent_categories: list[str] | None = None
59
59
  accepting_orders: bool
60
60
 
61
61
  @property
@@ -208,6 +208,25 @@ class Category(BaseModel):
208
208
  slug: str
209
209
 
210
210
 
211
+ class Bid(BaseModel):
212
+ price: str
213
+ size: str
214
+
215
+
216
+ class Ask(BaseModel):
217
+ price: str
218
+ size: str
219
+
220
+
221
+ class MarketBidsAndAsks(BaseModel):
222
+ market: str
223
+ asset_id: str
224
+ hash: str
225
+ bids: list[Bid]
226
+ asks: list[Ask]
227
+ lastUpdated: int
228
+
229
+
211
230
  class PolymarketFullMarket(BaseModel):
212
231
  id: str
213
232
  ticker: str
@@ -231,7 +250,7 @@ class PolymarketFullMarket(BaseModel):
231
250
  liquidity: USDC | None
232
251
  volume: USDC | None
233
252
  volume24hr: USDC | None
234
- competitive: float
253
+ competitive: float | None
235
254
  openInterest: int | None
236
255
  sortBy: str | None
237
256
  createdAt: datetime
@@ -327,7 +346,12 @@ class PriceSide(BaseModel):
327
346
 
328
347
  class State(BaseModel):
329
348
  data: (
330
- PolymarketFullMarket | PriceSide | None
349
+ PolymarketFullMarket
350
+ | MarketBidsAndAsks
351
+ | PriceSide
352
+ | dict[str, MarketBidsAndAsks]
353
+ | dict[str, PriceSide]
354
+ | None
331
355
  ) # It's none if you go to the website and it says "Oops...we didn't forecast this".
332
356
  dataUpdateCount: int
333
357
  dataUpdatedAt: int
@@ -9,7 +9,11 @@ from prediction_market_agent_tooling.tools.google import search_google
9
9
  def find_resolution_on_polymarket(question: str) -> Resolution | None:
10
10
  full_market = find_full_polymarket(question)
11
11
  # TODO: Only main markets are supported right now, add logic for others if needed.
12
- return full_market.main_market.resolution if full_market else None
12
+ return (
13
+ full_market.main_market.resolution
14
+ if full_market and full_market.is_main_market
15
+ else None
16
+ )
13
17
 
14
18
 
15
19
  def find_full_polymarket(question: str) -> PolymarketFullMarket | None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.28.0
3
+ Version: 0.29.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
@@ -19,7 +19,7 @@ prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5
19
19
  prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py,sha256=qYIHRxQLac3yxtZ8ChikiPG9O1aUQucHW0muTSm1nto,2627
20
20
  prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=oyW0jgrUT2Tr49c7GlpcMsYNQjoCSOcWis3q-MmVAhU,6089
21
21
  prediction_market_agent_tooling/gtypes.py,sha256=xGSJXw12hzp8LwvQ956l01GiZMWd07MZTYqo8CXVeLY,2417
22
- prediction_market_agent_tooling/loggers.py,sha256=gG92EeLAxqFqAm9E_Uz5dFXL_FC-8x9zszI9a-4A1Os,2898
22
+ prediction_market_agent_tooling/loggers.py,sha256=p_ibaEpUGGdcpPtzIJxh5UusJNCQyN1y_RDvoTaeUfA,3001
23
23
  prediction_market_agent_tooling/markets/agent_market.py,sha256=I1r83EU5yMJ1dJhCqZjJ523XOElhBkb96oGDxbr4mlU,6818
24
24
  prediction_market_agent_tooling/markets/categorize.py,sha256=yTd-lDMPW4ESDSzmxeLLBuzLX0FggOF7Vbswh7295o0,941
25
25
  prediction_market_agent_tooling/markets/data_models.py,sha256=uODY3aoFp8YYeLAUcrzMk1yU8pIKsTLobB9xIEGTmKs,1170
@@ -30,16 +30,16 @@ prediction_market_agent_tooling/markets/manifold/manifold.py,sha256=DJZ88r5BGtAu
30
30
  prediction_market_agent_tooling/markets/manifold/utils.py,sha256=cPPFWXm3vCYH1jy7_ctJZuQH9ZDaPL4_AgAYzGWkoow,513
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
- prediction_market_agent_tooling/markets/omen/data_models.py,sha256=f7RO1Zvytii-M2koGuLQiPERjTq_DsDjrT01mar_sX4,14398
33
+ prediction_market_agent_tooling/markets/omen/data_models.py,sha256=EXtjmcujx68Xu50BVkYXvLuf_Asx5o65RvFS3ZS6HGs,14405
34
34
  prediction_market_agent_tooling/markets/omen/omen.py,sha256=UeBKfiEzTVZMRJ-r6YHXdlrMniwz3V1Te2yZgNX64rA,31902
35
35
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=eDS8vN4Klv_-Y1wwfIeLDt3twhl9U_AJjPQov0JScb0,19888
36
- prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=-qssaOJweI_QktR7bQiYjn-V6T_bBTQOH9qQjG35D48,8809
36
+ prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=g77QsQ5WnSI2rzBlX87L_EhWMwobkyXyfRhHQmpAdzo,9012
37
37
  prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=QZWwkqvOqQ-b15jidwTNsn1K64x3FY_Un-l6A6g3Twg,22299
38
- prediction_market_agent_tooling/markets/polymarket/api.py,sha256=p1JkqL9kF8C04qbmqFzF0hgtzD5kN3yup2hYOjxazQ4,4188
39
- prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=srTl8-0FM76AGLRDWzjLpf46ikWloaBCgkn0XqZoKCI,4248
40
- prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=_GCa3P60W8kNeg_8kF20CZF0hvaM2RR4FhTcDfXwF2o,10950
38
+ prediction_market_agent_tooling/markets/polymarket/api.py,sha256=HXmA1akA0qDj0m3e-GEvWG8x75pm6BX4H7YJPQcST7I,4767
39
+ prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=9CJzakyEcsn6DQBK2nOXjOMzTZBLAmK_KqevXvW17DI,4292
40
+ prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=f8SRQy0Rn-gIHSEMrJJAI8H3J7l8lzOLj3aCMe0vJv8,11324
41
41
  prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=zqGfiUOH9f7jmDcQAt30wrHyfmqLMNwCYtotsxFoJmA,2678
42
- prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=Gwd2kOK_DrsjtyqgO6ob8oK7tjsB1Yo-Hf7IS5UGnio,1960
42
+ prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=m4JG6WULh5epCJt4XBMHg0ae5NoVhqlOvAl0A7DR9iM,2023
43
43
  prediction_market_agent_tooling/monitor/langfuse/langfuse_wrapper.py,sha256=b6T69YB1x8kSUvW9uRFuSWPLOrXzapZG7m5O5SU0QTQ,895
44
44
  prediction_market_agent_tooling/monitor/markets/manifold.py,sha256=GdYpgRX1GahDi-75Mr53jgtEg6nWcs_rHDUkg4o_7dQ,3352
45
45
  prediction_market_agent_tooling/monitor/markets/omen.py,sha256=jOLPnIbDU9syjnYtHfOb2xa6-Ize3vbplgh-8WWkuT4,3323
@@ -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.28.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
- prediction_market_agent_tooling-0.28.0.dist-info/METADATA,sha256=NtheDRRimzmgtWXNLObDx0rKM3ZvZT3toRmpCNV04oY,5465
70
- prediction_market_agent_tooling-0.28.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
- prediction_market_agent_tooling-0.28.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
- prediction_market_agent_tooling-0.28.0.dist-info/RECORD,,
68
+ prediction_market_agent_tooling-0.29.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
+ prediction_market_agent_tooling-0.29.0.dist-info/METADATA,sha256=o_gMRsvw7wrtl0JcbGw11_I-wyNA7VzW5GDlNqeR9tM,5465
70
+ prediction_market_agent_tooling-0.29.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
+ prediction_market_agent_tooling-0.29.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
+ prediction_market_agent_tooling-0.29.0.dist-info/RECORD,,