prediction-market-agent-tooling 0.27.0__py3-none-any.whl → 0.28.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.
@@ -1,5 +1,7 @@
1
+ import builtins
1
2
  import logging
2
3
  import sys
4
+ import typing as t
3
5
  import warnings
4
6
  from enum import Enum
5
7
 
@@ -35,9 +37,11 @@ def patch_logger() -> None:
35
37
  format_loguru = GCP_LOG_LOGURU_FORMAT
36
38
  format_logging = GCP_LOG_LOGGING_FORMAT
37
39
  datefmt_logging = GCP_LOG_FORMAT_LOGGING_DATEFMT
40
+ print_logging = print_using_loguru_info
38
41
 
39
42
  elif config.LOG_FORMAT == LogFormat.DEFAULT:
40
43
  format_loguru, format_logging, datefmt_logging = None, None, None
44
+ print_logging = None
41
45
 
42
46
  else:
43
47
  raise ValueError(f"Unknown log format: {config.LOG_FORMAT}")
@@ -63,9 +67,26 @@ def patch_logger() -> None:
63
67
  # Use logging module for warnings.
64
68
  logging.captureWarnings(True)
65
69
 
70
+ # Use loguru for prints.
71
+ if print_logging is not None:
72
+ builtins.print = print_logging # type: ignore[assignment] # Monkey patching, it's messy but it works.
73
+
66
74
  logger.info(f"Patched logger for {config.LOG_FORMAT.value} format.")
67
75
 
68
76
 
77
+ def print_using_loguru_info(
78
+ *values: object,
79
+ sep: str = " ",
80
+ end: str = "\n",
81
+ **kwargs: t.Any,
82
+ ) -> None:
83
+ message = sep.join(map(str, values)) + end
84
+ message = message.strip().replace(
85
+ "\n", "\\n"
86
+ ) # Escape new lines, because otherwise logs will be broken.
87
+ logger.info(message)
88
+
89
+
69
90
  def simple_warning_format(message, category, filename, lineno, line=None): # type: ignore[no-untyped-def] # Not typed in the standard library neither.
70
91
  return f"{category.__name__}: {message}"
71
92
 
@@ -18,6 +18,7 @@ from prediction_market_agent_tooling.tools.utils import (
18
18
  add_utc_timezone_validator,
19
19
  check_not_none,
20
20
  should_not_happen,
21
+ utcnow,
21
22
  )
22
23
 
23
24
 
@@ -147,9 +148,18 @@ class AgentMarket(BaseModel):
147
148
  ) -> list[Bet]:
148
149
  raise NotImplementedError("Subclasses must implement this method")
149
150
 
151
+ def is_closed(self) -> bool:
152
+ return self.close_time is not None and self.close_time <= utcnow()
153
+
150
154
  def is_resolved(self) -> bool:
151
155
  return self.resolution is not None
152
156
 
157
+ def get_liquidity(self) -> TokenAmount:
158
+ raise NotImplementedError("Subclasses must implement this method")
159
+
160
+ def has_liquidity(self) -> bool:
161
+ return self.get_liquidity().amount > 0
162
+
153
163
  def has_successful_resolution(self) -> bool:
154
164
  return self.resolution in [Resolution.YES, Resolution.NO]
155
165
 
@@ -174,8 +184,15 @@ class AgentMarket(BaseModel):
174
184
  raise NotImplementedError("Subclasses must implement this method")
175
185
 
176
186
  @classmethod
177
- def get_positions(cls, user_id: str) -> list[Position]:
187
+ def get_positions(cls, user_id: str, liquid_only: bool = False) -> list[Position]:
178
188
  """
179
189
  Get all non-zero positions a user has in any market.
190
+
191
+ If `liquid_only` is True, only return positions that can be sold.
180
192
  """
181
193
  raise NotImplementedError("Subclasses must implement this method")
194
+
195
+ def can_be_traded(self) -> bool:
196
+ if self.is_closed() or not self.has_liquidity():
197
+ return False
198
+ return True
@@ -117,11 +117,17 @@ class OmenAgentMarket(AgentMarket):
117
117
  else None
118
118
  )
119
119
 
