Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit 1bbf34c

Browse files
author
TheophilusChinomona
committed
fix: adversarial review findings — 10 issues caught
REGRESSIONS FIXED: - Polymarket.__init__: remove private key validation from init (breaks read-only CLI usage). Move validation to _init_api_keys() where it's actually needed for trading operations. - build_order(): restore py_order_utils imports (Signer, OrderBuilder, OrderData) that were accidentally removed. BUGS FIXED: - TradingAgent.weekly(): call self.schedule.weekly() instead of self.weekly() — method is on TimeScheduler, not TradingScheduler - parse_pydantic_market: filter None from parse_nested_event results to prevent None entries in market.events list - get_usdc_balance: fix 10e5 -> 10**6 (USDC has 6 decimals, was off by 10x) - Source.id/name: add = None defaults (required in Pydantic v2) - tenacity retry: add httpx.TimeoutException and httpx.NetworkError to retry exception types (httpx doesn't raise Python TimeoutError) - _init_approvals: replace 6 remaining print() with logger.info() - executor.py get_polymarket_llm: replace last print() with logger
1 parent ab4ef92 commit 1bbf34c

7 files changed

Lines changed: 37 additions & 19 deletions

File tree

agents/application/creator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import httpx
12
import logging
23

34
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
@@ -20,7 +21,13 @@ def __init__(self):
2021
@retry(
2122
stop=stop_after_attempt(MAX_RETRIES),
2223
wait=wait_exponential(multiplier=1, min=2, max=30),
23-
retry=retry_if_exception_type((ConnectionError, TimeoutError, RuntimeError)),
24+
retry=retry_if_exception_type((
25+
ConnectionError,
26+
TimeoutError,
27+
RuntimeError,
28+
httpx.TimeoutException,
29+
httpx.NetworkError,
30+
)),
2431
reraise=True,
2532
)
2633
def one_best_market(self):

agents/application/cron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def start(self) -> None:
2424
class TradingAgent(TradingScheduler):
2525
def __init__(self) -> None:
2626
super().__init__()
27-
self.weekly(Monday(), self.trader.one_best_trade)
27+
self.schedule.weekly(Monday(), self.trader.one_best_trade)

agents/application/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def get_polymarket_llm(self, user_input: str) -> str:
100100
else:
101101
# If exceeding limit, process in chunks
102102
chunk_size = len(combined_data) // ((total_tokens // token_limit) + 1)
103-
print(f'total tokens {total_tokens} exceeding llm capacity, now will split and answer')
103+
logger.info('total tokens %d exceeding llm capacity, now will split and answer', total_tokens)
104104
group_size = (total_tokens // token_limit) + 1 # 3 is safe factor
105105
keys_no_meaning = ['image','pagerDutyNotificationEnabled','resolvedBy','endDate','clobTokenIds','negRiskMarketID','conditionId','updatedAt','startDate']
106106
useful_keys = ['id','questionID','description','liquidity','clobTokenIds','outcomes','outcomePrices','volume','startDate','endDate','question','questionID','events']

agents/application/trade.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import shutil
33

4+
import httpx
45
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
56

67
from agents.application.executor import Executor as Agent
@@ -33,7 +34,13 @@ def clear_local_dbs(self) -> None:
3334
@retry(
3435
stop=stop_after_attempt(MAX_RETRIES),
3536
wait=wait_exponential(multiplier=1, min=2, max=30),
36-
retry=retry_if_exception_type((ConnectionError, TimeoutError, RuntimeError)),
37+
retry=retry_if_exception_type((
38+
ConnectionError,
39+
TimeoutError,
40+
RuntimeError,
41+
httpx.TimeoutException,
42+
httpx.NetworkError,
43+
)),
3744
reraise=True,
3845
)
3946
def one_best_trade(self) -> None:

agents/polymarket/gamma.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def parse_pydantic_market(self, market_object: dict) -> Market:
2828
if "events" in market_object:
2929
events: list[PolymarketEvent] = []
3030
for market_event_obj in market_object["events"]:
31-
events.append(self.parse_nested_event(market_event_obj))
31+
parsed = self.parse_nested_event(market_event_obj)
32+
if parsed is not None:
33+
events.append(parsed)
3234
market_object["events"] = events
3335

3436
# These two fields below are returned as stringified lists from the api

agents/polymarket/polymarket.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
OrderBookSummary,
2121
)
2222
from py_clob_client.order_builder.constants import BUY
23+
from py_order_utils.builders import OrderBuilder
24+
from py_order_utils.model import OrderData
25+
from py_order_utils.signer import Signer
2326

2427
from agents.utils.objects import SimpleMarket, SimpleEvent
2528

@@ -41,10 +44,6 @@ def __init__(self) -> None:
4144

