prediction-market-agent-tooling 0.38.0__py3-none-any.whl → 0.39.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.
- prediction_market_agent_tooling/markets/agent_market.py +21 -0
- prediction_market_agent_tooling/markets/omen/omen.py +61 -0
- prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +6 -0
- {prediction_market_agent_tooling-0.38.0.dist-info → prediction_market_agent_tooling-0.39.1.dist-info}/METADATA +2 -2
- {prediction_market_agent_tooling-0.38.0.dist-info → prediction_market_agent_tooling-0.39.1.dist-info}/RECORD +8 -8
- {prediction_market_agent_tooling-0.38.0.dist-info → prediction_market_agent_tooling-0.39.1.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.38.0.dist-info → prediction_market_agent_tooling-0.39.1.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.38.0.dist-info → prediction_market_agent_tooling-0.39.1.dist-info}/entry_points.txt +0 -0
@@ -114,6 +114,20 @@ class AgentMarket(BaseModel):
|
|
114
114
|
"""
|
115
115
|
raise NotImplementedError("Subclasses must implement this method")
|
116
116
|
|
117
|
+
def get_last_trade_yes_outcome_price(self) -> float | None:
|
118
|
+
# Price on prediction markets are, by definition, equal to the probability of an outcome.
|
119
|
+
# Just making it explicit in this function.
|
120
|
+
if last_trade_p_yes := self.get_last_trade_p_yes():
|
121
|
+
return float(last_trade_p_yes)
|
122
|
+
return None
|
123
|
+
|
124
|
+
def get_last_trade_no_outcome_price(self) -> float | None:
|
125
|
+
# Price on prediction markets are, by definition, equal to the probability of an outcome.
|
126
|
+
# Just making it explicit in this function.
|
127
|
+
if last_trade_p_no := self.get_last_trade_p_no():
|
128
|
+
return float(last_trade_p_no)
|
129
|
+
return None
|
130
|
+
|
117
131
|
def get_bet_amount(self, amount: float) -> BetAmount:
|
118
132
|
return BetAmount(amount=amount, currency=self.currency)
|
119
133
|
|
@@ -193,6 +207,13 @@ class AgentMarket(BaseModel):
|
|
193
207
|
"""
|
194
208
|
raise NotImplementedError("Subclasses must implement this method")
|
195
209
|
|
210
|
+
@classmethod
|
211
|
+
def get_positions_value(cls, positions: list[Position]) -> BetAmount:
|
212
|
+
"""
|
213
|
+
Get the total value of all positions held by a user.
|
214
|
+
"""
|
215
|
+
raise NotImplementedError("Subclasses must implement this method")
|
216
|
+
|
196
217
|
def can_be_traded(self) -> bool:
|
197
218
|
if self.is_closed() or not self.has_liquidity():
|
198
219
|
return False
|
@@ -421,6 +421,67 @@ class OmenAgentMarket(AgentMarket):
|
|
421
421
|
|
422
422
|
return positions
|
423
423
|
|
424
|
+
@classmethod
|
425
|
+
def get_positions_value(cls, positions: list[Position]) -> BetAmount:
|
426
|
+
# Two dicts to map from market ids to (1) positions and (2) market.
|
427
|
+
market_ids_positions = {p.market_id: p for p in positions}
|
428
|
+
# Check there is only one position per market.
|
429
|
+
if len(set(market_ids_positions.keys())) != len(positions):
|
430
|
+
raise ValueError(
|
431
|
+
f"Markets for positions ({market_ids_positions.keys()}) are not unique."
|
432
|
+
)
|
433
|
+
markets: list[OmenAgentMarket] = [
|
434
|
+
OmenAgentMarket.from_data_model(m)
|
435
|
+
for m in OmenSubgraphHandler().get_omen_binary_markets(
|
436
|
+
limit=sys.maxsize, id_in=list(market_ids_positions.keys())
|
437
|
+
)
|
438
|
+
]
|
439
|
+
market_ids_markets = {m.id: m for m in markets}
|
440
|
+
|
441
|
+
# Validate that dict keys are the same.
|
442
|
+
if set(market_ids_positions.keys()) != set(market_ids_markets.keys()):
|
443
|
+
raise ValueError(
|
444
|
+
f"Market ids in {market_ids_positions.keys()} are not the same as in {market_ids_markets.keys()}"
|
445
|
+
)
|
446
|
+
|
447
|
+
# Initialise position value.
|
448
|
+
total_position_value = 0.0
|
449
|
+
|
450
|
+
for market_id in market_ids_positions.keys():
|
451
|
+
position = market_ids_positions[market_id]
|
452
|
+
market = market_ids_markets[market_id]
|
453
|
+
|
454
|
+
yes_tokens = 0.0
|
455
|
+
no_tokens = 0.0
|
456
|
+
if OMEN_TRUE_OUTCOME in position.amounts:
|
457
|
+
yes_tokens = position.amounts[OutcomeStr(OMEN_TRUE_OUTCOME)].amount
|
458
|
+
if OMEN_FALSE_OUTCOME in position.amounts:
|
459
|
+
no_tokens = position.amounts[OutcomeStr(OMEN_FALSE_OUTCOME)].amount
|
460
|
+
|
461
|
+
# Account for the value of positions in resolved markets
|
462
|
+
if market.is_resolved() and market.has_successful_resolution():
|
463
|
+
valued_tokens = yes_tokens if market.boolean_outcome else no_tokens
|
464
|
+
total_position_value += valued_tokens
|
465
|
+
|
466
|
+
# Or if the market is open and trading, get the value of the position
|
467
|
+
elif market.can_be_traded():
|
468
|
+
total_position_value += yes_tokens * market.yes_outcome_price
|
469
|
+
total_position_value += no_tokens * market.no_outcome_price
|
470
|
+
|
471
|
+
# Or if the market is still open but not trading, estimate the value
|
472
|
+
# of the position
|
473
|
+
else:
|
474
|
+
if yes_tokens:
|
475
|
+
yes_price = check_not_none(
|
476
|
+
market.get_last_trade_yes_outcome_price()
|
477
|
+
)
|
478
|
+
total_position_value += yes_tokens * yes_price
|
479
|
+
if no_tokens:
|
480
|
+
no_price = check_not_none(market.get_last_trade_no_outcome_price())
|
481
|
+
total_position_value += no_tokens * no_price
|
482
|
+
|
483
|
+
return BetAmount(amount=total_position_value, currency=Currency.xDai)
|
484
|
+
|
424
485
|
@classmethod
|
425
486
|
def get_user_url(cls, keys: APIKeys) -> str:
|
426
487
|
return f"https://gnosisscan.io/address/{keys.bet_from_address}"
|
@@ -166,6 +166,7 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
|
|
166
166
|
resolved: bool | None = None,
|
167
167
|
liquidity_bigger_than: Wei | None = None,
|
168
168
|
condition_id_in: list[HexBytes] | None = None,
|
169
|
+
id_in: list[str] | None = None,
|
169
170
|
excluded_questions: set[str] | None = None,
|
170
171
|
) -> dict[str, t.Any]:
|
171
172
|
where_stms: dict[str, t.Any] = {
|
@@ -193,6 +194,9 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
|
|
193
194
|
if condition_id_in is not None:
|
194
195
|
where_stms["condition_"]["id_in"] = [x.hex() for x in condition_id_in]
|
195
196
|
|
197
|
+
if id_in is not None:
|
198
|
+
where_stms["id_in"] = id_in
|
199
|
+
|
196
200
|
if resolved is not None:
|
197
201
|
if resolved:
|
198
202
|
where_stms["resolutionTimestamp_not"] = None
|
@@ -308,6 +312,7 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
|
|
308
312
|
creator: t.Optional[HexAddress] = None,
|
309
313
|
liquidity_bigger_than: Wei | None = None,
|
310
314
|
condition_id_in: list[HexBytes] | None = None,
|
315
|
+
id_in: list[str] | None = None,
|
311
316
|
excluded_questions: set[str] | None = None, # question titles
|
312
317
|
sort_by_field: FieldPath | None = None,
|
313
318
|
sort_direction: str | None = None,
|
@@ -326,6 +331,7 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
|
|
326
331
|
finalized=finalized,
|
327
332
|
resolved=resolved,
|
328
333
|
condition_id_in=condition_id_in,
|
334
|
+
id_in=id_in,
|
329
335
|
excluded_questions=excluded_questions,
|
330
336
|
liquidity_bigger_than=liquidity_bigger_than,
|
331
337
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: prediction-market-agent-tooling
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.39.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
|
@@ -35,7 +35,7 @@ Requires-Dist: safe-cli (>=1.0.0,<2.0.0)
|
|
35
35
|
Requires-Dist: safe-eth-py (>=6.0.0b14,<7.0.0)
|
36
36
|
Requires-Dist: scikit-learn (>=1.3.1,<2.0.0)
|
37
37
|
Requires-Dist: streamlit (>=1.31.0,<2.0.0)
|
38
|
-
Requires-Dist: subgrounds (>=1.
|
38
|
+
Requires-Dist: subgrounds (>=1.9.1,<2.0.0)
|
39
39
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
40
40
|
Requires-Dist: tqdm (>=4.66.2,<5.0.0)
|
41
41
|
Requires-Dist: typer (>=0.9.0,<1.0.0)
|
@@ -21,7 +21,7 @@ prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py,sha256=qYIHRxQLa
|
|
21
21
|
prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=oyW0jgrUT2Tr49c7GlpcMsYNQjoCSOcWis3q-MmVAhU,6089
|
22
22
|
prediction_market_agent_tooling/gtypes.py,sha256=lbV2nsPyhMIRI9olx0_6A06jwTWKYBPGMxyiGVFysag,2467
|
23
23
|
prediction_market_agent_tooling/loggers.py,sha256=ua9rynYmsbOJZjxPIFxRBooomeN08zuLSJ7lxZMDS7w,3133
|
24
|
-
prediction_market_agent_tooling/markets/agent_market.py,sha256=
|
24
|
+
prediction_market_agent_tooling/markets/agent_market.py,sha256=OduMFTRPHLIi_YYpzFHW6cKloMgVvoez9HbdB3F9OkA,7943
|
25
25
|
prediction_market_agent_tooling/markets/categorize.py,sha256=yTd-lDMPW4ESDSzmxeLLBuzLX0FggOF7Vbswh7295o0,941
|
26
26
|
prediction_market_agent_tooling/markets/data_models.py,sha256=uODY3aoFp8YYeLAUcrzMk1yU8pIKsTLobB9xIEGTmKs,1170
|
27
27
|
prediction_market_agent_tooling/markets/manifold/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -32,10 +32,10 @@ prediction_market_agent_tooling/markets/manifold/utils.py,sha256=cPPFWXm3vCYH1jy
|
|
32
32
|
prediction_market_agent_tooling/markets/markets.py,sha256=w05Oo7yCA2axpCw69Q9y4i9Gcdpht0u5bZGbWqld3rU,2964
|
33
33
|
prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
34
|
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=EXtjmcujx68Xu50BVkYXvLuf_Asx5o65RvFS3ZS6HGs,14405
|
35
|
-
prediction_market_agent_tooling/markets/omen/omen.py,sha256=
|
35
|
+
prediction_market_agent_tooling/markets/omen/omen.py,sha256=yigcdBM7bT8rinj_gADFADXRNJCZFCMHedQJ5eeQZk4,36786
|
36
36
|
prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=-EEmN4vA8Fn52ewqQ7ZXZAFnfP4EQ4YISkeDHb9oeLk,21722
|
37
37
|
prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=g77QsQ5WnSI2rzBlX87L_EhWMwobkyXyfRhHQmpAdzo,9012
|
38
|
-
prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=
|
38
|
+
prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=6TC-uTq6DEQdXkbsZ0jI-g9zbqoO7UT3RCLFN1mQtAk,23772
|
39
39
|
prediction_market_agent_tooling/markets/polymarket/api.py,sha256=HXmA1akA0qDj0m3e-GEvWG8x75pm6BX4H7YJPQcST7I,4767
|
40
40
|
prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=9CJzakyEcsn6DQBK2nOXjOMzTZBLAmK_KqevXvW17DI,4292
|
41
41
|
prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=f8SRQy0Rn-gIHSEMrJJAI8H3J7l8lzOLj3aCMe0vJv8,11324
|
@@ -69,8 +69,8 @@ prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0r
|
|
69
69
|
prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
|
70
70
|
prediction_market_agent_tooling/tools/utils.py,sha256=-G22UEbCRm59bm1RWFdeF55hRsaxgwZVAHvK32-Ye1g,6190
|
71
71
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=nKRHmdLnWSKd3wpo-cysXGvhhrJ2Yf69sN2FFQfSt6s,10578
|
72
|
-
prediction_market_agent_tooling-0.
|
73
|
-
prediction_market_agent_tooling-0.
|
74
|
-
prediction_market_agent_tooling-0.
|
75
|
-
prediction_market_agent_tooling-0.
|
76
|
-
prediction_market_agent_tooling-0.
|
72
|
+
prediction_market_agent_tooling-0.39.1.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
73
|
+
prediction_market_agent_tooling-0.39.1.dist-info/METADATA,sha256=MP61P9hHdpxiOXEhSj03oZIXr9qTScvcR1SM7o4z1C4,7634
|
74
|
+
prediction_market_agent_tooling-0.39.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
75
|
+
prediction_market_agent_tooling-0.39.1.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
76
|
+
prediction_market_agent_tooling-0.39.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|