120
- def get_liquidity(self) -> Wei:
120
+ def get_liquidity_in_wei(self) -> Wei:
121
121
  return self.get_contract().totalSupply()
122
122
 
123
123
  def get_liquidity_in_xdai(self) -> xDai:
124
- return wei_to_xdai(self.get_liquidity())
124
+ return wei_to_xdai(self.get_liquidity_in_wei())
125
+
126
+ def get_liquidity(self) -> TokenAmount:
127
+ return TokenAmount(
128
+ amount=self.get_liquidity_in_xdai(),
129
+ currency=Currency.xDai,
130
+ )
125
131
 
126
132
  def get_tiny_bet_amount(self) -> BetAmount:
127
133
  return BetAmount(amount=0.00001, currency=self.currency)
@@ -133,6 +139,10 @@ class OmenAgentMarket(AgentMarket):
133
139
  omen_auto_deposit: bool = True,
134
140
  web3: Web3 | None = None,
135
141
  ) -> None:
142
+ if not self.can_be_traded():
143
+ raise ValueError(
144
+ f"Market {self.id} is not open for trading. Cannot place bet."
145
+ )
136
146
  if amount.currency != self.currency:
137
147
  raise ValueError(f"Omen bets are made in xDai. Got {amount.currency}.")
138
148
  amount_xdai = xDai(amount.amount)
@@ -148,6 +158,10 @@ class OmenAgentMarket(AgentMarket):
148
158
  def sell_tokens(
149
159
  self, outcome: bool, amount: TokenAmount, auto_withdraw: bool = True
150
160
  ) -> None:
161
+ if not self.can_be_traded():
162
+ raise ValueError(
163
+ f"Market {self.id} is not open for trading. Cannot sell tokens."
164
+ )
151
165
  binary_omen_sell_outcome_tx(
152
166
  api_keys=APIKeys(),
153
167
  amount=xDai(amount.amount),
@@ -301,7 +315,7 @@ class OmenAgentMarket(AgentMarket):
301
315
  )
302
316
 
303
317
  @classmethod
304
- def get_positions(cls, user_id: str) -> list[Position]:
318
+ def get_positions(cls, user_id: str, liquid_only: bool = False) -> list[Position]:
305
319
  sgh = OmenSubgraphHandler()
