prediction-market-agent-tooling 0.58.0__py3-none-any.whl → 0.58.2__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,6 +1,7 @@
1
1
  import json
2
2
  import subprocess
3
3
  import sys
4
+ from functools import cache
4
5
 
5
6
  from google.cloud.functions_v2.services.function_service.client import (
6
7
  FunctionServiceClient,
@@ -197,6 +198,7 @@ def gcp_function_is_active(fname: str) -> bool:
197
198
  return get_gcp_function(fname).state == Function.State.ACTIVE
198
199
 
199
200
 
201
+ @cache
200
202
  def gcp_get_secret_value(name: str, version: str = "latest") -> str:
201
203
  client = SecretManagerServiceClient()
202
204
  return client.access_secret_version(
@@ -0,0 +1,59 @@
1
+ from datetime import timedelta
2
+
3
+ from prediction_market_agent_tooling.config import APIKeys
4
+ from prediction_market_agent_tooling.loggers import logger
5
+ from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket
6
+ from prediction_market_agent_tooling.markets.omen.omen_subgraph_handler import (
7
+ OmenSubgraphHandler,
8
+ )
9
+ from prediction_market_agent_tooling.tools.balances import get_balances
10
+ from prediction_market_agent_tooling.tools.utils import utcnow
11
+
12
+
13
+ def sell_all(
14
+ api_keys: APIKeys,
15
+ closing_later_than_days: int,
16
+ auto_withdraw: bool = False,
17
+ ) -> None:
18
+ """
19
+ Helper function to sell all existing outcomes on Omen that would resolve later than in X days.
20
+ """
21
+ better_address = api_keys.bet_from_address
22
+ bets = OmenSubgraphHandler().get_bets(
23
+ better_address=better_address,
24
+ market_opening_after=utcnow() + timedelta(days=closing_later_than_days),
25
+ )
26
+ bets_total_usd = sum(b.collateral_amount_usd for b in bets)
27
+ unique_market_urls = set(b.fpmm.url for b in bets)
28
+ starting_balance = get_balances(better_address)
29
+ new_balance = starting_balance
30
+
31
+ logger.info(
32
+ f"For {better_address}, found the following {len(bets)} bets on {len(unique_market_urls)} unique markets worth of {bets_total_usd} USD: {unique_market_urls}"
33
+ )
34
+
35
+ for bet in bets:
36
+ agent_market = OmenAgentMarket.from_data_model(bet.fpmm)
37
+ outcome = agent_market.outcomes[bet.outcomeIndex]
38
+ current_token_balance = agent_market.get_token_balance(better_address, outcome)
39
+
40
+ if current_token_balance.amount <= OmenAgentMarket.get_tiny_bet_amount().amount:
41
+ logger.info(
42
+ f"Skipping bet on {bet.fpmm.url} because the actual balance is unreasonably low {current_token_balance.amount}."
43
+ )
44
+ continue
45
+
46
+ old_balance = new_balance
47
+ agent_market.sell_tokens(
48
+ bet.boolean_outcome,
49
+ current_token_balance,
50
+ auto_withdraw=auto_withdraw,
51
+ api_keys=api_keys,
52
+ )
53
+ new_balance = get_balances(better_address)
54
+
55
+ logger.info(
56
+ f"Sold bet on {bet.fpmm.url} for {new_balance.wxdai - old_balance.wxdai} xDai."
57
+ )
58
+
59
+ logger.info(f"Obtained back {new_balance.wxdai - starting_balance.wxdai} wxDai.")
@@ -351,6 +351,13 @@ def byte32_to_ipfscidv0(hex: HexBytes) -> IPFSCIDVersion0:
351
351
  return IPFSCIDVersion0(base58.b58encode(completed_binary_str).decode("utf-8"))
352
352
 
353
353
 
354
+ @tenacity.retry(
355
+ wait=tenacity.wait_chain(*[tenacity.wait_fixed(n) for n in range(1, 10)]),
356
+ stop=tenacity.stop_after_attempt(5),
357
+ after=lambda x: logger.debug(
358
+ f"get_receipt_block_timestamp failed, {x.attempt_number=}."
359
+ ),
360
+ )
354
361
  def get_receipt_block_timestamp(receipt_tx: TxReceipt, web3: Web3) -> int:
355
362
  block_number = receipt_tx["blockNumber"]
356
363
  block = web3.eth.get_block(block_number)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.58.0
3
+ Version: 0.58.2
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.13
@@ -29,7 +29,7 @@ prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=kMrIE3wMv_IB6n
29
29
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
30
30
  prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5yp0GE9Mw5caYqlFUZQ2j3ks,3739
31
31
  prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py,sha256=OsPboCFGiZKsvGyntGZHwdqPlLTthITkNF5rJFvGgU8,2582
32
- prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=dzAvSQWRc2pndHFyKhVgrTtDm91K-csgusEaFRyfSow,5664
32
+ prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=WI2ycX1X-IlTRoNoG4ggFlRwPL28kwM9VGDFD2fePLo,5699
33
33
  prediction_market_agent_tooling/deploy/trade_interval.py,sha256=Xk9j45alQ_vrasGvsNyuW70XHIQ7wfvjoxNR3F6HYCw,1155
34
34
  prediction_market_agent_tooling/gtypes.py,sha256=G9KOKqYcxoKLv5Tfto4g5zq46FeIKxGl4RTArLIJn3I,2563
35
35
  prediction_market_agent_tooling/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -102,6 +102,7 @@ prediction_market_agent_tooling/tools/is_predictable.py,sha256=qVd6zqay2Dg2fyeAu
102
102
  prediction_market_agent_tooling/tools/langfuse_.py,sha256=jI_4ROxqo41CCnWGS1vN_AeDVhRzLMaQLxH3kxDu3L8,1153
103
103
  prediction_market_agent_tooling/tools/langfuse_client_utils.py,sha256=83T31s-YbsnNBLyYCjmBI2BBKUEqJUuYFa0uCdkoqy8,5901
104
104
  prediction_market_agent_tooling/tools/omen/reality_accuracy.py,sha256=M1SF7iSW1gVlQSTskdVFTn09uPLST23YeipVIWj54io,2236
105
+ prediction_market_agent_tooling/tools/omen/sell_positions.py,sha256=JIfTMKF0bHyQ9qXNfyr5ul_eu4hBuydlRVGJET8Uw90,2308
105
106
  prediction_market_agent_tooling/tools/parallelism.py,sha256=6Gou0hbjtMZrYvxjTDFUDZuxmE2nqZVbb6hkg1hF82A,1022
106
107
  prediction_market_agent_tooling/tools/relevant_news_analysis/data_models.py,sha256=95l84aztFaxcRLLcRQ46yKJbIlOEuDAbIGLouyliDzA,1316
107
108
  prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py,sha256=CddJem7tk15NAudJDwmuL8znTycbR-YI8kTNtd3LzG8,5474
@@ -116,9 +117,9 @@ prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=B02maQkl3wN
116
117
  prediction_market_agent_tooling/tools/tokens/main_token.py,sha256=5iHO7-iehSlXuue6ocVrr4IsklVjm7QHIwln4BsebJA,573
117
118
  prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
118
119
  prediction_market_agent_tooling/tools/utils.py,sha256=jLG4nbEoIzzJiZ4RgMx4Q969Zdl0p0s63p8uET_0Fuw,6440
119
- prediction_market_agent_tooling/tools/web3_utils.py,sha256=wqUDCed3iNrn1Wao1iwGN6tzIrhpzrTRj319wlveJEo,12275
120
- prediction_market_agent_tooling-0.58.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
121
- prediction_market_agent_tooling-0.58.0.dist-info/METADATA,sha256=E_PM7SHleOyz3e52aCzYfAdmKRrfRZqR05PzbQLZ6kk,8629
122
- prediction_market_agent_tooling-0.58.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
123
- prediction_market_agent_tooling-0.58.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
124
- prediction_market_agent_tooling-0.58.0.dist-info/RECORD,,
120
+ prediction_market_agent_tooling/tools/web3_utils.py,sha256=e7lqqQddVZaa905rhBb6L1fC3o39Yr-PDJsJjHFBeRE,12523
121
+ prediction_market_agent_tooling-0.58.2.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
122
+ prediction_market_agent_tooling-0.58.2.dist-info/METADATA,sha256=6a2-ucKTXSn19qa7dDHal28aNeopkwoEJB9jOdfW-9A,8629
123
+ prediction_market_agent_tooling-0.58.2.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
124
+ prediction_market_agent_tooling-0.58.2.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
125
+ prediction_market_agent_tooling-0.58.2.dist-info/RECORD,,