4245
self.chain_id = 137 # POLYGON
4346
self.private_key = os.getenv("POLYGON_WALLET_PRIVATE_KEY")
44-
if not self.private_key:
45-
raise ValueError(
46-
"POLYGON_WALLET_PRIVATE_KEY environment variable is required"
47-
)
4847

4948
self.polygon_rpc = "https://polygon-rpc.com"
5049
self.w3 = Web3(Web3.HTTPProvider(self.polygon_rpc))
@@ -72,12 +71,15 @@ def __init__(self) -> None:
7271
self._init_approvals(False)
7372

7473
def _init_api_keys(self) -> None:
74+
if not self.private_key:
75+
raise ValueError(
76+
"POLYGON_WALLET_PRIVATE_KEY is required for trading operations"
77+
)
7578
self.client = ClobClient(
7679
self.clob_url, key=self.private_key, chain_id=self.chain_id
7780
)
7881
self.credentials = self.client.create_or_derive_api_creds()
7982
self.client.set_api_creds(self.credentials)
80-
# print(self.credentials)
8183

8284
def _init_approvals(self, run: bool = False) -> None:
8385
if not run:
@@ -104,7 +106,7 @@ def _init_approvals(self, run: bool = False) -> None:
104106
usdc_approve_tx_receipt = web3.eth.wait_for_transaction_receipt(
105107
send_usdc_approve_tx, 600
106108
)
107-
print(usdc_approve_tx_receipt)
109+
logger.info("USDC approve receipt (CTF Exchange): %s", usdc_approve_tx_receipt)
108110

109111
nonce = web3.eth.get_transaction_count(pub_key)
110112

@@ -120,7 +122,7 @@ def _init_approvals(self, run: bool = False) -> None:
120122
ctf_approval_tx_receipt = web3.eth.wait_for_transaction_receipt(
121123
send_ctf_approval_tx, 600
122124
)
123-
print(ctf_approval_tx_receipt)
125+
logger.info("CTF approval receipt: %s", ctf_approval_tx_receipt)
124126

125127
nonce = web3.eth.get_transaction_count(pub_key)
126128

@@ -137,7 +139,7 @@ def _init_approvals(self, run: bool = False) -> None:
137139
usdc_approve_tx_receipt = web3.eth.wait_for_transaction_receipt(
138140
send_usdc_approve_tx, 600
139141
)
140-
print(usdc_approve_tx_receipt)
142+
logger.info("USDC approve receipt (Neg Risk CTF): %s", usdc_approve_tx_receipt)
141143

142144
nonce = web3.eth.get_transaction_count(pub_key)
143145

@@ -153,7 +155,7 @@ def _init_approvals(self, run: bool = False) -> None:
153155
ctf_approval_tx_receipt = web3.eth.wait_for_transaction_receipt(
154156
send_ctf_approval_tx, 600
155157
)
156-
print(ctf_approval_tx_receipt)
158+
logger.info("CTF approval receipt (Neg Risk): %s", ctf_approval_tx_receipt)
157159

158160
nonce = web3.eth.get_transaction_count(pub_key)
159161

@@ -170,7 +172,7 @@ def _init_approvals(self, run: bool = False) -> None:
170172
usdc_approve_tx_receipt = web3.eth.wait_for_transaction_receipt(
171173
send_usdc_approve_tx, 600
172174
)
173-
print(usdc_approve_tx_receipt)
175+
logger.info("USDC approve receipt (Neg Risk Adapter): %s", usdc_approve_tx_receipt)
174176

175177
nonce = web3.eth.get_transaction_count(pub_key)
176178

@@ -186,7 +188,7 @@ def _init_approvals(self, run: bool = False) -> None:
186188
ctf_approval_tx_receipt = web3.eth.wait_for_transaction_receipt(
187189
send_ctf_approval_tx, 600
188190
)
189-
print(ctf_approval_tx_receipt)
191+
logger.info("CTF approval receipt (Neg Risk Adapter): %s", ctf_approval_tx_receipt)
190192

191193
def get_all_markets(self) -> "list[SimpleMarket]":
192194
markets = []
@@ -353,7 +355,7 @@ def get_usdc_balance(self) -> float:
353355
balance_res = self.usdc.functions.balanceOf(
354356
self.get_address_for_private_key()
355357
).call()
356-
return float(balance_res / 10e5)
358+
return float(balance_res / 10**6)
357359

358360

359361
def test():

agents/utils/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ class SimpleEvent(BaseModel):
212212

213213

214214
class Source(BaseModel):
215-
id: Optional[str]
216-
name: Optional[str]
215+
id: Optional[str] = None
216+
name: Optional[str] = None
217217

218218

219219
class Article(BaseModel):

0 commit comments

Comments
 (0)