306
320
  omen_positions = sgh.get_user_positions(
307
321
  better_address=Web3.to_checksum_address(user_id),
@@ -329,6 +343,11 @@ class OmenAgentMarket(AgentMarket):
329
343
  positions = []
330
344
  for condition_id, omen_positions in omen_positions_dict.items():
331
345
  market = cls.from_data_model(omen_markets[condition_id])
346
+
347
+ # Skip markets that cannot be traded if `liquid_only`` is True.
348
+ if liquid_only and not market.can_be_traded():
349
+ continue
350
+
332
351
  amounts: dict[OutcomeStr, TokenAmount] = {}
333
352
  for omen_position in omen_positions:
334
353
  outecome_str = market.index_set_to_outcome_str(
@@ -83,7 +83,7 @@ class Market(BaseModel):
83
83
  category: t.Any | None
84
84
  ammType: t.Any | None
85
85
  description: str
86
- liquidity: str
86
+ liquidity: str | None
87
87
  startDate: datetime
88
88
  createdAt: datetime
89
89
  xAxisValue: t.Any | None
@@ -128,7 +128,7 @@ class Market(BaseModel):
128
128
  umaResolutionStatus: t.Any | None
129
129
  curationOrder: t.Any | None
130
130
  volumeNum: USDC | None
131
- liquidityNum: float
131
+ liquidityNum: float | None
132
132
  endDateIso: datetime | None
133
133
  startDateIso: datetime | None
134
134
  umaEndDateIso: datetime | None
@@ -137,8 +137,8 @@ class Market(BaseModel):
137
137
  gameStartTime: datetime | None
138
138
  secondsDelay: int | None
139
139
  clobTokenIds: list[str]
140
- liquidityAmm: float
141
- liquidityClob: float
140
+ liquidityAmm: float | None
141
+ liquidityClob: float | None
142
142
  makerBaseFee: int | None
143
143
  takerBaseFee: int | None
144
144
  negRisk: t.Any | None
@@ -163,7 +163,7 @@ class Market(BaseModel):
163
163
  closed_time: t.Any | None
164
164
  wide_format: bool | None
165
165
  volume_num: USDC | None
166
- liquidity_num: USDC
166
+ liquidity_num: USDC | None
167
167
  image_raw: str
168
168
  resolutionData: ResolutionData
169
169
 
@@ -228,7 +228,7 @@ class PolymarketFullMarket(BaseModel):
228
228
  new: bool
229
229
  featured: bool
230
230
  restricted: bool
231
- liquidity: USDC
231
+ liquidity: USDC | None
232
232
  volume: USDC | None
233
233
  volume24hr: USDC | None
234
234
  competitive: float
@@ -239,8 +239,8 @@ class PolymarketFullMarket(BaseModel):
239
239
  disqusThread: t.Any | None
240
240
  updatedAt: datetime
241
241
  enableOrderBook: bool
242
- liquidityAmm: float
243
- liquidityClob: float
242
+ liquidityAmm: float | None
243
+ liquidityClob: float | None
244
244
  imageOptimized: ImageOptimized | None
245
245
  iconOptimized: IconOptimized | None
246
246
  featuredImageOptimized: str | None
@@ -248,7 +248,7 @@ class PolymarketFullMarket(BaseModel):
248
248
  negRiskMarketID: t.Any | None
249
249
  negRiskFeeBips: t.Any | None
250
250
  markets: list[Market]
251
- categories: list[Category] | None
251
+ categories: list[Category] | None = None
252
252
  series: t.Any | None
253
253
  image_raw: str
254
254
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.27.0
3
+ Version: 0.28.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,8 +19,8 @@ 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=0znHrzxSbeBaDiB920EZC6a2TiF0tw80Sa_yoLwvo_w,2289
23
- prediction_market_agent_tooling/markets/agent_market.py,sha256=b2gsqEXADJir_LxcNUmzEfxGCcJ_V5mWPGM2SZfIA6M,6250
22
+ prediction_market_agent_tooling/loggers.py,sha256=gG92EeLAxqFqAm9E_Uz5dFXL_FC-8x9zszI9a-4A1Os,2898
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
26
26
  prediction_market_agent_tooling/markets/manifold/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -31,13 +31,13 @@ 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=f7RO1Zvytii-M2koGuLQiPERjTq_DsDjrT01mar_sX4,14398
34
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=YcM9AbBUOJ1xoZTI9UlHZTSNR4T1cTwyl3lZlXy2qbs,31209
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
36
  prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=-qssaOJweI_QktR7bQiYjn-V6T_bBTQOH9qQjG35D48,8809
37
37
  prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=QZWwkqvOqQ-b15jidwTNsn1K64x3FY_Un-l6A6g3Twg,22299
38
38
  prediction_market_agent_tooling/markets/polymarket/api.py,sha256=p1JkqL9kF8C04qbmqFzF0hgtzD5kN3yup2hYOjxazQ4,4188
39
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=qop9lK4-3VfEJ9SuSCJdYPhjMqP4g6F5FpHziJv8HDY,10887
40
+ prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=_GCa3P60W8kNeg_8kF20CZF0hvaM2RR4FhTcDfXwF2o,10950
41
41
  prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=zqGfiUOH9f7jmDcQAt30wrHyfmqLMNwCYtotsxFoJmA,2678
42
42
  prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=Gwd2kOK_DrsjtyqgO6ob8oK7tjsB1Yo-Hf7IS5UGnio,1960
43
43
  prediction_market_agent_tooling/monitor/langfuse/langfuse_wrapper.py,sha256=b6T69YB1x8kSUvW9uRFuSWPLOrXzapZG7m5O5SU0QTQ,895
@@ -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.27.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
- prediction_market_agent_tooling-0.27.0.dist-info/METADATA,sha256=EOgPmMy7tmfMsgdKgxB_zVCFZN8YQO5n49IazPE9gJA,5465
70
- prediction_market_agent_tooling-0.27.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
- prediction_market_agent_tooling-0.27.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
- prediction_market_agent_tooling-0.27.0.dist-info/RECORD,,
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,,